You are here: PSPad forum > English discussion forum > swap with line above

swap with line above

#1 swap with line above

Posted by: scharfie | Date: 07/01/2005 20:29 | IP: IP Logged

I have written script that provides swap with line above, swap with line below functions. I realize that swap with line below was already in pspad, but I just put it in because it was easy smiling smiley

Anyway, if anyone wants to try it, it's here: www.csee.wvu.edu

Just drop it into \PSPad\Script\JScript and then do Scripts > Recompile scripts.

A couple of things to note: the script, by default, assigns Ctrl+Up to swap with line above, and Ctrl+Down to swap with line below. These can be changed in the .JS file if necessary.

Also, I had trouble using caretX(0), so I used the command("ecLineStart"). Not sure if it's a bug in the scripting, but I had strange problems with lines that had spaces at the beginning and trying to use caretX(0) and then lineText(). If you are adventurous, you can replace the command("ecLineStart") lines with caretX(0), and you'll see what I mean.

Options: Reply | Quote | Up ^


#2 Re: swap with line above

Posted by: gogogadgetscott | Date: 07/02/2005 01:27 | IP: IP Logged

Great work, this will defiantly come in handy. Thanks.

After looked into you issue with caretX, this is what I found:
It is my understanding that lineText() accesses the entire line and is independent of the curser X position. If this in fact the case neither caretX() or ecLineStart are required. The strange beaver seams to be caused by lineText().


function test()
{
var editor = newEditor();
editor.assignActiveEditor();
var log = NewEditor();
log.AssignLog();
for(var y = 1; y < editor.linesCount() + 1; y++) {
editor.caretY(y);
log.selText(editor.lineText()+"\n");
editor.lineText("123abc");
}
}


Lorem ipsum dolor sit amet <br>
C onsectetuer suscipit et malesuada eu <br>
Eget ligula nisl mus Fusce <br>
Pellentesque In tincidunt dui tortor <br>

When running the above code, on the above text the following is the result:


123abc
123abc
123abc
123abc

The use of ecLineStart seems to override the lineText bug.

p.s. both caretX and caretY have a start index of 1.

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2014 Jan Fiala
Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák