Plugin: Move Selected Lines
Plugin: Move Selected Lines
Move selected lines up or down.
- Attachments
-
- move selected lines.zip
- (772 Bytes) Downloaded 966 times
Blumentals Software Programmer
Re: Plugin: Move Selected Lines
Here's plugin code to use as an example:
Code: Select all
function GetTrimmedSelection() {
var Sel = Editor.Selection;
if ((Sel.SelStartLine < Sel.SelEndLine) && (Sel.SelEndCol == 0)) {
Sel.SelEndLine--;
Sel.SelEndCol = Length(Editor.LinesAsDisplayed[Sel.SelEndLine]);
}
return Sel;
}
function MoveUp(Sender) {
var Sel = GetTrimmedSelection();
if ((Sel.SelStartLine > 0) && (Sel.SelEndLine > 0)) {
Editor.BeginEditing;
var line, line2;
for (var f = Sel.SelStartLine; f <= Sel.SelEndLine; f++) {
line = Editor.Lines[f - 1];
line2 = Editor.Lines[f];
Editor.Lines[f - 1] = line2;
Editor.Lines[f] = line;
}
Sel.SelStartLine = Sel.SelStartLine - 1;
Sel.SelEndLine = Sel.SelEndLine - 1;
Editor.Selection = Sel;
Editor.EndEditing;
}
}
function MoveDown(Sender) {
var Sel = GetTrimmedSelection();
if (Sel.SelEndLine < Editor.LineCount - 1) {
Editor.BeginEditing;
var line, line2;
for (f = Sel.SelEndLine; f >= Sel.SelStartLine; f--) {
line = Editor.Lines[f];
line2 = Editor.Lines[f + 1];
Editor.Lines[f] = line2;
Editor.Lines[f + 1] = line;
}
Sel.SelStartLine = Sel.SelStartLine + 1;
Sel.SelEndLine = Sel.SelEndLine + 1;
Editor.Selection = Sel;
Editor.EndEditing;
}
}
Script.RegisterDocumentAction("Move Selected Lines", "Move Selected Lines Up", "Shift+Ctrl+Up", &MoveUp);
Script.RegisterDocumentAction("Move Selected Lines", "Move Selected Lines Down", "Shift+Ctrl+Down", &MoveDown);
Blumentals Software Programmer
Re: Plugin: Move Selected Lines
Thanks, simple and usefull feature.
-
- Posts: 5
- Joined: Wed Sep 18, 2013 10:53 pm
Re: Plugin: Move Selected Lines
My Question like these so I decided to post here:
I would like to move to the last line of some bigger files (around 3.000 Lines). How can I realise it? Can someone please give me an idea.
I would like to move to the last line of some bigger files (around 3.000 Lines). How can I realise it? Can someone please give me an idea.
-
- Posts: 5
- Joined: Wed Sep 18, 2013 10:53 pm
Re: Plugin: Move Selected Lines
I've found a solution. May it's not the best, but it works, also with very big files up to 26 MB (this was an fault and not usual in web environment):
As I wrote some Plugins now, I wish me a more precise documentation. May you can put this to your todo-list.
Code: Select all
function GoToLastRow(Sender) {
Editor.SelectAll;
var sel = Editor.Selection;
sel.SelStartLine = sel.SelEndLine;
Editor.Selection = sel;
sel = Editor.Selection;
sel.SelStartColReal = sel.SelEndColReal;
Editor.Selection = sel;
} // GoToLastRow