Plugin: Duplicate Selected Lines

Browse, download and discuss plugins for Blumentals code editors

Plugin: Duplicate Selected Lines

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

Built-in functionality duplicates a single line. If that's not enough then you need this plugin.

Updated: Bugfix, did not work on 1st line.
Attachments
duplicate lines.zip
(651 Bytes) Downloaded 375 times
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 2389
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: Plugin: Duplicate Selected Lines

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

Here's plugin code to use as an example:

Code: Select all
function DupLines(Sender) {
  var Sel = Editor.Selection;
  if ((Sel.SelStartLine >= 0) && (Sel.SelEndLine >= 0)) {

    Editor.BeginEditing;

    //get selection start/end lines and shrink selection if last selected line is not really selected
    var start = Sel.SelStartLine;
    var end = Sel.SelEndLine;
    if ((end > start) && (Sel.SelEndCol == 0)) {
      end--;
    }

    //create duplicate of the selected lines
    var line;
    var s = "";
    for (var f = start; f <= end; f++) {
      line = Editor.Lines[f];
      s += line + "\n";
    }

    //move selection to end of current selection and append the duplicated text
    Sel.SelStartLine = end + 1;
    Sel.SelStartCol = 0;
    Sel.SelEndLine = Sel.SelStartLine;
    Sel.SelEndCol = 0;
    Editor.Selection = Sel;
    Editor.SelText = s;

    Editor.EndEditing;
  }
}


Script.RegisterDocumentAction("", "Duplicate Selected Lines", "Ctrl+D", &DupLines);
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 2389
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia


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

Who is online

Users browsing this forum: No registered users and 1 guest

cron