[Geany-Devel] pull request on GitHub, to add GeanyHighlightSelectedWords, into Geany Plugins

Colomban Wendling lists.ban at xxxxx
Sat May 30 01:09:39 UTC 2015


Le 30/05/2015 01:45, Matthew Brush a écrit :
> […]
> I was thinking something like this for implementation:
> - Have a preference to enable the feature (since it would now be
> automatic). Have the preference turned off by default. Put the
> preference in "Preferences->Editor->Display" as a checkbox called
> "Highlight current word" or similar. Or would it be better under
> "Preferences->Editor->Features"?
> - Use a different indicator number than the current "Mark All" feature,
> so it won't clash with the one used for the Search dialog and can have
> different styling.
> - Remove the "Mark All" keybinding. Also make these new indicator types
> not cleared by the "Document->Remove Markers" menu item.

As said on IRC, I probably would rather combine the two feature (current
"mark all" [shift-ctrl+m] and this dynamic version of it).

E.g, have a setting in the preferences "Dynamically mark the current
word" that decides whether mark all is dynamic or not, and have
shift+ctrl+m toggle the marking, whether it's dynamic or not.

on_toggle_mark() {
    if ((dynamic && active) || (!dynamic && current_char_is_marked())
    active = dynamic && !active;

on_caret_moved() {
    /* if enabled and current word is not already marked */
    if (dynamic && active && !current_char_is_marked()) {

> […]
> - If there is a current word and it's different from the last one, clear
> the indicators and then have Scintilla close its gap buffer by getting
> the character pointer to it.
> - Use strstr() starting at the character pointer to the buffer start,
> comparing the bytes with the bytes of the current word, working its way
> through the whole document.
> - For each non-NULL return of strstr(), set an indicator at position
> `foundPtr - docStartPtr` with the indicator length as the number of
> bytes in the current word, and then use strstr() again starting at
> `foundPtr + currentWordLength`, repeat to end.

Why not use the basic Scintilla search features?  It should be fast and
do just what you want just as easily -- and look like it's the expected
way you do it, which may even not need closing the gave or something.

> Does that sound fairly reasonable?
> The only thing I'm not 100% sure about is handling of multi-byte
> characters in the UTF-8 of the wordchars or the buffer, but it seems
> like it should "just work" since it's just comparing raw bytes, and at
> worst, setting a indicator position in Scintilla that is between two
> bytes of the same multi-byte char (but not moving the caret there, so no
> weird editing bugs).

you shouldn't have to worry about that.  we already have a way to get
the word under cursor, so just use that and don't worry about how it's
done (we can always fix it if it doesn't get it right, but it seem to be
good enough as nobody complained).


More information about the Devel mailing list