Skip to content

Commit d9879aa

Browse files
committed
fixed scope fo selection when changing to Replace in files
1 parent 0add8ea commit d9879aa

File tree

1 file changed

+51
-38
lines changed

1 file changed

+51
-38
lines changed

src/MultiReplacePanel.cpp

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -648,20 +648,8 @@ void MultiReplace::updateReplaceInFilesVisibility()
648648

649649
moveAndResizeControls(); // actually MoveWindow()/SetWindowPos() all controls
650650
adjustWindowSize(); // shrink/grow the dialog to fit
651-
652-
// Keep the Scope-radio buttons consistent with current mode
653-
if (isReplaceInFiles)
654-
{
655-
// Selection scope is meaningless while replacing in files – disable it.
656-
::EnableWindow(GetDlgItem(_hSelf, IDC_SELECTION_RADIO), FALSE);
657-
::SendMessage(GetDlgItem(_hSelf, IDC_SELECTION_RADIO), BM_SETCHECK, BST_UNCHECKED, 0);
658-
::SendMessage(GetDlgItem(_hSelf, IDC_ALL_TEXT_RADIO), BM_SETCHECK, BST_CHECKED, 0);
659-
}
660-
else
661-
{
662-
// Back to normal replace modes – let selection logic decide.
663-
onSelectionChanged(); // re-evaluate current text selection
664-
}
651+
652+
onSelectionChanged(); // disable Selection Radio Button if Text Selection
665653

666654
InvalidateRect(_hSelf, NULL, TRUE); // repaint client
667655
UpdateWindow(_hSelf);
@@ -10573,41 +10561,66 @@ void MultiReplace::pointerToScintilla() {
1057310561
}
1057410562
}
1057510563

10576-
void MultiReplace::onSelectionChanged() {
10564+
void MultiReplace::onSelectionChanged()
10565+
{
10566+
static bool wasTextSelected = false; // remember previous selection state
1057710567

10578-
static bool wasTextSelected = false; // This stores the previous state
10568+
HWND hDlg = getDialogHandle(); // dialog handle once for reuse
1057910569

10580-
// Always force “All Text”, disable the Selection radio, and leave early.
10581-
if (instance->isReplaceInFiles) {
10582-
HWND hSel = ::GetDlgItem(getDialogHandle(), IDC_SELECTION_RADIO);
10583-
HWND hAll = ::GetDlgItem(getDialogHandle(), IDC_ALL_TEXT_RADIO);
10570+
// -----------------------------------------------------------------------
10571+
// 1) “Replace in Files” mode:
10572+
// - Selection-Radio ist dort nutzlos → immer deaktivieren
10573+
// - Nur wenn er noch angehakt ist, auf All Text umschalten
10574+
// - Dann sofort zurückkehren, damit er nicht erneut aktiviert wird
10575+
// -----------------------------------------------------------------------
10576+
if (instance && instance->isReplaceInFiles)
10577+
{
10578+
HWND hSel = ::GetDlgItem(hDlg, IDC_SELECTION_RADIO);
1058410579
::EnableWindow(hSel, FALSE);
10585-
::SendMessage(hSel, BM_SETCHECK, BST_UNCHECKED, 0);
10586-
::SendMessage(hAll, BM_SETCHECK, BST_CHECKED, 0);
10587-
return;
10588-
}
1058910580

10590-
// Get the start and end of the selection
10591-
Sci_Position start = ::SendMessage(getScintillaHandle(), SCI_GETSELECTIONSTART, 0, 0);
10592-
Sci_Position end = ::SendMessage(getScintillaHandle(), SCI_GETSELECTIONEND, 0, 0);
10581+
if (::SendMessage(hSel, BM_GETCHECK, 0, 0) == BST_CHECKED)
10582+
{
10583+
::CheckRadioButton(
10584+
hDlg,
10585+
IDC_ALL_TEXT_RADIO, // first in radio group
10586+
IDC_COLUMN_MODE_RADIO, // last in radio group
10587+
IDC_ALL_TEXT_RADIO // button to check
10588+
);
10589+
}
10590+
return; // nothing else must re-enable Selection in this mode
10591+
}
1059310592

10594-
// Enable or disable IDC_SELECTION_RADIO depending on whether text is selected
10593+
// -----------------------------------------------------------------------
10594+
// 2) Normal Replace-All / Replace-in-Opened-Docs modes
10595+
// -----------------------------------------------------------------------
10596+
Sci_Position start = ::SendMessage(getScintillaHandle(),
10597+
SCI_GETSELECTIONSTART, 0, 0);
10598+
Sci_Position end = ::SendMessage(getScintillaHandle(),
10599+
SCI_GETSELECTIONEND, 0, 0);
1059510600
bool isTextSelected = (start != end);
10596-
::EnableWindow(::GetDlgItem(getDialogHandle(), IDC_SELECTION_RADIO), isTextSelected);
1059710601

10598-
// If no text is selected and IDC_SELECTION_RADIO is checked, check IDC_ALL_TEXT_RADIO instead
10599-
if (!isTextSelected && (::SendMessage(::GetDlgItem(getDialogHandle(), IDC_SELECTION_RADIO), BM_GETCHECK, 0, 0) == BST_CHECKED)) {
10600-
::SendMessage(::GetDlgItem(getDialogHandle(), IDC_ALL_TEXT_RADIO), BM_SETCHECK, BST_CHECKED, 0);
10601-
::SendMessage(::GetDlgItem(getDialogHandle(), IDC_SELECTION_RADIO), BM_SETCHECK, BST_UNCHECKED, 0);
10602+
HWND hSel = ::GetDlgItem(hDlg, IDC_SELECTION_RADIO);
10603+
::EnableWindow(hSel, isTextSelected);
10604+
10605+
// If no text is selected but Selection is still checked → switch to All Text
10606+
if (!isTextSelected &&
10607+
::SendMessage(hSel, BM_GETCHECK, 0, 0) == BST_CHECKED)
10608+
{
10609+
::CheckRadioButton(
10610+
hDlg,
10611+
IDC_ALL_TEXT_RADIO,
10612+
IDC_COLUMN_MODE_RADIO,
10613+
IDC_ALL_TEXT_RADIO
10614+
);
1060210615
}
1060310616

10604-
// Check if there was a switch from selected to not selected
10605-
if (wasTextSelected && !isTextSelected) {
10606-
if (instance != nullptr) {
10617+
// Inform other UI parts when we just lost a selection
10618+
if (wasTextSelected && !isTextSelected)
10619+
{
10620+
if (instance)
1060710621
instance->setUIElementVisibility();
10608-
}
1060910622
}
10610-
wasTextSelected = isTextSelected; // Update the previous state
10623+
wasTextSelected = isTextSelected;
1061110624
}
1061210625

1061310626
void MultiReplace::onTextChanged() {

0 commit comments

Comments
 (0)