Implement line based select and paste

Implement line based select and paste

2
NewbieNewbie
2

    Apr 30, 2015#1

    I would like to modify the selection and paste operations. Coming from another editor (MultiEdit), I'm used to being able to use Shift+Down Arrow (or Shift+Up Arrow) to select the entire line, and then continuing Shift+Down Arrow (or Shift+Up Arrow) to extend selecting entire lines to create a full block of complete lines. I find this much easier (and more intuitive) than having the selection begin wherever my cursor happens to be, or always having to remember to first go to the beginning of the line. I mean really, what percentage of the time do you want to start a selection in the middle of a line and continue to somewhere in the middle of the next line as opposed to wanting to select full lines? :)

    In addition, when I copy a selection that includes an entire line (or block of lines), 99% of the time when I go to paste it back in I do NOT want to paste it in the middle of a line. So if I'm pasting lines I again always have to remember to go to the beginning of the line where I'm going to paste. I would like to be able to paste, and if the selection contains line ends (or a block of lines), then instead of inserting in the middle of my current line, instead paste the clipped line or block ABOVE the current line. If the selection to be clipped does NOT contain line end characters then just paste at current cursor position, as is currently done.

    In my other editor, this was called operating in line mode, as opposed to stream mode. Now I can understand a reluctance to change the UE editor default behavior (although an option for native line mode operation would be nice), so I don't mind writing my own scripts and binding them to custom keys.

    My questions are:
    Am I missing some way to configure the editor to work as I wish?
    Does anyone know of scripts already available to do this, or that work similarly so I could modify (since I'm just starting to learn UE scripting)?

    Thanks

    6,682583
    Grand MasterGrand Master
    6,682583

      May 01, 2015#2

      jayterry wrote:Am I missing some way to configure the editor to work as I wish?
      I don't thinks so. But there are some features you might not have detected until now.
      • Edit - Select Line
        This command selects the entire active line independent on current position within the line. I have assigned Alt+L as hotkey to this command (EditSelectLine) in key mapping configuration dialog for quick usage by key.
      • Home key always goes to column 1
        There is the setting Home key always goes to column 1 at Advanced - Configuration - Editor - Miscellaneous which makes it possible to move caret with pressing key HOME always to start of a line instead of first non whitespace character except caret is already on first non whitespace character in which case caret is moved to column 1.
        HOME and Shift+Down Arrow or HOME and Shift+Up Arrow results in a quick selection of active line or line above with this setting enabled.
      • Enable copy/cut of current line with no selection active
        There is the setting Enable copy/cut of current line with no selection active at Advanced - Configuration - Editor - Miscellaneous.
      • Triple primary (left) mouse button click selects entire line
        A triple click on primary mouse button selects also entire line in case of using the mouse. Well, this feature is most likely not of interest for you as you want to use keyboard for making a block selection.
      jayterry wrote:Does anyone know of scripts already available to do this, or that work similarly so I could modify (since I'm just starting to learn UE scripting)?
      I can't remember having ever written or read about such a script or macro.

      Overriding Windows standard for making a selection by key using a script could be very tricky.

      First, I failed to assign a script to Shift+Up Arrow or Shift+Down Arrow. UltraEdit always replaced the hotkey on closing the Scripts dialog with button OK by Shift+Execute (German keyboard). I don't know why because I have tried that never before.

      I have tried as line mode Shift+Down Arrow the script:

      Code: Select all

      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // The column mode property is a property of the UltraEdit object in
         // UltraEdit for Windows and UEStudio, but a property of the document
         // object in UltraEdit for Linux and for Mac.
         var bColumnMode = false;
         if (typeof(UltraEdit.columnMode) == "boolean") bColumnMode = UltraEdit.columnMode;
         else if (typeof(UltraEdit.activeDocument.columnMode) == "boolean") bColumnMode = UltraEdit.activeDocument.columnMode;
      
         // Is normal text editing (with one or more carets) active?
         if (!bColumnMode && !UltraEdit.activeDocument.hexMode)
         {
            // Is there currently no selection?
            if (!UltraEdit.activeDocument.isSel())
            {
               // Select the entire active line.
               UltraEdit.activeDocument.selectLine();
            }
            else
            {
               UltraEdit.activeDocument.startSelect();
               UltraEdit.activeDocument.key("DOWN ARROW");
            }
         }
         else
         {
            UltraEdit.activeDocument.startSelect();
            UltraEdit.activeDocument.key("DOWN ARROW");
         }
      }
      
      I have tried as line mode Shift+Up Arrow the script:

      Code: Select all

      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // The column mode property is a property of the UltraEdit object in
         // UltraEdit for Windows and UEStudio, but a property of the document
         // object in UltraEdit for Linux and for Mac.
         var bColumnMode = false;
         if (typeof(UltraEdit.columnMode) == "boolean") bColumnMode = UltraEdit.columnMode;
         else if (typeof(UltraEdit.activeDocument.columnMode) == "boolean") bColumnMode = UltraEdit.activeDocument.columnMode;
      
         // Is normal text editing (with one or more carets) active?
         if (!bColumnMode && !UltraEdit.activeDocument.hexMode)
         {
            // Is there currently no selection?
            if (!UltraEdit.activeDocument.isSel())
            {
               // Move caret to column 1 in active line.
               UltraEdit.activeDocument.gotoLine(0,1);
            }
         }
         UltraEdit.activeDocument.startSelect();
         UltraEdit.activeDocument.key("UP ARROW");
      }
      
      But this script failed to expand an existing selection upwards if there is already a line selected using this script. I don't know why, perhaps a bug on detection that command startSelect should result in expanding a selection if caret is blinking at beginning instead of end of active selection.

      Another problem on overriding standard Windows Shift+Up Arrow or Shift+Down Arrow selection behavior are the many different modes which must be taken into account.
      • normal single-caret text editing mode with currently no selection whereby insert/overstrike mode does not matter
      • normal single-caret text editing mode with already existing selection
      • normal multi-caret text editing mode with or without existing selection(s)
      • column editing mode with or without existing selection
      • hex editing mode with or without existing selection
      Overriding the paste behavior on Ctrl+V is also tricky to code as again all the different modes as above plus insert/overstrike mode must be taken into account.

      I think, it would be best to send an email to IDM support with the feature request for a line mode configuration setting which does following when enabled.
      • On Shift+Up Arrow or Shift+Down Arrow:
        + IF normal text editing mode is active
        + AND there is only one caret
        + AND there is currently no selection
        set caret to column 1 before execution function usually called on Shift+Up Arrow or Shift+Down Arrow.
        In all other cases execute Shift+Up Arrow or Shift+Down Arrow with no extra action.
      • On paste:
        + IF normal text editing mode is active
        + AND insert mode is active
        + AND there is only one caret
        + AND there is currently no selection
        + AND active clipboard contains at least 1 carriage return or line-feed
        move caret to column 1 before pasting the text.
        In all other cases do the paste with no extra action.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        May 01, 2015#3

        Thanks very much. I appreciate the thoughtful and detailed reply. Also, the scripts that I may be able to use as a starting point.

        Of course, the best solution would be if IDM were to implement the line mode functionality natively, but I am realistic about the possibility of that happening. :) Given that, I'm willing to assign the functionality to custom keys. So maybe instead of Shift+Down Arrow or Shift+Up Arrow I could use Ctrl+Shift+Down Arrow (I haven't looked at what keys are available yet) to handle selecting complete lines and extending complete line selections. And maybe an alternate key for pasting in line mode. Doing it that way, I'm not trying to override default, built-in behavior but rather simply adding a new functionality.

        Thanks