IDE Select & Highlight

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

IDE Select & Highlight

Post 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?
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: IDE Select & Highlight

Post by Mistrel »

+1

I love this feature in Notepad++.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: IDE Select & Highlight

Post by Kukulkan »

Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: IDE Select & Highlight

Post by Foz »

My apologies for creating a new thread - I had done a search, but I hadn't searched hard enough. :oops:
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: IDE Select & Highlight

Post by Tenaja »

...and my request predates the previous link by about a year:
http://www.purebasic.fr/english/viewtop ... ht#p340278
ssb
User
User
Posts: 44
Joined: Wed Jun 21, 2006 11:09 am

Re: IDE Select & Highlight

Post by ssb »

Count my vote for this too!
Never understood why so many useful features of Scintilla have been disabled in Purebasic IDE.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: IDE Select & Highlight

Post 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.
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: IDE Select & Highlight

Post 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());
    }
}
 
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: IDE Select & Highlight

Post 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++.
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: IDE Select & Highlight

Post by xorc1zt »

notepad++ only do the highlighting on the visible part of the text.

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

line 78
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: IDE Select & Highlight

Post 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:
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: IDE Select & Highlight

Post 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...
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: IDE Select & Highlight

Post by c4s »

I can't +1 this feature request enough as it's very useful! +1
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: IDE Select & Highlight

Post 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.
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: IDE Select & Highlight

Post by xorc1zt »

did you read the first post ? :D
Post Reply