Community
    • Login

    Select the same line in both views of cloned document.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    cloned viewselected linecaretsynchronizedscrolling
    18 Posts 4 Posters 2.2k 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.
    • jcg3675J
      jcg3675
      last edited by

      I cloned a document to a new view so that I can see the beginning and the end of the same line (it is too long to fit on screen). I have vertical scrolling synchronized too.

      When I move to a different line in either view, I want the blue “highlighted” line in both views to change–this will make it easier to see what line I am on in both views. Right now, only the view that I am interacting with changes. Is this possible?

      EkopalypseE 1 Reply Last reply Reply Quote 1
      • EkopalypseE
        Ekopalypse @jcg3675
        last edited by

        @jcg3675

        afaik you only can highlight words but not the entire line.
        If a highlighted word is enough, make sure you have set
        Settings->Preferences->Highlighting->Highlight another view

        1 Reply Last reply Reply Quote 2
        • jcg3675J
          jcg3675
          last edited by

          I tried out your suggestion, just to see what would happen. I did see any differences–I should note I am using a forked version of NotePad++, maybe it is broken. Thank you for your suggestion.

          Also, I should clarify. When I say highlight, I mean the light blue of a selected line, in the image below. The issue is that the selected line differs between the two views, but they should be binded together so if one changes the other changes too. I am not sure if that was clear in my question.

          {00A39CC3-1E13-478B-B10B-B1DDF943035C}.png.jpg

          EkopalypseE 1 Reply Last reply Reply Quote 0
          • EkopalypseE
            Ekopalypse @jcg3675
            last edited by

            @jcg3675

            I am not sure if that was clear in my question.

            It was but unfortunately it wasn’t made clear by me.
            No, currently, as far as I know, there is no synchronous highlighting
            of the current caret line.
            But there is word highlighting like in this picture

            0f038b1b-3047-4a00-a290-f9e38d11f711-image.png

            BUT what I learnt today is, that for cloned documents it is not
            needed to have Highlight another view is activated and if you
            close npp and relaunch it, then the cloned document isn’t really
            a cloned doc anymore.
            As this setting is not active, it must be handled by the scintilla control, I guess.
            But nevertheless, npp could, I guess make enhancements to
            synchronize this. Let me try to see if I can make this work using pythonscript. Will come back on it.

            1 Reply Last reply Reply Quote 2
            • jcg3675J
              jcg3675
              last edited by

              Alright I see the difference now. The first time I did not try the highlighting with different docs, I only tried on a cloned doc, which you are correct–it makes no difference in that scenario. Good to know!

              It would be cool if you could get pythonscript to do something, but don’t die on this hill! It’s not worth it

              EkopalypseE 1 Reply Last reply Reply Quote 1
              • EkopalypseE
                Ekopalypse @jcg3675
                last edited by

                @jcg3675

                I guess this script should do it.

                from Npp import notepad, editor, editor1, editor2, SCINTILLANOTIFICATION, NOTIFICATION
                
                class VIEW_MONITOR:
                
                    def __init__(self):
                        self.monitor = {0: None, 1: None}
                        self.enabled = False
                        notepad.callback(self.on_bufferactivated, [NOTIFICATION.BUFFERACTIVATED])
                        editor.callbackSync(self.on_updateui, [SCINTILLANOTIFICATION.UPDATEUI])
                
                
                    def on_bufferactivated(self, args):
                        self.monitor[notepad.getCurrentView()] = args['bufferID']
                        self.enabled = self.monitor[0] == self.monitor[1]
                
                
                    def on_updateui(self, args):
                        if self.enabled and args['updated'] == 0x8:
                            e1_current_line = editor1.lineFromPosition(editor1.getCurrentPos())
                            e2_current_line = editor2.lineFromPosition(editor2.getCurrentPos())
                            if e1_current_line != e2_current_line:
                                if notepad.getCurrentView():
                                    editor1.gotoLine(e2_current_line)
                                else:
                                    editor2.gotoLine(e1_current_line)
                
                mon = VIEW_MONITOR()
                

                Assuming that your forked version allows installing pythonscript
                plugin, create a new script via pythonscript plugin menu, name it
                startup.py and paste the content of the script into it. Save it, close it.
                Via pythonscript menu Configuration… set Initialisation from
                LAZY to ATSTARTUP. Done. Restart npp.

                jcg3675J 1 Reply Last reply Reply Quote 3
                • jcg3675J
                  jcg3675 @Ekopalypse
                  last edited by

                  @Ekopalypse Good call on the forked version–it does not support python scripts, I switched to the official download. I also removed “and args[‘updated’] == 0x8” from the “on_updatedui()” function. It seems like an arg value of 0x8 means horizontal scrolling has changed.

                  Thank you for your hard work! This will make readability so much easier. If I can repay the favor somehow just let me know.

                  EkopalypseE 1 Reply Last reply Reply Quote 1
                  • EkopalypseE
                    Ekopalypse @jcg3675
                    last edited by

                    @jcg3675

                    No problem and good to see you already improved it for yourself.

                    If I can repay the favor somehow just let me know.

                    No joke, if you would like to share your favorite recipe with me,
                    I would appreciate.
                    Cooking/grilling/baking is another hobby I like to do. :-)

                    Alan KilbornA jcg3675J 3 Replies Last reply Reply Quote 0
                    • Alan KilbornA
                      Alan Kilborn @Ekopalypse
                      last edited by

                      @Ekopalypse

                      You didn’t elaborate on the magic number of “8”…would have been appreciated.

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

                        @Ekopalypse

                        or maybe the OP already explained the 8.

                        I found that with the script as written, the sync-up won’t happen until one of the cloned-doc views is adjusted horizontally, e.g. the horizontal scroll bar is moved. This is OK to me. I will keep this script close at hand for future need.

                        1 Reply Last reply Reply Quote 1
                        • EkopalypseE
                          Ekopalypse
                          last edited by

                          @Alan-Kilborn, sorry @jcg3675 is right, it is the value for horizontal scroll changes.

                          1 Reply Last reply Reply Quote 1
                          • guy038G
                            guy038
                            last edited by guy038

                            Hello @jcg3675, @ekopalypse, @alan-kilborn and All,

                            I found out a weird but minor bug related to the Smart Highlighting when a file is cloned in the secondary view. Of course, @ekopalypse, this post does not refer to your python script at all, ( script that I have not tested it yet, BTW ! )


                            To begin with, some hypotheses :

                            • N++ version : v7.8.3

                            • No extra plugin installed, just the 3 default ones

                            • Options ticked in Preferences... > Highlighting > Smart Highlighting : Enable, Match whole word only and Highlight another view. All the other options un-ticked

                            • Disable the multi-line tabs feature by un-ticking the option Preferences... > General > Tab Bar > Multi-line => 1 row of tabs, only !

                            • The Horizontal splitter between primary and secondary is selected. If not, simply right-click on the splitter and choose the Rotate to left option

                            • Default zoom is used, both, in primary and secondary view ( Ctrl + Numpad / )

                            • No horizontal nor vertical synchronization of the two views. So, un-tick the options View > Synchronize Vertical Scrolling and View > Synchronize Horizontal Scrolling

                            • For readability, enable the line numbers column, in Preferences... > Editing > Display line number


                            Now :

                            • Open a new tab

                            • Hit the Enter key to create 20 empty lines

                            • Then , append 10 lines containing the string ABCDE ( so, from lines 21 to 30 )

                            • End with 2 empty lines ( lines 31 and 32 )

                            • Save it as Test.txt

                            • Select the option View > Move/Clone Current Document > Clone to Other View => The cloned document Test.txt is located at bottom of screen

                            • Move line 16 as the first line in the secondary view

                            • Now, select the original Test.txt tab, on top of screen

                            • In the same way, move line 16 as the first line of the primary view

                            • Double-click on line 23 of the primary view => The ten lines ABCDE, in each view, are highlighted, as expected

                            • Then, while keeping the mouse pointer over the primary view, scroll down , with the mouse wheel ( or with the vertical bar ) , until no text is present => Only the visible line(s) of the primary view is/are highlighted in the secondary view !

                            • Now, scroll up, with the mouse wheel, until no text is present => In the same way, only the visible line(s) of the primary view is/are highlighted in the secondary view !


                            Remarks :

                            • If, without changing the active top tab ( primary view ), we place the mouse pointer over the secondary view and scroll up/down, with the mouse wheel, nothing is changed in the primary view and the ten lines are always highlighted

                            • If we stop and re-start Notepad++ with the Test.txt displayed in each view, this minor bug still occurs

                            • I also noticed this behaviour, with the old N++ 7.2 version, which was the first release which included the Highlight another view option, regarding the Smart Highlighting feature !

                            • Although not tested, I suppose that the recent v7.8.4 version does produce the same bug


                            Important :

                            • Instead of cloning the file Test.txt, in the secondary view, let’s create a copy of the file Test.txt, named Copy.txt

                            • Open this new file, in the secondary view, with the option View > Move/Clone Current Document > Move to Other View

                            • This time, if we repeat the above steps, whatever the visible lines ABCDE, in the primary view, obtained by scrolling text up or down, the ten lines ABCDE of the identical file Copy.txt are always highlighted, in the secondary view, as expected !

                            Best Regards,

                            guy038

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

                              @guy038 said in Select the same line in both views of cloned document.:

                              this minor bug

                              Should you also do THIS with it?

                              1 Reply Last reply Reply Quote 2
                              • EkopalypseE
                                Ekopalypse
                                last edited by

                                I discovered something similar when using the new method multipleSelectAddNext.

                                If I use your test and having in the top view only two occurrences of the word ABCDE visible, placing the caret within the first visible word ABCDE and I run editor.multipleSelectAddNext(), it only selects the two visible lines.

                                The documentation states, that it does that for the current target. Now it might be, that either scintilla or npp set the visible lines as the current target automatically, or that this is a bug. Needs to be checked.

                                1 Reply Last reply Reply Quote 1
                                • EkopalypseE
                                  Ekopalypse
                                  last edited by Ekopalypse

                                  1 Reply Last reply Reply Quote 1
                                  • guy038G
                                    guy038
                                    last edited by

                                    Hello, @jcg3675, @ekopalypse, @alan-kilborn and All,

                                    So, with some delay, I created an issue on GitHub :

                                    issue#7910

                                    Cheers,

                                    guy038

                                    1 Reply Last reply Reply Quote 4
                                    • jcg3675J
                                      jcg3675 @Ekopalypse
                                      last edited by

                                      @Ekopalypse Well I am more of a microwave dinner and Ramen noodle kind of guy at the moment, being a college student and all :)

                                      But I do have a suggestion–my family makes Lithuanian cracker stuffing a couple of times a year for the big holidays. My dad’s side has made it every year since they came to America in the 1910s.

                                      The recipe that I linked is pretty accurate, but there are a few modifications:
                                      Replace chopped giblets with diced turkey bacon bits
                                      Replace saltine crackers with milk crackers

                                      And that should do it. Let me know how it goes!

                                      EkopalypseE 1 Reply Last reply Reply Quote 3
                                      • EkopalypseE
                                        Ekopalypse @jcg3675
                                        last edited by

                                        @jcg3675
                                        Thank you very much and yes, there is time when a microwave becomes the best invention since sliced bread :-)

                                        Let me know how it goes!

                                        I sure will do.

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