Combine “find next” and “Select and find next” and "find (Volatile) next" to same Shortcut Key F3



  • Hi ,

    Please can you advice how I can Combine “find next” and “Select and find next” and “find (Volatile) next” to same Shortcut Key Like F3 to do both actions. this is was i used to from other text editors (crimson) and is missing to me here

    Thanks



  • @Adeeb-Khair

    The short answer is that you can’t do this because it doesn’t make any sense.
    These are three different commands that do three different things.
    If they were all assigned to the same shortcut key, how would Notepad++ know which you intend to do at any given press of that key?



  • @Adeeb-Khair ,

    The only difference between Find (Volatile) Next and Select and Find Next is that Find (Volatile) Next doesn’t change an internal variable, so the “normal” Find Next will remember the old value, rather than the new. (That is, Select and Find Next on word “x” followed by normal Find Next will still find “x”; whereas Find (Volatile) Next on “y” will find “y”, but going back to normal Find Next will search for “x” again.) If you are wanting a one-key solution, Find (Volatile) Next is not what you want, so we’ll remove that from the mix.

    Further, running Select and Find Next repeatedly does what I assume your end goal is: a single key to just cycle through all the instances of the word that your cursor was on when you started. If that’s the case, then just go to Shortcut Mapper, remove the F3 shortcut from Find Next, and modify the shortcut for Select and Find Next to be F3.

    But note: that means if you use the standard Find dialog to start your search (for a regex search, or whatever) and close your dialog, you won’t have F3 available to find the next instance of that latest regex search.

    If you really use the in-text version more often and are morally opposed to hitting the Ctrl modifier for your in-text search, but occasionally want to be able to Find Next after closing the Find dialog, then swap the shortcuts so that Select and Find Next is normal F3 and the plain Find Next is Ctrl+F3.

    Personally, I would just leave things as-is, and try to learn your new editor, rather than expecting all editors to behave like your old one. All you have to do to get the single keystroke functionality is to learn that Ctrl+F3 Select and Find Next is the way to do single-word find-next directly from the text, whereas a plain F3 is meant for finding the next occurrence after you’ve closed the Find dialog.

    But Notepad++ cannot distinguish between your intentions after exiting the Find dialog, and if your “normal next and select-and-next use the same key” were implemented as a so-called “super-next” shortcut, then someone would be very upset when Notepad++ had the wrong default behavior for that key: after coming out of a Find dialog, one might expect that your “super-next” shortcut would “obviously” continue searching for whatever was in the dialog, whereas another would expect that the “super-next” shortcut would “obviously” discard the previous find and start a new one from whatever word it was on. Like the Lilliputians big-endian vs. little-endian disagreement, that can only lead to trouble.

    Based on the impossibility of distinguishing the intent of the user, I have to assume that either Crimson didn’t have multiple methods of Find, so it didn’t have to distinguish, or you were using the Crimson-equivalent of Select and Find Next all the time, without realizing it had a more specific meaning than you thought.



  • I pondered this a bit more, and, discarding the “volatile” version of the command from consideration, I’ve decided it could be considered reasonable to combine Find Next and Select and Find Next functionalities as a single “command”. That command would then be connected to a shortcut key (e.g., replacing the default functionality of the F3 key).

    Here’s how it would work when the script is run (e.g. pressing its assigned key):

    • If you have an active selection OR your caret is touching a “word”, perform a SelectAndFindNext (obviously using the selection or the word as the text to search for)

    • If you don’t have and active selection AND your caret is not touching a “word”, perform a FindNext (uses whatever is currently in the find-next memory buffer as the search term)

    The above is achievable via a PythonScript such as this one:

    # -*- coding: utf-8 -*-
    
    from Npp import editor, notepad, MENUCOMMAND
    
    word_at_caret_or_selection = ''
    sel_start = editor.getSelectionStart()
    sel_end = editor.getSelectionEnd()
    if sel_start != sel_end:
        word_at_caret_or_selection = editor.getTextRange(sel_start, sel_end)
    else:
        start_of_word_pos = editor.wordStartPosition(editor.getCurrentPos(), True)
        end_of_word_pos = editor.wordEndPosition(start_of_word_pos, True)
        if start_of_word_pos != end_of_word_pos:
            word_at_caret_or_selection = editor.getTextRange(start_of_word_pos, end_of_word_pos)
    if len(word_at_caret_or_selection) == 0:
        notepad.menuCommand(MENUCOMMAND.SEARCH_FINDNEXT)
    else:
        notepad.menuCommand(MENUCOMMAND.SEARCH_SETANDFINDNEXT)
    


  • @Alan-Kilborn ,

    That’s great, if it stays in a PythonScript where the user is choosing to knowingly break existing functionality.

    But if someone were to put it in as the built-in behavior, I would complain loudly, because I frequently use F3 for Find Next even if I have clicked on or arrowed my cursor to touching some word (use Find to move to the next instance of some section; click and edit in that section randomly, then use F3 to move to the next section, etc)



  • @PeterJones said in Combine “find next” and “Select and find next” and "find (Volatile) next" to same Shortcut Key F3:

    if it stays in a PythonScript where the user is choosing to knowingly break existing functionality.

    It would be a hard-sell to go anywhere else…and why would it need to?

    Pretty much a forte for PythonScript … modifying existing functionality.
    If I did not have such power, maybe I would use a different editor. ! ?

    Someday I’ll make a list, maybe just for myself, of all the default behavior that I dislike, that I’ve overridden with a script.


Log in to reply