@@ -648,20 +648,8 @@ void MultiReplace::updateReplaceInFilesVisibility()
648
648
649
649
moveAndResizeControls (); // actually MoveWindow()/SetWindowPos() all controls
650
650
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
665
653
666
654
InvalidateRect (_hSelf, NULL , TRUE ); // repaint client
667
655
UpdateWindow (_hSelf);
@@ -10573,41 +10561,66 @@ void MultiReplace::pointerToScintilla() {
10573
10561
}
10574
10562
}
10575
10563
10576
- void MultiReplace::onSelectionChanged () {
10564
+ void MultiReplace::onSelectionChanged ()
10565
+ {
10566
+ static bool wasTextSelected = false ; // remember previous selection state
10577
10567
10578
- static bool wasTextSelected = false ; // This stores the previous state
10568
+ HWND hDlg = getDialogHandle () ; // dialog handle once for reuse
10579
10569
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);
10584
10579
::EnableWindow (hSel, FALSE );
10585
- ::SendMessage (hSel, BM_SETCHECK, BST_UNCHECKED, 0 );
10586
- ::SendMessage (hAll, BM_SETCHECK, BST_CHECKED, 0 );
10587
- return ;
10588
- }
10589
10580
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
+ }
10593
10592
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 );
10595
10600
bool isTextSelected = (start != end);
10596
- ::EnableWindow (::GetDlgItem(getDialogHandle(), IDC_SELECTION_RADIO), isTextSelected);
10597
10601
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
+ );
10602
10615
}
10603
10616
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)
10607
10621
instance->setUIElementVisibility ();
10608
- }
10609
10622
}
10610
- wasTextSelected = isTextSelected; // Update the previous state
10623
+ wasTextSelected = isTextSelected;
10611
10624
}
10612
10625
10613
10626
void MultiReplace::onTextChanged () {
0 commit comments