Page 1 of 2

IDE Select & Highlight

Posted: Wed May 16, 2012 12:52 am
by Foz
One of the things that I use in Scintilla based programs (either Scite or Notepad++) is the ability to highlight the same word - highly useful when coming to refactoring your variable names.

In Scite, I uncomment:

Code: Select all

highlight.current.word=1
highlight.current.word.by.style=1
highlight.current.word.colour=#00D040
Could this be added to the IDE? Or is it available and I've missed it?

Re: IDE Select & Highlight

Posted: Wed May 16, 2012 2:56 am
by Mistrel
+1

I love this feature in Notepad++.

Re: IDE Select & Highlight

Posted: Wed May 16, 2012 7:02 am
by Kukulkan

Re: IDE Select & Highlight

Posted: Wed May 16, 2012 11:27 am
by Foz
My apologies for creating a new thread - I had done a search, but I hadn't searched hard enough. :oops:

Re: IDE Select & Highlight

Posted: Wed May 16, 2012 5:23 pm
by Tenaja
...and my request predates the previous link by about a year:
http://www.purebasic.fr/english/viewtop ... ht#p340278

Re: IDE Select & Highlight

Posted: Thu May 17, 2012 12:27 am
by ssb
Count my vote for this too!
Never understood why so many useful features of Scintilla have been disabled in Purebasic IDE.

Re: IDE Select & Highlight

Posted: Thu May 17, 2012 12:44 am
by Tenaja
ssb wrote:Count my vote for this too!
Never understood why so many useful features of Scintilla have been disabled in Purebasic IDE.
This is not actually a "feature of scintilla." It is a feature that is commonly implemented in editors that use scintilla, but it is manually coded in each. It is not like the "goto line #" feature that is a single function call. With Smart Highlighting, you have to manually grab the highlighted text, then manually search for each occurrence and then manually shade them. All the while tracking when views and selections change to add and remove highlighting, etc. There are some simple examples online, but they are always lacking features.

Re: IDE Select & Highlight

Posted: Thu May 17, 2012 1:14 am
by xorc1zt
from scite

Code: Select all

void SciTEBase::HighlightCurrentWord(bool highlight) {
    if (!currentWordHighlight.isEnabled)
        return;
    GUI::ScintillaWindow &wCurrent = wOutput.HasFocus() ? wOutput : wEditor;
    // Remove old indicators if any exist.
    wCurrent.Call(SCI_SETINDICATORCURRENT, indicatorHightlightCurrentWord);
    int lenDoc = wCurrent.Call(SCI_GETLENGTH);
    wCurrent.Call(SCI_INDICATORCLEARRANGE, 0, lenDoc);
    if (!highlight)
        return;
    // Get start & end selection.
    int selStart = wCurrent.Call(SCI_GETSELECTIONSTART);
    int selEnd = wCurrent.Call(SCI_GETSELECTIONEND);
    bool noUserSelection = selStart == selEnd;
    SString wordToFind = RangeExtendAndGrab(wCurrent, selStart, selEnd,
            &SciTEBase::islexerwordcharforsel);
    if (wordToFind.length() == 0 || wordToFind.contains('\n') || wordToFind.contains('\r'))
        return; // No highlight when no selection or multi-lines selection.
    if (noUserSelection && currentWordHighlight.statesOfDelay == currentWordHighlight.noDelay) {
        // Manage delay before highlight when no user selection but there is word at the caret.
        currentWordHighlight.statesOfDelay = currentWordHighlight.delay;
        // Reset timer
        currentWordHighlight.elapsedTimes.Duration(true);
        return;
    }
    // Get style of the current word to highlight only word with same style.
    int selectedStyle = wCurrent.Call(SCI_GETSTYLEAT, selStart);

    // Manage word with DBCS.
    wordToFind = EncodeString(wordToFind);

    // Case sensitive & whole word only.
    wCurrent.Call(SCI_SETSEARCHFLAGS, SCFIND_MATCHCASE | SCFIND_WHOLEWORD);
    wCurrent.Call(SCI_SETTARGETSTART, 0);
    wCurrent.Call(SCI_SETTARGETEND, lenDoc);
    // Find the first occurrence of word.
    int indexOf = wCurrent.CallString(SCI_SEARCHINTARGET,
            wordToFind.length(), wordToFind.c_str());
    while (indexOf != -1 && indexOf < lenDoc) {
        if (!currentWordHighlight.isOnlyWithSameStyle || selectedStyle ==
                wCurrent.Call(SCI_GETSTYLEAT, indexOf)) {
            wCurrent.Call(SCI_INDICATORFILLRANGE, indexOf, wordToFind.length());
        }
        // Try to find next occurrence of word.
        wCurrent.Call(SCI_SETTARGETSTART, indexOf + wordToFind.length() + 1);
        wCurrent.Call(SCI_SETTARGETEND, lenDoc);
        indexOf = wCurrent.CallString(SCI_SEARCHINTARGET, wordToFind.length(),
                wordToFind.c_str());
    }
}
 

Re: IDE Select & Highlight

Posted: Thu May 17, 2012 5:26 am
by Tenaja
I have seen that in the source, but can't for the life of me find the setting to turn it on! (I like NP++ and PN enough that I don't really use Scite.)

I have seen other very similar routines, and when you have a large file open, they are very laggy since it updates the entire document each time. As it is, using Gosci, it is already more than four times as slow as Notepad++, and I have slimmed Gosci down quite a bit, too. I don't know if it is the better compiler optimization, or just the lighter weight "generic" lexer, but with the PB compiled version taking so much longer I wouldn't want to run that search & style through with every highlight on large files.

For reference, I duplicated a file until it was just over 200k lines. Notepad++ styled it in under 5 seconds (the entire doc) and using PB and Gosci (compiled to exe), it took over 25. Sure, that is a very long file, but 10,000 lines is very normal, and that is still about 1.5 seconds, compared to less than 1/2 second for NP++.

Re: IDE Select & Highlight

Posted: Thu May 17, 2012 2:58 pm
by xorc1zt
notepad++ only do the highlighting on the visible part of the text.

http://notepad-plus.svn.sourceforge.net ... iew=markup

line 78

Re: IDE Select & Highlight

Posted: Thu May 17, 2012 3:10 pm
by Demivec
Tenaja wrote:...and my request predates the previous link by about a year:
http://www.purebasic.fr/english/viewtop ... ht#p340278
And yours is predated by this one by eight months. :mrgreen:

Re: IDE Select & Highlight

Posted: Thu May 17, 2012 4:04 pm
by Tenaja
Demivec wrote:
Tenaja wrote:...and my request predates the previous link by about a year:
http://www.purebasic.fr/english/viewtop ... ht#p340278
And yours is predated by this one by eight months. :mrgreen:
Wow, so oft requested...

Re: IDE Select & Highlight

Posted: Thu May 17, 2012 4:05 pm
by c4s
I can't +1 this feature request enough as it's very useful! +1

Re: IDE Select & Highlight

Posted: Thu May 17, 2012 4:31 pm
by Tenaja
xorc1zt wrote:from scite

Code: Select all

void SciTEBase::HighlightCurrentWord(bool highlight) {
    if (!currentWordHighlight.isEnabled)
        return;
    GUI::ScintillaWindow &wCurrent = wOutput.HasFocus() ? wOutput : wEditor;
    // Remove old indicators if any exist.
    wCurrent.Call(SCI_SETINDICATORCURRENT, indicatorHightlightCurrentWord);
    int lenDoc = wCurrent.Call(SCI_GETLENGTH);
    wCurrent.Call(SCI_INDICATORCLEARRANGE, 0, lenDoc);
    if (!highlight)
        return;
    // Get start & end selection.
    int selStart = wCurrent.Call(SCI_GETSELECTIONSTART);
    int selEnd = wCurrent.Call(SCI_GETSELECTIONEND);
    bool noUserSelection = selStart == selEnd;
    SString wordToFind = RangeExtendAndGrab(wCurrent, selStart, selEnd,
            &SciTEBase::islexerwordcharforsel);
    if (wordToFind.length() == 0 || wordToFind.contains('\n') || wordToFind.contains('\r'))
        return; // No highlight when no selection or multi-lines selection.
    if (noUserSelection && currentWordHighlight.statesOfDelay == currentWordHighlight.noDelay) {
        // Manage delay before highlight when no user selection but there is word at the caret.
        currentWordHighlight.statesOfDelay = currentWordHighlight.delay;
        // Reset timer
        currentWordHighlight.elapsedTimes.Duration(true);
        return;
    }
    // Get style of the current word to highlight only word with same style.
    int selectedStyle = wCurrent.Call(SCI_GETSTYLEAT, selStart);

    // Manage word with DBCS.
    wordToFind = EncodeString(wordToFind);

    // Case sensitive & whole word only.
    wCurrent.Call(SCI_SETSEARCHFLAGS, SCFIND_MATCHCASE | SCFIND_WHOLEWORD);
    wCurrent.Call(SCI_SETTARGETSTART, 0);
    wCurrent.Call(SCI_SETTARGETEND, lenDoc);
    // Find the first occurrence of word.
    int indexOf = wCurrent.CallString(SCI_SEARCHINTARGET,
            wordToFind.length(), wordToFind.c_str());
    while (indexOf != -1 && indexOf < lenDoc) {
        if (!currentWordHighlight.isOnlyWithSameStyle || selectedStyle ==
                wCurrent.Call(SCI_GETSTYLEAT, indexOf)) {
            wCurrent.Call(SCI_INDICATORFILLRANGE, indexOf, wordToFind.length());
        }
        // Try to find next occurrence of word.
        wCurrent.Call(SCI_SETTARGETSTART, indexOf + wordToFind.length() + 1);
        wCurrent.Call(SCI_SETTARGETEND, lenDoc);
        indexOf = wCurrent.CallString(SCI_SEARCHINTARGET, wordToFind.length(),
                wordToFind.c_str());
    }
}
 
I found how to activate this. You must edit the SciTEGlobal.properties file, and uncoment (remove the # character) from the line that has the setting:
change:
#highlight.current.word=1
to:
highlight.current.word=1

So apparently Scite's biggest drawback is the lack of dialog boxes for changing properties. You also have to edit properties files to save the "recent file" list, and a whole bunch of other features people would expect. I haven't figure out how to get the PB syntax to work, though, even adding it to the list and all the other stuff that would seem necessary.

Re: IDE Select & Highlight

Posted: Thu May 17, 2012 5:52 pm
by xorc1zt
did you read the first post ? :D