Community
    • Login

    Notepad++ should not fill the search field with default text when search window was already open and filled

    Scheduled Pinned Locked Moved General Discussion
    11 Posts 7 Posters 5.4k 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.
    • Scott SumnerS
      Scott Sumner @debiedowner
      last edited by

      @debiedowner

      In such a situation I would use the mouse to bring focus back to the Find window, which will NOT change the text in the Find What box.

      debiedownerD 1 Reply Last reply Reply Quote 0
      • debiedownerD
        debiedowner @Scott Sumner
        last edited by

        @Scott-Sumner

        Yep, that’s what I have been trying to force myself to do after losing the long expressions I typed a number of times. But I very much prefer using the keyboard; and in the case of Ctrl+F, it is almost instinctive from all the programs that I use that if there is a search field visible, Ctrl+F will focus on that. Which it indeed does, with the aforementioned problem.

        It would be great if there were a keyboard shortcut to bring the dialog back to focus, either a different shortcut, or ideally Ctrl+F itself. Alternatively the issue would be moot if there was an option to modify Notepad++'s behavior to fill the search field when no text is selected.

        Scott SumnerS 1 Reply Last reply Reply Quote 0
        • Scott SumnerS
          Scott Sumner @debiedowner
          last edited by

          @debiedowner

          So I’m not sure if you’re looking for something that will work to fix your problem, or you just want to report it in the form of a feature request and hope it gets implemented some day. I tend to fix/workaround things myself, because that way I’m not relying on anyone else’s timeline.

          I have worked-around some of the Find/Replace feature’s peculiarities (my opinion!) using AutoIt3. If this is a length (installing that program) that you’d be willing to go to to get your desired behavior, here’s something I grabbed from one of my .au3 scripts that seems to implement it:

          Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client
          Local $win_and_tab_caption = "Find"
          If WinSetState($win_and_tab_caption, "", @SW_SHOW) == 0 Then
              $win_and_tab_caption = "Replace"
              If WinSetState($win_and_tab_caption, "", @SW_SHOW) == 0 Then
                  $win_and_tab_caption = "Find in Files"
                  If WinSetState($win_and_tab_caption, "", @SW_SHOW) == 0 Then
                      $win_and_tab_caption = "Mark"
                      If WinSetState($win_and_tab_caption, "", @SW_SHOW) == 0 Then
                          ; a find-family window hasn't been invoked yet during this Notepad++ session; invoke it:
                          Send("^!+f")  ; <--------- N++ shortcut-mapper mapping for "Search -> Find..." (ctrl+alt+shift+f in my case)
                      EndIf
                  EndIf
              EndIf
          EndIf
          WinActivate($win_and_tab_caption)
          WinWaitActive($win_and_tab_caption, "", 1)
          MouseClick("left", 10, 10, 1, 0)  ; click on "Find" tab to make it the active tab
          ControlFocus("Find", "", 1601)  ; 1601 = control ID for Find what box
          Send("{END}")  ; de-select the text in the Find what box
          

          The general idea is to tie the running of that AutoIt3 script to your usual “find” keypress via the Run menu, and remap the native Notepad++ “find” action to something obscure (I used ctrl+alt+shift+f in the above script). If you have interest, but are uncertain about how to set it up, just say so. I’m willing to provide details, but don’t want to bother if there is no interest.

          debiedownerD 1 Reply Last reply Reply Quote 0
          • AdrianHHHA
            AdrianHHH
            last edited by

            A related problem that might be added to this idea: When I type into the search window and then use the arrow keys for editing the test, I sometimes (being a fumble fingers) hit the up or down arrows and that replaces the current string with something from the history, but it completely loses the search string I was entering.

            1 Reply Last reply Reply Quote 0
            • debiedownerD
              debiedowner @Scott Sumner
              last edited by

              @Scott-Sumner

              Thank you so much! I actually already have an AutoHotKey script running all the time, but I had never used it for scripting, I just had some simple key remappings. It never occurred to me to solve this via a script. Looking at your code, I wrote the following for AutoHotKey:

              #If WinActive("ahk_exe notepad++.exe")
              ^f::
              if WinExist("Find")
                if WinActive("Find")
                  WinActivate, ahk_class Notepad++
                else
                  WinActivate, Find
              else if WinExist("Replace")
                ControlClick x35 y35, Replace ; click on "Find"
              else
                SendInput, ^f
              return
              ^h::
              if WinExist("Replace")
                if WinActive("Replace")
                  WinActivate, ahk_class Notepad++
                else
                  WinActivate, Replace
              else if WinExist("Find")
                ControlClick x70 y35, Find ; click on "Replace"
              else
                SendInput, ^h
              return
              #If
              

              It works great, exactly like I want. It solved my problem; plus it enables me to toggle focus between text and search dialog successively each time I press Ctrl+F or Ctrl+H; plus I can switch between Search and Replace with shortcuts when the dialog is active, something I couldn’t do before. It could be extended to include the “Find in Files” and “Mark” cases, if desired.

              I hadn’t heard of AutoIt before. Apparently AutoHotKey forked from it. I guess I should look into it as well to see which is better if I do serious scripting in the future; AutoHotKey was good enough for the simple things I needed so far.

              @AdrianHHH

              That happened to me as well! I think when you are typing your own string, up arrow should do nothing, and if you press down arrow by mistake, up arrow should bring back the text you were writing. Unfortunately it is not possible to implement that behavior via a script, Notepad++ must do that; but it is certainly possible to disable up and down arrows completely while in the search window via AutoHotkey (or presumably AutoIt) if you never need them. (Or one could make the up and down arrows do nothing, and Ctrl+up and down act like the arrow buttons for the times you actually need them.) I don’t know if it is worth installing AutoHotkey or AutoIt over, if you are not otherwise using them though; but I will consider adding such a line to my script.

              1 Reply Last reply Reply Quote 0
              • ocroquetteO
                ocroquette
                last edited by

                I extended @debiedowner 's script for AutoHotKey v1 to clear the prefilled text boxes:

                #If WinActive("ahk_exe notepad++.exe")
                ^f::
                if WinExist("Find")
                  ; Switch back and forth between editor and dialog
                  if WinActive("Find")
                    WinActivate, ahk_class Notepad++
                  else
                    WinActivate, Find
                else if WinExist("Replace") {
                  ; Switch from "Replace" to "Find"
                  ; The following coordinates are system specific. Use the Window spy to find your own values
                  ControlClick x33 y48, Replace ; click on "Find"
                }
                else {
                  ; Open the dialog
                  SendInput, ^f
                  ; Clear pre-filled text boxes
                  ; See also https://github.com/notepad-plus-plus/notepad-plus-plus/issues/3243
                  WinWaitActive, ahk_class #32770 ahk_exe notepad++.exe,,1
                  ControlSetText, Edit1,
                }
                return
                ^h::
                if WinExist("Replace")
                  ; Switch back and forth between editor and dialog
                  if WinActive("Replace")
                    WinActivate, ahk_class Notepad++
                  else
                    WinActivate, Replace
                else if WinExist("Find")
                  ; Switch from "Find" to "Replace"
                  ; The following coordinates are system specific. Use the Window spy to find your own values
                  ControlClick x90 y50, Find ; click on "Replace"
                else {
                  SendInput, ^h
                  WinWaitActive, ahk_class #32770 ahk_exe notepad++.exe,,1
                  ; Clear pre-filled text boxes
                  ; See also https://github.com/notepad-plus-plus/notepad-plus-plus/issues/3243
                  ControlSetText, Edit1,
                  ControlSetText, Edit2,
                }
                return
                #If
                
                1 Reply Last reply Reply Quote 0
                • cmeriauxC
                  cmeriaux
                  last edited by

                  I never the same issue in some situations.
                  I think a workaround could be :
                  On dialog creation, if the windows already exists, don’t create a new one, don’t fill search field, position field, filter field…

                  I’ll check on the code to see if it’s a easy fix or a tuff one.

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

                    @cmeriaux

                    On dialog creation, if the windows already exists,

                    These are 2 different things.

                    Find window gets created exactly one time during a N++ run: the first time the user calls it up.

                    to see if it’s a easy fix

                    Don’t fix what isn’t broken. Just because the window is showing doesn’t mean that I don’t want what is under the caret to replace the text currently in the Find what box when I press ctrl+f !!

                    1 Reply Last reply Reply Quote 1
                    • cmeriauxC
                      cmeriaux
                      last edited by

                      @Alan-Kilborn after further investigation

                      it’s seems the bug I’m encountering comes from the light explorer plugin which clear some parameters of Findreplace dialog.
                      There is no issue when invoking Findreplace dialog from CTRL+F or “folder as workspace” or sherlockExplorer.

                      No need to fix anything in Npp

                      1 Reply Last reply Reply Quote 1
                      • donhoD
                        donho
                        last edited by

                        FYI, it’s implemented in
                        https://github.com/notepad-plus-plus/notepad-plus-plus/commit/7a1096de5b3618bc3e6611e6c25caac952d41ae2

                        It’ll be in the next release.

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