Community
    • Login

    How to add lines in specific locations

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    21 Posts 5 Posters 2.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Alan KilbornA
      Alan Kilborn @Paul Wormer
      last edited by

      @paul-wormer said in How to add lines in specific locations:

      Obviously that the editor keeps on finding <box> and keeps on inserting <thumb>

      You mean finding the same <box> over and over?
      It doesn’t do this because after a replacement it starts the next search after the position of the replacement text.

      Paul WormerP 2 Replies Last reply Reply Quote 2
      • Paul WormerP
        Paul Wormer @Alan Kilborn
        last edited by

        @alan-kilborn said in How to add lines in specific locations:

        You mean finding the same <box> over and over?

        No, I mean when the editor wraps around and starts at the top, it will go down finding boxes and inserting thumbs again. But I guess it remembers its starting position, although remembering is not trivial, because lines are added, both above and below the starting position.

        Alan KilbornA 1 Reply Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @Paul Wormer
          last edited by

          @paul-wormer said in How to add lines in specific locations:

          I mean when the editor wraps around and starts at the top, it will go down finding boxes

          Perhaps you didn’t see my earlier point:

          Replace All + Wrap around will make one pass thru the entire file, starting at the top. It doesn’t care where the caret/cursor currently is.

          There is no “wrap around” with Replace All. In this case think of the Wrap around checkbox as saying “Entire document top-to-bottom”.

          The only time “remembering the starting position” is important is when Replace (not All) or Find Next is pressed, and the text isn’t found – in these cases the software needs to know where to stop looking after wrapping around. Basically what it does, for a downward search is TWO searches: from caret/cursor to end-of-file, and then from top-of-file to caret location. In neither case does the starting position move based upon a replacement changing text.

          1 Reply Last reply Reply Quote 2
          • Paul WormerP
            Paul Wormer @Alan Kilborn
            last edited by

            @alan-kilborn
            I’m sorry, I didn’t read too well. You said that “Replace all” starts at the top, whereas I assumed that it started at the caret (current position), worked down, and wrapped around.

            Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @Paul Wormer
              last edited by

              @paul-wormer said in How to add lines in specific locations:

              I assumed that it (Replace All) started at the caret (current position), worked down, and wrapped around.

              Well, it could work that way, but that would be more complicated for the developers for that type of replacement.

              PeterJonesP 1 Reply Last reply Reply Quote 2
              • PeterJonesP
                PeterJones @Alan Kilborn
                last edited by PeterJones

                @alan-kilborn said in How to add lines in specific locations:

                @paul-wormer said in How to add lines in specific locations:

                I assumed that it (Replace All) started at the caret (current position), worked down, and wrapped around.

                Well, it could work that way, but that would be more complicated for the developers for that type of replacement.

                It could also make some regex not work as expected. Let’s say I had the cursor partway through a document,

                one
                two
                three
                four
                five
                six
                seven
                

                and set up a regex that said “skip the first two lines at the beginning of the file, then replace the rest of the file with deleted”:
                FIND = \A(?-s:^.*$\R){2}\K(?s:.*)
                REPLACE = deleted
                If it did it your ( @paul-wormer 's) way, and you had the cursor at the start of five and it was remembering that cursor location as the “start/end” point, then it would search from five to seven not finding a match, then wrap around to one, skip lines one and two, and match from three to four – stopping because it got to the “start/end” at line five. =>

                one
                two
                deletedfive
                six
                seven
                

                Fortunately, it does not do that. Instead, it starts at the beginning of the file, skips the first two lines, and matches the whole rest of the document like was intended. =>

                one
                two
                deleted
                
                1 Reply Last reply Reply Quote 4
                • PeterJonesP
                  PeterJones @Paul Wormer
                  last edited by

                  @paul-wormer ,

                  Also, please note that this behavior is well-defined in the online user manual:

                  • Replace All: With ☑ Wrap Around ticked, it makes one pass through the active document, from the very top to the very bottom, and replaces all occurrences found. With ☐ Wrap Around unticked, it searches from the caret to the end of the file (if ☐ Backward direction is unticked) or from the beginning of the file to the caret (if ☑ Backward direction is ticked) and replaces all occurrences found in that region.

                  – https://npp-user-manual.org/docs/searching/#find-replace-tabs

                  This description was specifically clarified last year, to avoid any confusion as to what Replace All means in conjunction with the Wrap Around and Backward direction options.

                  Paul WormerP 1 Reply Last reply Reply Quote 3
                  • Paul WormerP
                    Paul Wormer @PeterJones
                    last edited by

                    @peterjones
                    Thank you, I understand it completely now.

                    Probably others have remarked this before, but the name of the box “Wrap around” is misleading for a “Replace all”, because - as you point out - there is no wrapping. The term “Wrap around” is the source of my confusion. Easier to understand would be three replacement boxes labeled “Overall”, “Downward”, and “Upward” or something similar. (I do not mean this as suggestion for an adaptation of the UI. The Find panel is already crowded enough, IMHO).

                    Alan KilbornA 3 Replies Last reply Reply Quote 2
                    • Alan KilbornA
                      Alan Kilborn @Paul Wormer
                      last edited by

                      @paul-wormer said in How to add lines in specific locations:

                      Probably others have remarked this before, but the name of the box “Wrap around” is misleading for a “Replace all

                      Yes, they have. But, this UI is trying to do a maximum of things with a minimum of UI components, because, as you say:

                      The Find panel is already crowded enough,

                      So, really, it is just a matter of learning how the software works.

                      1 Reply Last reply Reply Quote 2
                      • Alan KilbornA
                        Alan Kilborn @Paul Wormer
                        last edited by Alan Kilborn

                        @paul-wormer said in How to add lines in specific locations:

                        Easier to understand would be three replacement boxes labeled “Overall”, “Downward”, and “Upward” or something similar.

                        Maybe that would be even more confusing, as there’s already a Backward direction checkbox (which resembles your “Upward”).

                        Also, having an “Overall” choice makes Wrap around redundant, but Wrap around is needed for Find Next and Replace !

                        Historical note: I forget which version it was changed in, but the Backward direction checkbox used to be two radio buttons in the UI:

                        93752776-4ae3-413f-b521-97b08c68f7af-image.png

                        As you say, you’re not suggesting changes to the UI, and this is a good thing, because developers don’t listen to those requests for the Find family of windows.

                        1 Reply Last reply Reply Quote 1
                        • Alan KilbornA
                          Alan Kilborn @Paul Wormer
                          last edited by

                          @paul-wormer

                          And… if it helps you, you could always customize the text of the UI yourself (there’s a way to do it without rebuilding the software), so you’d have something like this for the Wrap around box:

                          35f926f4-afda-4aa7-8cd9-27d93fa0badb-image.png

                          1 Reply Last reply Reply Quote 3
                          • ImgemaI
                            Imgema @Alan Kilborn
                            last edited by

                            @alan-kilborn

                            Your solution worked. I added the missing “/” in the second <thumb> part where it was needed and by using “replace all” it applied the lines in all entries.

                            Thanks all for the replies :)

                            1 Reply Last reply Reply Quote 3
                            • First post
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors