Make "Find Next" / "Find Prev" buttons an option
-
@Scott-Sumner Ah thanks for the clarification :)
-
My biggest issue with how it is now is that if I check “search backwards”, the next time I open the find dialog box, it will still be checked. Usually, when I need to search backwards, it’s for a specific instance while I have the find dialog open. Once I close it, I would like it to default to forward again the next time I open it.
I can’t tell you how many times I’ve searched backwards in a file and then later (sometimes days later) went to search a different file where NPP tells me nothing was found until I realized that the “search backwards” option was checked. That’s why I liked the two buttons. I was 100% sure which direction I was searching. If NPP is sticking with a single Find button, perhaps we could have the option to reset the direction checkbox each time the find dialog box was opened. This would help greatly.
Rich
-
The reason I loved the two button approach so much was that many times I search forward in a file and then need to go back one. Having both buttons saved having to check and uncheck a lot. I, too, like the idea of having separate forward/backward buttons for all 3 functions (find, replace, replace all).
But one thing I find odd from this thread…doesn’t the “replace all” button replace everything in a file, not just from the cursor to the beginning or end of the file? Meaning it will wrap around if the cursor is in the middle of the file when “replace all” is pressed?
-
@Michael-DiGregorio said:
doesn’t the “replace all” button replace everything in a file, not just from the cursor to the beginning or end of the file? Meaning it will wrap around if the cursor is in the middle of the file when “replace all” is pressed?
Replace All only does what you are describing if the Wrap around checkbox is checked.
-
@richlux said:
perhaps we could have the option to reset the direction checkbox each time the find dialog box was opened.
Maybe…but I wouldn’t count on it. @donho seems to have very specific ideas about how things should be, and what should be configurable via options–I’m okay with that as it is his program, after all. :-)
Coming to Notepad++ after 20 years of using an editor where this behavior was configurable–I could tell it that each time the Find window was invoked to set the search direction to Down–not having that capability drove me nuts…until I found a way to script it in order to bend it to my will.
At first I used AutoIt3 to do it, but that had some drawbacks; more recently I’ve switched to a Pythonscript method. I’ll share it below; it will work on Notepad++ versions 7.5 and anything reasonably current but less than 7.4.2 (tested on 7.5 and 7.2.2).
So to use the script you obviously have to have the Pythonscript plugin installed. Use the shortcut mapper to remap ctrl+f to the script (and remove the default binding). Sorry, mouse users, there isn’t a great way to get this functionality via the mouse (without navigating nested menus or creating a toolbar button–certainly nothing as minimal as a quick keystroke!).
Here’s
FindDialogAutosetDirectionToDown.py
:import ctypes from ctypes.wintypes import BOOL, HWND, LPARAM, WPARAM def FDADTD__main(): # (F)ind(D)ialog(A)utoset(D)irection(T)o(D)own backwards_checkbox_text = u'Backward direction' # N++ 7.5 (and up?) direction_up_radio_button_text = u'&Up' # N++ before 7.4.2 direction_down_radio_button_text = u'&Down' # N++ before 7.4.2 find_what_box_text = u'&Find what :' WNDENUMPROC = ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) FindWindow = ctypes.windll.user32.FindWindowW SendMessage = ctypes.windll.user32.SendMessageW EnumChildWindows = ctypes.windll.user32.EnumChildWindows create_unicode_buffer = ctypes.create_unicode_buffer GetWindowText = ctypes.windll.user32.GetWindowTextW GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW BM_GETCHECK = 0x00F0 BM_CLICK = 0x00F5 WM_NEXTDLGCTL = 0x28 # invoke/show the Find tab of the Find dialog: notepad.menuCommand(MENUCOMMAND.SEARCH_FIND) find_dialog_hwnd = FindWindow(None, u'Find') FDADTD__main.backwards_checkbox_hwnd = None # N++ 7.5 (and up?) FDADTD__main.direction_up_radio_btn_hwnd = None # N++ before 7.4.2 FDADTD__main.direction_down_radio_btn_hwnd = None # N++ before 7.4.2 FDADTD__main.find_what_box_trigger_enable = False FDADTD__main.find_what_box_hwnd = None def EnumCallback(hwnd, lparam): win_text_len_plus1 = GetWindowTextLength(hwnd) + 1 window_text = ctypes.create_unicode_buffer(win_text_len_plus1) GetWindowText(hwnd, window_text, win_text_len_plus1) if window_text.value == backwards_checkbox_text: FDADTD__main.backwards_checkbox_hwnd = hwnd elif window_text.value == direction_up_radio_button_text: FDADTD__main.direction_up_radio_btn_hwnd = hwnd elif window_text.value == direction_down_radio_button_text: FDADTD__main.direction_down_radio_btn_hwnd = hwnd elif window_text.value == find_what_box_text: # the control we need is the control FOLLOWING the one with the correct text on it, so set up a trigger flag to grab the NEXT control FDADTD__main.find_what_box_trigger_enable = True elif FDADTD__main.find_what_box_trigger_enable: FDADTD__main.find_what_box_hwnd = hwnd FDADTD__main.find_what_box_trigger_enable = False return True EnumChildWindows(find_dialog_hwnd, WNDENUMPROC(EnumCallback), 0) if FDADTD__main.backwards_checkbox_hwnd: # running N++ 7.5 (and up?) if SendMessage(FDADTD__main.backwards_checkbox_hwnd, BM_GETCHECK, 0, 0) == 1: # backwards checkbox was checked; uncheck it: SendMessage(FDADTD__main.backwards_checkbox_hwnd, BM_CLICK, 0, 0) else: # running N++ prior to 7.4.2 if SendMessage(FDADTD__main.direction_up_radio_btn_hwnd, BM_GETCHECK, 0, 0) == 1: # direction is set to up; set it to down: SendMessage(FDADTD__main.direction_down_radio_btn_hwnd, BM_CLICK, 0, 0) if FDADTD__main.find_what_box_hwnd: # want input focus on the Find-what box, but it could be elsewhere from the above code # put the focus on the Find-what box # (see https://blogs.msdn.microsoft.com/oldnewthing/20040802-00/?p=38283 for how this is properly done) SendMessage(find_dialog_hwnd, WM_NEXTDLGCTL, WPARAM(FDADTD__main.find_what_box_hwnd), True) FDADTD__main()
This script was inspired by coding ideas presented here: https://notepad-plus-plus.org/community/topic/13754/replace-1-lines
If this (or ANY posting on the Notepad++ Community site) is useful, don’t reply with a “thanks”, simply up-vote ( click the
^
in the^ 0 v
area on the right ). -
@dail, @scott-sumner and others, there was also some discussion (can’t remember where now) about the fact that fitting the words in multiple languages on the buttons was problematic. Although, I believe that could be fixed by removing the Find, Replace, and Replace All text from the buttons themselves; instead placing it above or in-between each pair of buttons (making sure it’s clear which buttons each text goes with), and then just have
<<
and>>
on the buttons themselves.As a side note, I almost never used the search Up feature (much less than 1%), probably because it was a pain to click on it, then click back later; so when this came out, I went “Meh.” But in the few days I had the
<< Find
button, I did use it a couple of times, as it was convenient to have it there.@michael-digregorio I almost always have the Wrap around box checked, so I assumed Replace All had that functionality too, similar to the Count button in the Find box. I usually select text, then use Replace All with the In selection box checked when I want to replace in only part of the document.
Speaking of the In selection box, I’ve noticed it sometimes gets unchecked at certain times - although strangely, not when the Replace dialog is closed and re-opened. I haven’t tested to find out when it gets unchecked; I just verify it’s checked before clicking Replace All again. So @richlux, I support your suggestion, especially as it may be able to follow the rules for unchecking the In selection box, to make it fit in with how @donho likes to see things. :-)
-
@glennfromiowa said:
…(Replace) In-selection box, I’ve noticed it sometimes gets unchecked…
It will get unchecked (and disabled) anytime the Replace dialog is opened/activated and there is no selected text in the editor tab that is currently active. It will also get unchecked (and disabled) if there is a column-selection active in the editor tab that is currently active when Replace is invoked.
If multi-select is enabled and multiple selections are active, there is nothing odd about the in-selection checkbox’s behavior, but if a replace-all is attempted under these conditions (with the in-selection checkbox checked), only the most recent of the multi-selected areas is effected!
-
My upvote for the separate “<< [Search|Replace|Replace All]” and / “[Search|Replace|Replace All]>>” buttons… maybe with the backwards button disabled if “Wrap around” is checked.
Since I saw it in 7.4.2 I really loved having the two separate buttons, I think the checkbox is simpler but quite ugly -
@Alessandro-Barbieri said:
with the backwards button disabled if “Wrap around” is checked
Searching backwards (up toward top-of-file from current caret position) and wraparound are two completely independent concepts–why do you want to join them in this way?
It is completely valid to be searching backwards and wanting to continue (the backwards search) at the end-of-file once you hit the beginning of the file.
Searching backwards IS incompatible with the regular expression search mode, and the backwards-direction checkbox should be (and is) disabled when the search mode is changed to regex, but that is the only circumstance in the Find dialog options that needs to be restricted. This is discussed more in other threads…
-
Came to this forum just to let know that I LOVED << Find | Find >>, I will revert to 7.4.2 and will wait until it is restored.
-
@Bas-van-der-Veeken said:
Came to this forum just to let know that I LOVED << Find | Find >>, I will revert to 7.4.2 and will wait until it is restored.
Totally agree, I just updated some of my older installs on various workstation to get the << Find Find >> buttons, and they are gone already. - Damn! Make it an option!
Don’t tempt us with goodness then take it away. how silly. -
@Bas-van-der-Veeken said:
Came to this forum just to let know that I LOVED << Find | Find >>, I will revert to 7.4.2 and will wait until it is restored.
Same here, gone back to 7.4.2 until << Find and Find >> appear again.
-
@Bas-van-der-Veeken said:
Came to this forum just to let know that I LOVED << Find | Find >>, I will revert to 7.4.2 and will wait until it is restored.
Same here! Please restore this great feature!
-
Just adding my voice to those asking for this feature to be added back in some way. Thanks.
-
This post is deleted! -
I suggest leaving the checkbox. But the buttons “Find >>” and “<< Find” must switch the checkbox.
-
I hated the << Find | Find >> buttons, JUST ALWAYS USE FIND ALL OCCURRENCES!! ONLY EVER!!
-
I rolled back to v7.4.2
the two buttons are just too useful
-
I think the best solution would be to add an option in the settings to choose between the current setup and the double buttons setup
when the option is enabled,
<< Find and Find >>
will always show<< Count and Count >>
<< Replace and Replace >>
<< ReplaceAll and ReplaceAll>>should only be visible if the “wrap around” checkbox is not selected
it seems to me that this would be the solution to make everybody happy
-
you have not all buttons. Your option will have to be returned again.