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 thenotificationto plugins. Which means there’s no sense to modify e.g.notification->nmhdr.codeinside 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
SetWindowLongPtrwithGWLP_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_INSERTCHECKis an interesting way indeed.
In this case, how can I understand whetherSC_MOD_INSERTCHECKis the result of a character being typed or the result of pasting from the clipboard? -
being typed or the result of pasting
hmm … I think you need to subclass the Scintilla control and check for the WM_PASTE message. The scintilla api, to my knowledge, has no way of letting you know that. But is it even important to know the difference?
-
@Ekopalypse
In terms of XBrackets behavior, the difference between typing and pasting is important.
When a user types ‘[’, XBrackets will autocomplete it with ‘]’.
When a user pastes “[”, XBrackets will not react. -
Eventually, it seems the best solution is to subclass Scintilla’s WndProc (for both Main and Secondary Scintilla window) and to handle WM_CHAR there.
The benefits:- no need to bother with Scintilla’s native notifications and their nuances;
- full control and clarity of what happens and when it happens: within own WM_CHAR handler, we are able to process a character before it goes to Scintilla and after it goes to Scintilla;
- simplified code because all the logic is controlled by you and there is no need to conform to Scintilla’s way of processing the events.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login