Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 4 Posters 2.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Adeeb KhairA
      Adeeb Khair
      last edited by

      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

      Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Adeeb Khair
        last edited by

        @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?

        1 Reply Last reply Reply Quote 2
        • PeterJonesP
          PeterJones @Adeeb Khair
          last edited by PeterJones

          @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.

          1 Reply Last reply Reply Quote 3
          • Alan KilbornA
            Alan Kilborn
            last edited by Alan Kilborn

            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)
            
            PeterJonesP Neil SchipperN 2 Replies Last reply Reply Quote 4
            • PeterJonesP
              PeterJones @Alan Kilborn
              last edited by

              @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)

              Alan KilbornA 1 Reply Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn @PeterJones
                last edited by

                @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.

                1 Reply Last reply Reply Quote 2
                • Neil SchipperN
                  Neil Schipper @Alan Kilborn
                  last edited by

                  I came across this old thread after searching for posts that may have been relevant to a new issue I submitted.

                  @Alan-Kilborn said in Combine “find next” and “Select and find next” and “find (Volatile) next” to same Shortcut Key F3:

                  If you have an active selection OR your caret is touching a “word”, perform a SelectAndFindNext

                  As @PeterJones pointed out, a requirement to place the caret off-text to nudge (Shift-)F3 to use prior memory would be quite horrible. However, a “new and improved” implementation of (Shift-)F3 would act like SelectAndFindNext only if there is currently a selection. This would be quite convenient and easy to learn.

                  The common use case I’m thinking of is when user is (Shift-)F3-ing around, and then takes the action of selecting different text, which strongly suggests the new selection, being now of particular interest, is likely to be the target of a subsequent search.

                  Yes, there are also less common use cases that such functionality would break, thereby annoying the user, for ex., (Shift-)F3-ing around specifically to edit nearby text, or to copy nearby text to clipboard (perhaps to then paste to a different file, or load up clipboard history). But these less common situations are easily handled with other familiar techniques, such as keeping the Find dialog up and using Next/Prev, or performing a find/bookmark all in curr doc and navigating with the results.

                  The great advantage of the proposed enhanced behaviour of F3 is having, as an out-of-the-box default, a single-key shortcut to launch a (forward) find. I imagine this would be quite pleasing to Joe & Mary Normal. (Learning about and messing with Shortcut Mapper is for people with a bit of experience and confidence).

                  I’m interested to know if there’s community interest in pursuing this (and I know this forum is not where feature requests are made).

                  Alan KilbornA 1 Reply Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @Neil Schipper
                    last edited by Alan Kilborn

                    @Neil-Schipper

                    I will have to consider your proposed functionality more deeply before offering an opinion. And that probably means: Mocking it up with a script – and quite possibly, slightly modifying the script I presented earlier in this thread.

                    LATER FOLLOWUP:

                    I did some thinking on the idea. Maybe it is OK…probably not a “game changer” though…

                    As to quickly scripting it for experimentation, I think it can be a one-liner:

                    notepad.menuCommand(MENUCOMMAND.SEARCH_SETANDFINDNEXT if not editor.getSelectionEmpty() else MENUCOMMAND.SEARCH_FINDNEXT)

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors