Paste as collapsed

Help with writing and running scripts

Paste as collapsed

Postby jdaues » Fri Oct 16, 2009 4:45 pm

I'm editing an xml document.
I copy a collapsed section of text.
When I paste, it pastes expanded.
I would like it to paste as collapsed.
It this possible?
jdaues
Newbie
 
Posts: 3
Joined: Mon Jan 12, 2009 9:42 am

Re: Paste as collapsed

Postby Mofi » Sat Oct 17, 2009 9:18 am

I think, NO, it is not possible to paste a block collapsed. But you could write a script and assign a hotkey or chord to it for pasting a text and collapse (hide) the pasted text immediately.

The script is very simple and therefore I have quickly written it.

Code: Select all
// Is any file open and clipboard contains data?
if (UltraEdit.document.length > 0 && UltraEdit.clipboardContent.length > 0) {
   UltraEdit.insertMode();
   // Store the number of the active line and paste the clipboard content.
   var nStartLine = UltraEdit.activeDocument.currentLineNum;
   UltraEdit.activeDocument.paste();
   // Get the number of the line after paste.
   var nEndLine = UltraEdit.activeDocument.currentLineNum;
   // Are at least 2 lines pasted in insert mode?
   if ((nEndLine - nStartLine) > 1) {
      // If the cursor is now not at start of a line, the clipboard content
      // does not end with a line ending. Therefore insert a line ending at
      // end of the file or set the cursor to start of the next line.
      var nActColNum = UltraEdit.activeDocument.currentColumnNum;
      if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nActColNum++;
      if (nActColNum != 1) {
         if (UltraEdit.activeDocument.isEof()) {
            UltraEdit.activeDocument.insertLine();
         } else {
            UltraEdit.activeDocument.gotoLine(++nEndLine,1);
         }
      }
      // Select the pasted block again and collapse it.
      UltraEdit.activeDocument.gotoLineSelect(nStartLine,1);
      UltraEdit.activeDocument.hideOrShowLines();
      // Set the cursor back to position after the pasted block.
      UltraEdit.activeDocument.gotoLine(nEndLine,1);
   }
}
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4064
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Scripts