Menu

mantain vertical selection for input

2006-08-02
2012-11-13
  • Nobody/Anonymous

    Hello, i'm a new notepad++ user, so first of all i would like to thank the author for this wonderfull application

    My question is, is it possible to lock, vertical selection of a stream of text, (when pressing alt and vertical selecting a text), so that a user can insert a text before, or after that particular text (insert a word that repeats itself vertically all over the selected text)

    Please, reply

     
    • Nobody/Anonymous

      See also the other threads on Column Editing modes.
      This multi-line-clone feature seems to be often requested ?

      To cover all the bases of replace/insert/paste, that's sounding like a new menu for Don :)

      - never had the need myself, so curious, what editing needs this .. ?

      jmg_

       
      • Nobody/Anonymous

        In structured documents, there xlever be columns of text. 
        In structured documents, there xlever be columns of text. 
        In structured documents, there xlever be columns of text. 
        In structured documents, there xlever be columns of text. 
        In structured documents, there xlever be columns of text. 

        oops, I wrote "xlever" instead of "could".  So in Crimson Editor or jEdit, I can column select the word "xlever" in the 5 lines (a rectangular selection) and then type "could" once and it is replicated in all lines. 

        Also handy for adding or subtracting text in multiple lines at once.  Can be used for tidying up code, etc.

        I have never used line selection, so I'm not sure how this should work there.  Anyway, since this has been on forums for several editors that use scintilla, I'm going to try to "fix" scintilla myself to make it work the way I want.

        Just wanted to explain how/why it is useful.

        chuckles

         
        • Nobody/Anonymous

          In case anyone is interested, I just hacked scintilla editor.cxx and produced the desired "maintain vertical selection for input" action.

          Now if one has:

          Name     phone
          bob      1115558111
          billy    1115551111
          jane     1115556543

          and you want to add ( ) and - so all the phone numbers look like (111) 555-8111,

          Just select a zero-width rectangle at the desired positions for all the phone numbers, then hit the '(', ') ' and '-'  keys at the appropriate places.  Works for me and I love it.

          Note that at this time is is a hack, because blank lines within the selection will get the new characters too. I'll be fixing that...

          If anyone is interested, respond to this post and let me know how to get you the code...

          chuckles.

          ps.  N++ really is great.

           
          • Nobody/Anonymous

            [X] Interested

            That's what I call great news! I would love to see vertical / rectangular selection in Notepad++.

            @Chuckles: Can you publish instructions how to introduce the feature in N++? Why not include it in next N++ Release?

             
            • Nobody/Anonymous

              As for instructions, I did all I think I can earlier in this thread.  It requires modifying the source to Scintilla and rebuilding Notepat++.  See my post of 2007-02-04 13:30 for the full instructions. 

              I am not a maintainer of Scintilla or Notepad, so someone else needs to evaluate the patch and deem it OK, then insert in into an official build.

              chuckles

               
    • Chris Severance

      Chris Severance - 2007-02-02

      The easiest update is to type "could" in the first line, column mark the good and bad words, and select TextFX | Edit | Fill Down Overwrite.

       
    • Nobody/Anonymous

      I had no idea that your solution existed.  Thanks for pointing it out. N++ has SO many neat features, I haven't had time to explore them all.

      On the plus side, I get the solution for all scintilla-based editors...

      chuckles

       
    • Nobody/Anonymous

      Oh, I should mention, in my case, form the rectangular selection and type once.  In your solution, type once, make the rectangular selection, then go to a menu and make a selection. 

      Thus, I have to say that my method is the "easiest".

      chuckles.

       
    • Nobody/Anonymous

      Yes, but it requires a change to the Scintilla engine.  If you get the
      source to Scintilla, make the following change and then build the
      .lib, .dll, .a or .so file as required by your OS and application.  

      This change has not been blessed by the Scintilla author(s) because
      Scintilla does not give visible indication of a zero-width rectangular
      selection.

      Save your existing Editor.cxx and then...
      in Editor.cxx at about line 3356 in the function listed below...

      void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) {
          bool wasSelection = currentPos != anchor;
                                                        <<<==== insert new code
      here.
          ClearSelection();
          bool charReplaceAction = false;
                       ///

      insert the following between the bool wasSelection and ClearSelection()
      lines.

          if(wasSelection && selType == selRectangle ) {
              int startPos;
              int endPos;

              int c1 = pdoc->GetColumn(currentPos);
              int c2 = pdoc->GetColumn(anchor);
              int offset = c1 < c2 ? c1 : c2;

              pdoc->BeginUndoAction();
              SelectionLineIterator lineIterator(this, false);
              while (lineIterator.Iterate()) {
                  startPos = lineIterator.startPos;
                  endPos   = lineIterator.endPos;

                  if(pdoc->GetColumn(endPos) >= offset){
                      unsigned int chars = lineIterator.endPos - startPos;
                      if (0 != chars) {
                          pdoc->DeleteChars(startPos, chars);
                      }
                      pdoc->InsertString(startPos, s, len);
                  }
              }
              anchor += len;
              currentPos += len;
              SetRectangularRange();
              pdoc->EndUndoAction();
          }
          else {
                      ///  then, have the else clause end just before
      EnsureCaretVisible()
          }
          EnsureCaretVisible();
          // Avoid blinking during rapid typing: