Auto-Completion Popup is unexpectedly shown when handling SCN_CHARADDED
-
I have the following Notepad++ settings under the Preferences -> Auto-Completion:
- [v] Enable auto-completion on each input
- (*) Function and word completion
- [v] Function parameters hint on input
- From 2nd character
This is to have the pretty nice Auto-Completion Popup while I’m typing.
Now, I have the source code that basically does the following:
extern "C" __declspec(dllexport) void beNotified(SCNotification* pscn) { switch ( pscn->nmhdr.code ) { case SCN_CHARADDED: if (pscn->ch == '\"') { HWND hSci = (HWND) pscn->nmhdr.hwndFrom; Sci_Position pos = (Sci_Position) SendMessage(hSci, SCI_GETSELECTIONSTART, 0, 0); // position right after the just typed '"' SendMessage(hSci, SCI_SETSEL, pos - 1, pos); // selecting the just typed '"' SendMessage(hSci, SCI_REPLACESEL, 0, (LPARAM)"\"function\""); // replacing the '"' with '"function"' SendMessage(hSci, SCI_SETSEL, pos, pos + 8); // selecting the text within the quotes return; } break; } }
This has the following consequences, while doing that in an XML file:
- when ‘"’ is typed, it is replaced by ‘“function”’ - this is intended and expected;
- at the moment when the text ‘“function”’ appears and its part ‘function’ becomes selected, the Auto-Completion Popup is unexpectedly shown.
Could you suggest why the Auto-Completion Popup is shown and what can I do to prevent it to be shown? Or, at least, to detect that it is shown and then to hide it immediately?
-
@Vitalii-Dovgan said in Auto-Completion Popup is unexpectedly shown when handling SCN_CHARADDED:
Could you suggest why the Auto-Completion Popup is shown and what can I do to prevent it to be shown? Or, at least, to detect that it is shown and then to hide it immediately?
I don’t have an answer to your question, but maybe a place to get started.
Notepad++ processes Scintilla notifications here; it sends notifications to the plugins first, then sends them to its own processing routines. The routine for SCN_CHARADDED is here. The plugin notification routines (here calling here) copy the notification to make sure the plugin can’t change it.
At least that should give you a clue where to look to follow what Notepad++ is doing and see if you can find a way to suppress the unwanted behavior.
-
Hmm, yes, Notepad++'s SCN_CHARADDED handler explicitly shows the Auto-Completion Popup:
Buffer* currentBuf = _pEditView->getCurrentBuffer(); if (currentBuf->allowAutoCompletion()) { AutoCompletion* autoC = isFromPrimary ? &_autoCompleteMain : &_autoCompleteSub; bool isColumnMode = _pEditView->execute(SCI_GETSELECTIONS) > 1; // Multi-Selection || Column mode) if (nppGui._matchedPairConf.hasAnyPairsPair() && !isColumnMode) autoC->insertMatchedChars(notification->ch, nppGui._matchedPairConf); autoC->update(notification->ch); }
And what is even more interesting, the
_pluginsManager.notify(notification);
sends a copy of thenotification
to plugins. Which means there’s no sense to modify e.g.notification->nmhdr.code
inside a plugin.
So… Seems I have two options:- temporarily tune some settings to make
currentBuf->allowAutoCompletion()
return false; - find a way to hide the AutoCompletion Popup if it was shown.
Some hint or additional advice of how to achieve that would be appreciated.
- temporarily tune some settings to make
-
@Vitalii-Dovgan said in Auto-Completion Popup is unexpectedly shown when handling SCN_CHARADDED:
hint
Well, there is a “nuclear option”…
Nothing stops a plugin from using SetWindowSubclass to subclass the main Notepad++ window in order to intercept and preprocess messages.
Example:
- set subclass
- subclass procedure
- what I’m actually doing (making sure tabstops that might be off screen are set before a rectangular selection paste)
I say “nuclear option” because you really need to be careful that you’re not messing up expectations for some other function or plugin. This should be a last resort, because it leaves you free to mess things up entirely.
-
Ah, yes, I believe it is something similar to
SetWindowLongPtr
withGWLP_WNDPROC
. I did it in NppExec many years ago and have forgotten about this approach :)
Well, if there will be no easier option suggested, then I’ll take this way. Thank you! -
I’m preparing a big update to XBrackets Lite, by the way, hence mentioning the quote characters.
Now it will inherit more functionality from XBrackets for AkelPad. -
I assume you could also use SCI_CHANGEINSERTION within the modified notification.
To do this, however, you must request the necessary additional SC_MOD_INSERTCHECK in nppn_ready. -
Thank you,
SC_MOD_INSERTCHECK
is an interesting way indeed.
In this case, how can I understand whetherSC_MOD_INSERTCHECK
is the result of a character being typed or the result of pasting from the clipboard?