Notepad++ should not fill the search field with default text when search window was already open and filled
-
When I press Ctrl+F or Ctrl+H, Notepad++ automatically fills the search field with the selected text if there is one, or if no text is selected, just whatever text is adjacent to the current position of caret. Most of the time this is fine, I can just delete it and write whatever I like. However, sometimes I am writing a complicated regular expression to the search field, and I need to go back to the text to look at or copy something. Then, if I press Ctrl+F to bring the Search window back to focus, bam, all that long expression that I typed is gone, replaced with a random word that the caret happens to be on. If I am lucky, an earlier version of the regular expression is in history and I can bring it back and retype recent modifications, otherwise I have to type the whole thing again. Can Notepad++ stop doing that, and just bring the search window to focus without changing what I typed in the search field?
Alternatively, an option could be added to stop filling the search field with selected/caret text altogether. I don’t use that feature often, I would be fine with turning it of completely to get rid of this annoyance.
Alternatively, a new shortcut could be added to toggle focus on the search window. E.g. Ctrl+something would focus to text, to search window, and to text successively without closing the search window. Sort of like how Ctrl+Tab changes focus between tabs. This could work, though I think incorporating this to Ctrl+F would be more useful. That is, if no search window is open, Ctrl+F would open a search dialog as usual, and if it a search window is open, it would toggle the focus between text and search.
-
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.
-
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.
-
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.
-
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.
-
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.
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.
-
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
-
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.
-
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 !! -
@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
-
FYI, it’s implemented in
https://github.com/notepad-plus-plus/notepad-plus-plus/commit/7a1096de5b3618bc3e6611e6c25caac952d41ae2It’ll be in the next release.