• Login
Community
  • Login

Need help with disabling the autocomplete and the "smart hightlighting"

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
14 Posts 3 Posters 7.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.
  • D
    dail
    last edited by Jun 17, 2016, 12:13 PM

    @Kasper-Graversen

    The SCN_UPDATEUI notification carries the SC_UPDATE_SELECTION flag to tell you if the selection has changed. This may help your logic a bit.

    1 Reply Last reply Reply Quote 0
    • K
      Kasper Graversen
      last edited by Jun 17, 2016, 6:17 PM

      @dail thanks but I still need to detect a change of the cursor position - or is that also regarded a selection? I’ll try it out.

      1 Reply Last reply Reply Quote 0
      • D
        dail
        last edited by Jun 17, 2016, 6:43 PM

        Hmm…good question, I’m not sure.

        K 1 Reply Last reply Jun 17, 2016, 7:01 PM Reply Quote 0
        • K
          Kasper Graversen @dail
          last edited by Kasper Graversen Jun 17, 2016, 7:02 PM Jun 17, 2016, 7:01 PM

          @dail no worries… I’ll fiddle with it… just found all these internal indicators… man there are a lot of #define’s that are not part of the plugin pack. Maybe I should instead write a simple .h parser and get all those values over to the plugin pack first… yeah I got the NPPM_INTERNAL_CLEARINDICATOR working… just need to call it at the right moment in time ;)

          1 Reply Last reply Reply Quote 0
          • D
            dail
            last edited by Jun 17, 2016, 7:14 PM

            I can’t say for sure but I think NPPM_INTERNAL_xxx are not really meant for plugin developers to use. Not saying they won’t work, just that there may be some caveats when using them (e.g. when and how)

            1 Reply Last reply Reply Quote 0
            • K
              Kasper Graversen
              last edited by Jun 17, 2016, 9:28 PM

              @dail yeah sounds pretty internal. but when N++ exposes no other way, what to do?

              C 1 Reply Last reply Jun 17, 2016, 10:10 PM Reply Quote 0
              • C
                Claudia Frank @Kasper Graversen
                last edited by Jun 17, 2016, 10:10 PM

                @Kasper-Graversen

                I assume the SCN_MODIFIED isn’t needed is it?
                Afaik when you add or delete text you also get an SCN_UPDATEUI message.
                So I assume that your EnsureFirstWordIsSelected function does the work twice.

                I think one situation isn’t covered (maybe it isn’t needed?).
                Assuming that your rebase file is the current active document, restart npp
                and you shouldn’t have anything selected, right?
                Afaik, when you start/restart npp you don’t get FILE… or BUFFERACTIVATED messages.
                I use the READY message to check for.

                And of course, dail is right. The message isn’t officially supported so you might have a solution which one day breaks.
                The only other way I can think of is to call the scintilla clear indicator itself but problem is the same,
                an internal code change can break it.

                So, as my mentor always said, if there is a way to solve the problem, do it, as long as there is no official way to do it.

                Cheers
                Claudia

                1 Reply Last reply Reply Quote 0
                • K
                  Kasper Graversen
                  last edited by Jun 19, 2016, 6:44 PM

                  Hi Claudia

                  thanks for the reply.

                  Afaik when you add or delete text you also get an SCN_UPDATEUI message.
                  So I assume that your EnsureFirstWordIsSelected function does the work twice.

                  Yes, but Im caching the position of my last selection - so I dont reselect if it is the same position. This reduces the amount of re-selects drastically, but then I need to know if the buffer changes. I’ve found a better experience is to set the cached value to null on buffer change however.

                  Regarding the restart of npp Im not too worried as you wouldn’t do that under a git rebase - but nice to know ;)

                  C 1 Reply Last reply Jun 20, 2016, 1:10 AM Reply Quote 0
                  • C
                    Claudia Frank @Kasper Graversen
                    last edited by Claudia Frank Jun 20, 2016, 1:11 AM Jun 20, 2016, 1:10 AM

                    Hello Kasper,

                    I’m not a c# expert. We do talk about this code, do we?

                        private static void EnsureFirstWordIsSelected(ScNotification notification)
                        {
                    	    if (isPluginActive)
                    	    {
                    		    if (notification.Header.Code == (ulong) SciMsg.SCN_UPDATEUI)
                    		    {
                    			    var scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                    			    var currentPosition = scintillaGateway.GetCurrentPos();
                    			    if (currentPosition != lastPositionWhenUiUpdate)
                    			    {
                    				    if (scintillaGateway.GetSelectionEmpty())
                    				    {
                    					    lastPositionWhenUiUpdate = firstWordSelector.SelectFirstWordOfLine(scintillaGateway);
                    				    }
                    			    }
                    			    return;
                    		    }
                    
                    		    if (notification.Header.Code == (ulong) SciMsg.SCN_MODIFIED)
                    		    {
                    			    var isTextInsertedOrDeleted = (notification.ModificationType &
                    			                                   ((int) SciMsg.SC_MOD_INSERTTEXT | (int) SciMsg.SC_MOD_DELETETEXT)) > 0;
                    			    if (isTextInsertedOrDeleted)
                    			    {
                    				    var scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                    				    firstWordSelector.SelectFirstWordOfLine(scintillaGateway);
                    			    }
                    		    }
                    

                    From my point of view

                    		    if (notification.Header.Code == (ulong) SciMsg.SCN_MODIFIED)
                    		    {
                    			    var isTextInsertedOrDeleted = (notification.ModificationType &
                    			                                   ((int) SciMsg.SC_MOD_INSERTTEXT | (int) SciMsg.SC_MOD_DELETETEXT)) > 0;
                    			    if (isTextInsertedOrDeleted)
                    			    {
                    				    var scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                    				    firstWordSelector.SelectFirstWordOfLine(scintillaGateway);
                    			    }
                    		    }
                    

                    is unnecessary. Let me explain why I’m thinking this is the case.

                    Whenever some adds or deletes text you will get SCN_MODIFIED and SCN_UPDATEUI events for this user action.
                    So both if statements get always executed and it seems that SCN_MODIFIED if block is just a subset
                    of SCN_UPDATEUI if block so there is no difference in regards of the editor action.

                    Do I miss something?

                    Cheers
                    Claudia

                    1 Reply Last reply Reply Quote 0
                    • K
                      Kasper Graversen
                      last edited by Jun 20, 2016, 8:47 PM

                      @Claudia-Frank yes that’s the code. but notice my caching of the selection “computation”

                       if (currentPosition != lastPositionWhenUiUpdate)
                      

                      if I select the first word and press PASTE and pasting another word of the same length, I need to select the new word. the currentposition is unchanged, so my if statement would not re-select.

                      the latest version of the code has become slightly simplified

                      		if (isPluginActive)
                      		{
                      			nppResource.ClearIndicator();
                      
                      			if (notification.Header.Code == (ulong) SciMsg.SCN_UPDATEUI)
                      			{
                      				var scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                      				var currentPosition = scintillaGateway.GetCurrentPos();
                      				if (currentPosition != lastPositionWhenUiUpdate)
                      				{
                      					if (scintillaGateway.GetSelectionEmpty())
                      					{
                      						lastPositionWhenUiUpdate = firstWordSelector.SelectFirstWordOfLine(scintillaGateway);
                      					}
                      				}
                      				return;
                      			}
                      
                      			if (notification.Header.Code == (ulong)SciMsg.SCN_MODIFIED)
                      			{
                      				var isTextInsertedOrDeleted = (notification.ModificationType &
                      											   ((int)SciMsg.SC_MOD_INSERTTEXT | (int)SciMsg.SC_MOD_DELETETEXT)) > 0;
                      				if (isTextInsertedOrDeleted)
                      				{
                      					lastPositionWhenUiUpdate = null;
                      				}
                      			}
                      		}
                      	}
                      
                      C 1 Reply Last reply Jun 20, 2016, 11:01 PM Reply Quote 0
                      • C
                        Claudia Frank @Kasper Graversen
                        last edited by Jun 20, 2016, 11:01 PM

                        @Kasper-Graversen

                        Ahh, now I understand. Thx for clarification.

                        Cheers
                        Claudia

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