Plugin: Move Selected Lines

Browse, download and discuss plugins for Blumentals code editors

Plugin: Move Selected Lines

Postby Aivars » Fri Feb 01, 2013 3:53 pm

Move selected lines up or down.
Attachments
move selected lines.zip
(772 Bytes) Downloaded 363 times
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 1981
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: Plugin: Move Selected Lines

Postby Aivars » Fri Feb 01, 2013 4:43 pm

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
User avatar
Aivars
Blumentals Software Developer
 
Posts: 1981
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: Plugin: Move Selected Lines

Postby MaxA » Tue Nov 26, 2013 7:16 pm

Thanks, simple and usefull feature.
MaxA
 
Posts: 18
Joined: Tue Aug 28, 2012 5:53 pm

Re: Plugin: Move Selected Lines

Postby molkenstehler » Sun Apr 05, 2015 10:38 pm

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.
molkenstehler
 
Posts: 2
Joined: Wed Sep 18, 2013 10:53 pm

Re: Plugin: Move Selected Lines

Postby molkenstehler » Sun Apr 05, 2015 11:06 pm

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):

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


As I wrote some Plugins now, I wish me a more precise documentation. May you can put this to your todo-list.
molkenstehler
 
Posts: 2
Joined: Wed Sep 18, 2013 10:53 pm


Return to Plugins for HTMLPad / Rapid CSS / Rapid PHP / WeBuilder

Who is online

Users browsing this forum: No registered users and 1 guest

cron