New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable search option "in selection" constantly #14108
Comments
Good point. |
Yaron10, |
Hi, |
@mididoc said:
I take this to mean that you are selecting a large (> 1024 bytes) of existing data, then pressing Ctrl+f to get that data into Find what, and then you are seeing In selection automatically checkmarked. |
@Yaron10 said:
Can you elaborate on what this means? If the checkbox is disabled, wouldn't there be situations where a user needs to checkmark it and they cannot because it is disabled? (There's something I'm not understanding here) |
Hi @alankilborn and @Yaron10, |
Well, the author of Notepad++ will have to decide on that. In the meanwhile, a workaround to always uncheck In Selection could be made by modifying the script HERE and then tying execution of that script to Ctrl+f rather than running the default command. If you are interested in such a script modification, let me know. |
Yes this would be really interesting, thanks. |
Here's the script. For its use and setting it up, see the previously referenced Community posting: And/or the Community's PythonScripting starter FAQ: Click to view the script# -*- coding: utf-8 -*-
from __future__ import print_function
# references:
# https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14108
# also https://community.notepad-plus-plus.org/topic/23793
from Npp import *
import inspect
import os
import sys
from ctypes import ( create_unicode_buffer, WinDLL, )
from ctypes.wintypes import ( HWND, LPARAM, UINT, WPARAM, )
LRESULT = LPARAM
#-------------------------------------------------------------------------------
python2 = True if sys.version_info.major == 2 else False
user32 = WinDLL('user32')
BM_CLICK = 0x00F5
BM_GETCHECK = 0x00F0
BST_CHECKED = 1
SW_SHOW = 5
SW_HIDE = 0
WM_NEXTDLGCTL = 0x28
SendMessage = user32.SendMessageW
SendMessage.restype = LRESULT
SendMessage.argtypes = [ HWND, UINT, WPARAM, LPARAM ]
#-------------------------------------------------------------------------------
# ids from find window controls, see
# https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/PowerEditor/src/ScintillaComponent/FindReplaceDlg_rc.h :
IDFINDWHAT = 1601
IDNORMAL = 1625
IDWHOLEWORD = 1603
IDMATCHCASE = 1604
IDC_BACKWARDDIRECTION = 1722
IDC_IN_SELECTION_CHECK = 1632
#-------------------------------------------------------------------------------
class HwndUtility(object):
def __init__(self):
pass
def set_control_text(self, hwnd, string):
if python2 and isinstance(string, str): string = unicode(string, 'utf-8')
return user32.SetWindowTextW(hwnd, string)
def get_control_text(self, hwnd):
length = user32.GetWindowTextLengthW(hwnd)
ubuff = create_unicode_buffer(length + 1)
user32.GetWindowTextW(hwnd, ubuff, length + 1)
return ubuff.value.encode('utf-8') if python2 else ubuff.value
def check_checkbox(self, hwnd, check_not_uncheck=True):
if self.is_control_enabled(hwnd):
currently_checked = self._is_checkbox_or_radio_checked(hwnd)
if check_not_uncheck and currently_checked: return True
elif not check_not_uncheck and not currently_checked: return True
else: return self.press_button(hwnd)
return False
def is_checkbox_checked(self, hwnd): return self._is_checkbox_or_radio_checked(hwnd)
def set_radio(self, hwnd): return self.check_checkbox(hwnd)
def is_radio_set(self, hwnd): return self._is_checkbox_or_radio_checked(hwnd)
def press_button(self, hwnd): return True if SendMessage(hwnd, BM_CLICK, 0, 0) == 0 else False
def is_control_enabled(self, hwnd): return True if user32.IsWindowEnabled(hwnd) == 1 else False
def set_dialog_control_focus(self, hwnd, dialog_hwnd):
# see https://devblogs.microsoft.com/oldnewthing/20040804-00/?p=38243
return True if SendMessage(dialog_hwnd, WM_NEXTDLGCTL, WPARAM(hwnd), LPARAM(True)) == 0 else False
def make_visible(self, hwnd, show=True):
user32.ShowWindow(hwnd, SW_SHOW if show else SW_HIDE)
# functions meant for internal use only by this class:
def _is_checkbox_or_radio_checked(self, hwnd): # internal function; external should use is_checkbox_checked() or is_radio_set()
return True if SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED else False
#-------------------------------------------------------------------------------
def get_word_at_caret_or_selection():
retval = ''
(sel_start, sel_end) = (editor.getSelectionStart(), editor.getSelectionEnd())
if editor.getSelections() == 1 and sel_start != sel_end:
retval = 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:
retval = editor.getTextRange(start_of_word_pos, end_of_word_pos)
editor.setSelection(end_of_word_pos, start_of_word_pos)
return retval
#-------------------------------------------------------------------------------
class FWDOS(object):
def __init__(self):
self.debug = True if 1 else False
if self.debug:
pass
#console.show()
#console.clear()
self.this_script_name = inspect.getframeinfo(inspect.currentframe()).filename.split(os.sep)[-1].rsplit('.', 1)[0]
self.this_script_path_without_ext = inspect.getframeinfo(inspect.currentframe()).filename.rsplit('.', 1)[0]
# activate the find tab of the find window
notepad.menuCommand(MENUCOMMAND.SEARCH_FIND)
# this could cause the word at caret or any active selection to be put in the find-what box
# (best practice: set Preferences > Searching > Don't fill find field... to UNTICKED)
find_window_hwnd = user32.FindWindowExW(None, None, u'#32770', u'Find')
findWhat_edit_hwnd = user32.GetDlgItem(find_window_hwnd, IDFINDWHAT)
normalSearchMode_radio_hwnd = user32.GetDlgItem(find_window_hwnd, IDNORMAL)
wholeWord_checkbox_hwnd = user32.GetDlgItem(find_window_hwnd, IDWHOLEWORD)
matchCase_checkbox_hwnd = user32.GetDlgItem(find_window_hwnd, IDMATCHCASE)
backwardDirection_checkbox_hwnd = user32.GetDlgItem(find_window_hwnd, IDC_BACKWARDDIRECTION)
inSelection_checkbox_hwnd = user32.GetDlgItem(find_window_hwnd, IDC_IN_SELECTION_CHECK)
text_to_set_for_findWhat = get_word_at_caret_or_selection()
hu = HwndUtility()
hu.press_button(normalSearchMode_radio_hwnd)
hu.check_checkbox(matchCase_checkbox_hwnd, False)
hu.check_checkbox(wholeWord_checkbox_hwnd, False)
hu.check_checkbox(backwardDirection_checkbox_hwnd, False)
hu.check_checkbox(inSelection_checkbox_hwnd, False)
hu.set_control_text(findWhat_edit_hwnd, text_to_set_for_findWhat)
hu.set_dialog_control_focus(findWhat_edit_hwnd, find_window_hwnd)
def print(self, *args):
if self.debug:
print(self.__class__.__name__ + ':', *args)
#-------------------------------------------------------------------------------
if __name__ == '__main__': FWDOS() |
Hi @alankilborn, |
There is nothing about "startup" for this script; thus you should have ignored any references to startup where you saw them in the general instructions. The startup stuff is only for scripts that don't run "on demand". This one runs "on demand", meaning when you are initiating a find action. Thus, you'd remove the keybinding for the default Ctrl+f action, which is tied to Search > Find..., and replace it with running of the script. Thus, when you are done with the one-time setup, Ctrl+f will invoke the script. Details on keybinding of a script are in the Community FAQ link from earlier. |
OK, |
Hello @alankilborn & @mididoc,
The CheckBox should be disabled when there's no selection on This approach is simpler and much more flexible IMO. I changed the behavior for my personal use a few years ago and I don't fully remember it now. :)
I also think that the "1024 bytes" factor is too sophisticated and unnecessarily complicates the implementation. I do think the behavior in NPP should be changed. |
@mididoc said:
It works for me. Here's how I tested it:
|
@Yaron10 said:
It could have been implemented this way from the start, but it wasn't, and now I (and I presume others) are used to the auto-checkmarking. At this point in the life of the software, it would be too disruptive to remove the auto-checkmarking.
Ideally what might be needed is a Preference setting -- on the Searching subpage -- (integer value) to control this size. If the size is set to zero, then automatic checkmarking of In selection will never occur. That would be easiest to develop but maybe not the best UI. Maybe two setting controls is better:
The "min. size" setting would be below the "enable" and slightly indented to the right. The "min. size" setting would appear disabled/grayed if the "enable" checkbox is unchecked. |
sorry, doing the same and still not working here. |
this would be the ideal solution. |
Hmm, okay; sorry we couldn't get it working for you... |
@donho If you like the following proposal for a change to solve this issue (which has been a problem for more users), then I will try my hand at a PR for it: New for the Preferences > Searching page, default settings shown: |
The user would only have to check it once. |
That makes the presumption that a user always wants to search in selected text, which isn't true. If it was the case that user always wanted this, then logic for Fill Find Field... would have to change as it makes no sense to fill the find field with selected text and then only search selected text. |
also, if this would be added to the preferences as an option, this disturbs nobody. |
The default case, due to history, should be searching in selection if selection is > 1024. If there is no selection, or selection is < 1024, searching should proceed from the caret position toward either the bottom or the top of the document. |
@Yaron10 |
This option won't be implemented. |
this is really a pitty cause alankilborn's proposel is exellent. |
It seems we still have a fundamental misunderstanding here. I do see the advantage in auto-check/uncheck. But it has a major downside too.
I meant that the CheckBox should be enabled/disabled only without programmatically checking/unchecking it. |
Hi again, |
Let it be 1024 then. I think it's a reasonable value. |
Let's do it on Edit control then. |
excellent. |
Please
|
It's a pity when localization needs have to drive UI design (placement, separation of controls) but it is not a problem for me to make the requested changes. |
Democracy is a compromised system, isn't it? ;) |
Wouldn't Minimum size for auto-checking "In selection": be better? - This is the heart of the issue/setting. |
+1 |
Hi all, If I want to search in the selection, I will enable this checkbox myself, I don't want it to activate itself regardless of any circumstances. edit: |
Hi, |
Ha, yea, well we all want things quickly. :-) |
@alankilborn has kindly agreed to work on this issue. |
Hi @alankilborn, |
ofcourse, i know that. |
Hi Yaron10, Thanks for the link. Cheers mike |
@mididoc Click the job name for the N++ you are using, then on the next screen click |
Thanks @alankilborn . Works excellent now, thanks lot for the modification. Cheers mike |
Sorry for the late reply. I wasn't by my PC. 👍 |
Set value to 0 to disable auto-checking "In Selection" checkbox in Find dialog. Set any value to define the length of selected characters to auto-check "In Selection" checkbox in Find dialog. The default and maximum value is 1024. Fix notepad-plus-plus#14108, fix notepad-plus-plus#13677, fix notepad-plus-plus#12639, close notepad-plus-plus#14175
I created issue #14265 to suggest using |
Hi,
is there a way to disable the search 'in selection' option always?
we always search in whole document and this option disturbs our search,
since it is enabling by itself.
thanks for assistance.
cheers mike
The text was updated successfully, but these errors were encountered: