Re: Optimize Notification processing
Mitchell <[email protected]> Sun, 18 May 2025 18:28:17 -0400
| Newsgroups | gmane.comp.lib.scintilla.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, > On May 18, 2025, at 5:40 PM, Jean Lalonde <[email protected]> wrote: > > Thanks for the help Mitchell. > > Sorry but I'm (easily) confused. And I'm not very familiar with events and masks... > >> I could be wrong, but you may be able to get away with just listening for `SCN_UPDATEUI` and `SCN_CHARADDED` and setting the mod mask to 0 to ignore them all: >> - For `SCN_UPDATEUI`, `updated & (SC_UPDATE_CONTENT | SC_UPDATE_SELECTION) > 0` can be used for detecting position, content and selection changes. >> - For `SCN_CHARADDED`, if `ch` is 10, the user pressed enter and you can perform auto-indent. > > How would you translate this into pseudo code? What does mean " setting the mod mask to 0 to ignore them all"? Yes, this can all be tricky to understand and get right. I’ve been there, and I could still be wrong :) `os_Sci.SETMODEVENTMASK(0)` turns off all `SCN_MODIFIED` events. Those are the insert text, delete text, etc. It can be very noisy, which is why Scintilla provides this message for you to pick and choose the modifications you care about. If you don’t care about any of them, you can use set to 0 as an optimization. You don’t use `SETMODEVENTMASK` with `SCN_UPDATEUI` or `SCN_CHARADDED`. Your `SciOnNotify` handler will always receive them (e.g. code 2007 for SCN_UPDATEUI, 2001 for SCN_CHARADDED), as you can see in your log. Using my suggestions, your SciOnNotify handler might look like this: ``` if (obj.SCNCode == SCN_UPDATEUI && (obj.updated & (SC_UPDATE_CONTENT | SC_UPDATE_SELECTION) > 0)) { // Either the document’s content or selection changed. // You can query its length, selection position, etc. to update your status bar. } else if (obj.SCNCode == SCN_CHARADDED && obj.char == 10) { // The user pressed enter, so you can do auto-indent. } ``` I hope that helps. Cheers, Mitchell > > I tested the mask o_Sci.SETMODEVENTMASK(SCN_UPDATEUI|SCN_CHARADDED) and logged the events. I'm getting SCN_UPDATEUI and SCN_CHARADDED events but also other types as shown by the following extracts (only one by type) from my log file: > > 20250518@17:17:20.199 SciOnNotify obj.SCNCode 2007 SCN_UPDATEUI > 20250518@17:17:20.200 SciOnNotify obj.modType 0 > 20250518@17:17:20.205 SciOnNotify obj.Ch 0 > 20250518@17:17:20.210 SciOnNotify obj.modifiers 0 > > 20250518@17:17:21.039 SciOnNotify obj.SCNCode 2000 SCN_STYLENEEDED > 20250518@17:17:21.039 SciOnNotify obj.modType 0 > 20250518@17:17:21.045 SciOnNotify obj.Ch 0 > 20250518@17:17:21.050 SciOnNotify obj.modifiers 0 > > 20250518@17:17:21.204 SciOnNotify obj.SCNCode 2028 UNKNOWN_2028 > 20250518@17:17:21.204 SciOnNotify obj.modType 0 > 20250518@17:17:21.211 SciOnNotify obj.Ch 0 > 20250518@17:17:21.217 SciOnNotify obj.modifiers 0 > > 20250518@17:17:21.279 SciOnNotify obj.SCNCode 2013 SCN_PAINTED > 20250518@17:17:21.284 SciOnNotify obj.modType 0 > 20250518@17:17:21.290 SciOnNotify obj.Ch 0 > 20250518@17:17:21.297 SciOnNotify obj.modifiers 0 > > 20250518@17:17:23.662 SciOnNotify obj.SCNCode 2008 SCN_MODIFIED > 20250518@17:17:23.662 SciOnNotify obj.modType 4466765987840 > 20250518@17:17:23.669 SciOnNotify obj.Ch 0 > 20250518@17:17:23.675 SciOnNotify obj.modifiers 0 > > When adding a new line: > > 20250518@17:17:23.740 SciOnNotify obj.SCNCode 2001 SCN_CHARADDED > 20250518@17:17:23.744 SciOnNotify obj.modType 0 > 20250518@17:17:23.750 SciOnNotify obj.Ch 55834574848 > 20250518@17:17:23.756 SciOnNotify obj.modifiers 13 > 20250518@17:17:23.763 SciOnNotify obj.SCNCode 2001 SCN_CHARADDED > 20250518@17:17:23.768 SciOnNotify obj.modType 0 > 20250518@17:17:23.773 SciOnNotify obj.Ch 42949672960 > 20250518@17:17:23.779 SciOnNotify obj.modifiers 10 > > 20250518@17:17:26.345 SciOnNotify obj.SCNCode 2029 UNKNOWN_2029 > 20250518@17:17:26.345 SciOnNotify obj.modType 0 > 20250518@17:17:26.352 SciOnNotify obj.Ch 0 > 20250518@17:17:26.358 SciOnNotify obj.modifiers 0 > > 20250518@17:17:27.710 SciOnNotify obj.SCNCode 2028 UNKNOWN_2028 > 20250518@17:17:27.710 SciOnNotify obj.modType 0 > 20250518@17:17:27.717 SciOnNotify obj.Ch 0 > 20250518@17:17:27.723 SciOnNotify obj.modifiers 0 > > FYI, I'm using Scintilla.DLL v3.7.6 with a wrapper written in AutoHotkey v1. > > Le dimanche 18 mai 2025 à 15 h 57 min 04 s UTC-4, Mitchell a écrit : > Hi, > >> On May 18, 2025, at 3:40 PM, Jean Lalonde <[email protected]> wrote: >> >> Hi, >> >> I'd like to check with you if I have the optimal setting to minimize the number of notifications but get all those I need to update the status bar with the length of text in the editor, length of selected text, position of the caret (line, column), etc. and to process line auto-indentation (as explained in Scintilla Usage Notes). >> >> I'm setting this event mask: >> >> o_Sci.SETMODEVENTMASK(SCN_MODIFIED) ; eventMask can be SCN_MODIFIED or SC_MOD_INSERTTEXT|SC_MOD_DELETETEXT > > I could be wrong, but you may be able to get away with just listening for `SCN_UPDATEUI` and `SCN_CHARADDED` and setting the mod mask to 0 to ignore them all: > - For `SCN_UPDATEUI`, `updated & (SC_UPDATE_CONTENT | SC_UPDATE_SELECTION) > 0` can be used for detecting position, content and selection changes. > - For `SCN_CHARADDED`, if `ch` is 10, the user pressed enter and you can perform auto-indent. > > Cheers, > Mitchell > >> >> I'm setting the notification handler with this: >> >> o_Sci.NOTIFY := "SciOnNotify" >> >> And inside SciOnNotify(), I first update the status bar: >> >> if (obj.SCNCode == SCN_CHARADDED and obj.Modifiers = 10) ; SCN_CHARADDED:=2001, 10 for LF >> { >> Gosub, AutoIndent >> } >> >> ... and update the status bar: >> >> if (obj.SCNCode = SCN_MODIFIED) ; SCN_MODIFIED:=2008 >> and (obj.ModType != 20) ; SC_MOD_CHANGESTYLE := 0x4 | SC_PERFORMED_USER := 0x10 = 0x14 = 20 >> { >> Gosub, UpdateStatusbar >> } >> >> This works for what I need. But can it be optimized? >> >> Thanks you for your input. >> >> -- >> You received this message because you are subscribed to the Google Groups "scintilla-interest" group. >> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. >> To view this discussion visit https://groups.google.com/d/msgid/scintilla-interest/ea0c2cfa-4f75-450a-bf53-6ca85121e586n%40googlegroups.com. > > > -- > You received this message because you are subscribed to the Google Groups "scintilla-interest" group. > To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. > To view this discussion visit https://groups.google.com/d/msgid/scintilla-interest/e284991d-c5ec-42bd-880a-804a0b02cca6n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "scintilla-interest" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/scintilla-interest/08D12005-6586-40C8-8745-705ED7CB430A%40foicica.com.