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



  • @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.



  • Hmm…good question, I’m not sure.



  • @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 ;)



  • 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)



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



  • @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



  • 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 ;)



  • 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



  • @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;
    				}
    			}
    		}
    	}


  • @Kasper-Graversen

    Ahh, now I understand. Thx for clarification.

    Cheers
    Claudia


Log in to reply