Community
    • Login

    Can Plugin control which lines are marked in green/orange by Change History?

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    10 Posts 4 Posters 619 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.
    • Guido ThelenG
      Guido Thelen
      last edited by Guido Thelen

      Hello,
      when my SQL Formatter Plugin formats a SQL statement it replaces the old non-formatted statement by the new beautified statement with following (simplified) logic

      currentScint.SetSel(posSelStart, posSelEnd);
      currentScint.ReplaceSel(formattedSQL);
      

      Even if the formatted SQL has only 1 line changed or when nothing has been changed, the Change History will show an orange change indicator for all lines.

      677d1bbc-5c2b-4f9c-b327-6bf0fc16926f-grafik.png

      My question: Is there a way to tell the change history indicator which lines to mark in green and which lines to mark in orange. The SQL Formatter plugin knows which lines have changed. So, the plugin could set the indicator by itself.
      Regards
      Guido

      PeterJonesP mpheathM 2 Replies Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @Guido Thelen
        last edited by

        @Guido-Thelen said in Can Plugin control which lines are marked in green/orange by Change History?:

        Hello,
        when my SQL Formatter Plugin formats a SQL statement it replaces the old non-formatted statement by the new beautified statement with following (simplified) logic

        currentScint.SetSel(posSelStart, posSelEnd);
        currentScint.ReplaceSel(formattedSQL);
        

        Even if the formatted SQL has only 1 line changed or when nothing has been changed, the Change History will show an orange change indicator for all lines.

        From a text editor’s perspective, changes to formatting (indentation, newline sequences, etc) are changes, because to do those, you are literally changing the text of the file. So Notepad++ disagrees with your claim that “nothing has been changed” – that “.ReplaceSel()” made a change.

        My question: Is there a way to tell the change history indicator which lines to mark in green and which lines to mark in orange. The SQL Formatter plugin knows which lines have changed. So, the plugin could set the indicator by itself.

        I am not an expert in the Notepad++ codebase, but as far as I know, all Notepad++ does to facilitate the Change History feature is to send the SCI_SETCHANGEHISTORY message to Scinitlla, and possibly the SCI_SETUNDOCOLLECTION, so I’m not sure how a plugin could influence things on the Notepad++ side of that equation, because I believe the “is the line changed” status comes from Scintilla logic.

        However, I don’t know whether or not you can lie to the underlying Scintilla component about whether there have been changes. Looking at the Change History section in the Scintilla documentation, it doesn’t show a way to override the status for a given line, but if you can figure out how to override the markers and/or indicators mentioned there for each line, you might be able to override what Scintilla (and thus Notepad++) think about each line.

        My guess is that Scintilla will fight against you on that, but studying that section, and the marker and/or indicator sections, is probably your best bet to get started down that path, if it is possible.

        Guido ThelenG 1 Reply Last reply Reply Quote 2
        • Alan KilbornA
          Alan Kilborn
          last edited by

          I brushed up against the OP’s problem in a somewhat related way; this PythonScript issue tells my story: https://github.com/bruderstein/PythonScript/issues/272

          It’s an interesting situation…

          Guido ThelenG 1 Reply Last reply Reply Quote 2
          • Guido ThelenG
            Guido Thelen @PeterJones
            last edited by

            @PeterJones Hi Peter, thanks for answering in such detail :-)
            Please open a file with N++, select the whole content with ctrl+A followed by ctrl+C and ctrl+V. The content of the file has not change, it has just been overriden/replaced by itself. The result will be a change history showing the whole file as changed although the content is 100% identical to the saved content.

            Is it the very overriding/replacing which leads to an orange marker? The content has not changed.

            I prefer not to “fight” against Scintilla’s logic ;-)

            Regards
            Guido

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • Guido ThelenG
              Guido Thelen @Alan Kilborn
              last edited by

              @Alan-Kilborn Hi Alan, indeed, it looks like a similar situation. Thanks for letting me know.
              Regards
              Guido

              1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @Guido Thelen
                last edited by

                Please open a file with N++, select the whole content with ctrl+A followed by ctrl+C and ctrl+V. The content of the file has not change, it has just been overriden/replaced by itself. The result will be a change history showing the whole file as changed although the content is 100% identical to the saved content.

                In Scintilla’s mind, that is a change: probably because paste-over-selection involves deleting all the old selected text, and replacing with whatever happens to be in the clipboard; scintilla doesn’t check the contents of the clipboard first before deciding whether it’s a change or not. As far as I understand, that Ctrl+A, Ctrl+C, Ctrl+V is handled essentially completely inside Scintilla (those keys are bound to Scintilla messages, so when Notepad++ receives those keystrokes, it just sends those messages to Scintilla without otherwise intervening), without any Notepad++ involvement. So it’s Scintilla that is using its internal logic to decide that it’s a change, even if the before and after do look the same and compare the same.

                Is it the very overriding/replacing which leads to an orange marker? The content has not changed.

                As far as I understand Scintilla’s logic, yes.

                I prefer not to “fight” against Scintilla’s logic ;-)

                As I’ve explained, the behavior described is Scintilla’s logic. Doing elsewise would require fighting against it.

                1 Reply Last reply Reply Quote 1
                • mpheathM
                  mpheath @Guido Thelen
                  last edited by

                  @Guido-Thelen

                  Scintilla Release 5.3.2

                  • Released 6 December 2022.
                  • Add SCI_REPLACETARGETMINIMAL to change text without causing unchanged prefix and suffix to be marked as modified in change history.

                  might be of use. How good is it compared to SCI_REPLACETARGET I do not know.

                  Guido ThelenG Alan KilbornA 3 Replies Last reply Reply Quote 3
                  • Guido ThelenG
                    Guido Thelen @mpheath
                    last edited by

                    @mpheath thanks for your reply. This looks very promising. I will need some time to test this new feature. As the plugin has been developped using C#, the PluginInfrastructure classes have to be adapted to include this new function (I never did this before). I will let you know about the results.
                    Regards
                    Guido

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

                      @mpheath

                      Your link for SCI_REPLACETARGETMINIMAL seems to be wrong, but attention everyone else, if you click on the SCI_REPLACETARGET link in @mpheath 's posting, you’ll see SCI_REPLACETARGETMINIMAL just below SCI_REPLACETARGET in the Scintilla docs:

                      f5c0a63d-51e0-42dd-928b-112667213b15-image.png

                      1 Reply Last reply Reply Quote 2
                      • Guido ThelenG
                        Guido Thelen @mpheath
                        last edited by

                        @mpheath Actually, the SCI_REPLACETARGETMINIMAL did the trick. In this SQL I just added I linebreak after “FROM” and only the impacted lines are shown in orange

                        9593901a-31e2-4f62-b18b-41940bcef4da-grafik.png

                        OF course, if there was another FROM statement all the lines between the two FROM statements would be shown in orange. This is fine for me.

                        b718760f-f4ab-4c9f-b494-b265093b620b-grafik.png

                        Regards
                        Guido

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