Paste strings with keeping position and pasting lines always at column 1

Paste strings with keeping position and pasting lines always at column 1

1
NewbieNewbie
1

    Oct 31, 2010#1

    Hello! I am a recent convert from Multi-Edit, having just started evaluating UEStudio and UltraCompare, and I am already fairly comfortable using UltraEdit. I've already written some 'real code' and my productivity has noticeably increased thanks to some of the features - particularly code folding - that UltraEdit just does better and with more polish. I'm not 100% converted yet, however, and the problems I am running into are simultaneously trivial AND show-stoppers - for me, anyway.

    I have two problems with pasting text:

    First - when I paste a piece of text into the middle of a line, the cursor positions itself at the END of the pasted text. Somehow, for the past 20 years, I've used text editors that position the cursor at the START of the pasted text - or at least allow me to set the behavior. After searching these forums, I found one message that peripherally mentioned that the columnar paste works the way I want, but getting to column mode isn't convenient for every cut and paste. Like I mentioned, this seems so darn trivial, but it completely upsets the way I work and breaks me out of my flow. Is there a macro or script out there that can help with this? Ostensibly, the macro would push the current cursor position, paste the clipboard, and then pop the cursor position back to where it was. I was really hoping to not have to learn another macro language - does anyone have some ideas?

    Second - When there is no text highlighted and I hit the copy or cut commands, I expect the editor to copy or cut the current line. Luckily, there was an option in UltraEdit to make this happen. Unfortunately, whenever I paste a series of lines (regardless of how I selected them), the lines get inserted into the file from the current cursor position. So, if I highlight five LINES, copy, and move somewhere else in the document, UNLESS the cursor is in the first column, the lines get inserted directly into the middle of a line, 'stream style'. This behavior is most noticeable when you copy and cut lines without highlighting them, like I mentioned. Again, this behavior just stops me in my tracks - even though you could argue that it is the 'correct' behavior. It just doesn't live up to my expectations of what it means to copy a line as a single unit, unto itself. I couldn't find an option to make it behave the way I wanted. Am I missing the option? A macro that checked to see if there was any selected text and then positioned the cursor at column one whenever a copy or cut is done without a selection would largely solve this problem. Has anyone done something like this?

    Although I am new to UltraEdit, I just want to assure the user community that I am not a newbie when it comes to being a responsible citizen of support discussion boards. I searched the product help file, did a bunch of searches on these forums, and did even more straight outta Google. Of course I may have missed something, but please point me to it instead of getting grumbly and cryptic and RTFMing me. Much obliged.

    6,606548
    Grand MasterGrand Master
    6,606548

      Oct 31, 2010#2

      There are no settings to get the "clipboard content based paste" behavior you want. It is not possible to code this behavior with a macro. But I think it is possible to code this behavior with a script. Here is the script I developed for you which hopefully does result in the paste behavior you want. I hope, I have understood your requirements correct.

      Code: Select all

      // Run this script only when at least 1 file is opened.
      if (UltraEdit.document.length > 0)
      {
         // 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;
         var bInsertMode = (typeof(UltraEdit.insOvrMode) == "boolean") ? UltraEdit.insOvrMode : true;
      
         // If the current file is opened in hex edit mode, or column mode
         // with insert or overwrite mode is active, or overwrite mode in
         // normal text edit mode is active or something is selected, just
         // paste the clipboard content into the file.
         if (UltraEdit.activeDocument.hexMode || bColumnMode ||
             bInsertMode == false || UltraEdit.activeDocument.isSel())
         {
            UltraEdit.activeDocument.paste();
         }
         else  // The file is opened in text edit mode and normal
         {     // insert mode is active and nothing is selected.
               // First get current line number into a variable.
            var nActiveLine = UltraEdit.activeDocument.currentLineNum;
            // Next check if the active clipboard contains one or more
            // lines by searching for a carriage return or line-feed.
            if (UltraEdit.clipboardContent.search(/[\r\n]/) >= 0 )
            {
               // Go to the start of this line, paste the line(s) and
               // set cursor back to beginning of the pasted lines.
               UltraEdit.activeDocument.gotoLine(nActiveLine,1);
               UltraEdit.activeDocument.paste();
               UltraEdit.activeDocument.gotoLine(nActiveLine,1);
            }
            else // Just a string and not an entire line should be inserted. Get
            {    // also the number of active column into a variable. Then paste
                 // clipboard content and set cursor back to insert position.
               var nActiveColumn = UltraEdit.activeDocument.currentColumnNum;
               if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nActiveColumn++;
               UltraEdit.activeDocument.paste();
               UltraEdit.activeDocument.gotoLine(nActiveLine,nActiveColumn);
            }
         }
      }
      You have to add this script to list of scripts in Scripting - Scripts and assign the hotkey Ctrl+V to this script. And you should remove in Advanced - Configuration - Key Mapping the hotkey Ctrl+V from command EditPaste. Alternatively you can assign to the script or to the command a different hotkey in case you need the built-in command.

      You should additionally uncheck configuration setting Show status information in output window at Advanced - Configuration - Scripting or every execution of this script results in overwriting current output window content with script status information.

      Last I must add that UltraEdit.insOvrMode == false respectively bInsertMode == false is not really working here. The reason is that UltraEdit for Windows and UEStudio on script start always enables the insert mode and restores original editing mode (insert or overwrite) on script exit. This is done for security because most script writers forget the commands to define the editing mode for their scripts before modifying the content of a file. So this scripts always inserts the clipboard content when normal text edit mode is active even when overwrite mode is enabled by you with key Ins. The other conditions for just pasting the clipboard content according to active mode work with UE v16.20.0.1011 (at least they result in running into the first IF branch).

      This script should work with UE v14.20 and later and UES v9.00 and later, but was tested only with UE v16.20.0.1011.
      Best regards from an UC/UE/UES for Windows user from Austria