Need help with disabling the autocomplete and the "smart hightlighting"
-
@Claudia-Frank said:
to prevent smart highlighting send NPPM_INTERNAL_CLEARINDICATOR message
and to prevent autocomplete set all possible chars as autoCStops chars.Great answer Claudia. I figured out the autoCStops - but I have yet to play around with the clear indicator. Really looking forward to seeing if it works.
Now that you are so much into the details of N++ - perhaps you can help me with the eventhandling. The plugin code is basically this one file https://github.com/kbilsted/NppPluginRebaseAssister/blob/master/RebaseAssister/Main.cs the idea is to call the
FirstWordOfLineSelector.SelectFirstWordOfLine
every time the cursor moves (and only when there is no selection going on from the user).I couldn’t find an event for that so I’m listening to more events but preventing the “expensive” call to
FirstWordOfLineSelector.SelectFirstWordOfLine
by caching the position of the cursor the last time I calledFirstWordOfLineSelector.SelectFirstWordOfLine
. Also I have a boolean indicating wheather the tab is a file I want to react to or not. But its not as readable as if I could say - if the buffer has changed or the cursor pos has changed.thanks
would you mind commenting on my handling of events? To be honest I really only want to recalculate the
-
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. -
@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?
-
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; } } } }
-