From 8f38707d33d869a5b8f5014dbb18619b166486a0 Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Tue, 15 Dec 2020 11:08:52 -0500 Subject: [PATCH] Improve text selection after Replace All In Selection operation Fix #9270, close #9273 --- .../src/ScitillaComponent/FindReplaceDlg.cpp | 20 ++++++++++++++++--- .../src/ScitillaComponent/FindReplaceDlg_rc.h | 1 - 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index 08ccdaf5..d424a3e5 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -2023,7 +2023,23 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool findReplaceInfo._txt2replace = txt2replace; findReplaceInfo._startRange = startPosition; findReplaceInfo._endRange = endPosition; - return processRange(op, findReplaceInfo, pFindersInfo, pOptions, colourStyleID); + + int nbProcessed = processRange(op, findReplaceInfo, pFindersInfo, pOptions, colourStyleID); + + if (nbProcessed > 0 && op == ProcessReplaceAll && pOptions->_isInSelection) + { + int newDocLength = static_cast((*_ppEditView)->execute(SCI_GETLENGTH)); + endPosition += newDocLength - docLength; + (*_ppEditView)->execute(SCI_SETSELECTION, endPosition, startPosition); + (*_ppEditView)->execute(SCI_SCROLLRANGE, startPosition, endPosition); + if (startPosition == endPosition) + { + setChecked(IDC_IN_SELECTION_CHECK, false); + enableFindDlgItem(IDC_IN_SELECTION_CHECK, false); + } + } + + return nbProcessed; } int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findReplaceInfo, const FindersInfo * pFindersInfo, const FindOption *opt, int colourStyleID, ScintillaEditView *view2Process) @@ -2651,7 +2667,6 @@ void FindReplaceDlg::enableReplaceFunc(bool isEnable) showFindDlgItem(IDREPLACE, isEnable); showFindDlgItem(IDREPLACEWITH, isEnable); showFindDlgItem(IDREPLACEALL, isEnable); - showFindDlgItem(IDREPLACEINSEL, isEnable); showFindDlgItem(IDC_REPLACE_OPENEDFILES, isEnable); showFindDlgItem(IDC_REPLACEINSELECTION); showFindDlgItem(IDC_IN_SELECTION_CHECK); @@ -3260,7 +3275,6 @@ void FindReplaceDlg::enableMarkFunc() showFindDlgItem(IDREPLACE, false); showFindDlgItem(IDREPLACEWITH, false); showFindDlgItem(IDREPLACEALL, false); - showFindDlgItem(IDREPLACEINSEL, false); showFindDlgItem(IDC_REPLACE_OPENEDFILES, false); showFindDlgItem(IDC_REPLACEINSELECTION, false); diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h index d1509ca2..93d22727 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h @@ -44,7 +44,6 @@ #define IDUNSLASH 1607 #define IDREPLACE 1608 #define IDREPLACEALL 1609 -#define IDREPLACEINSEL 1610 #define ID_STATICTEXT_REPLACE 1611 //#define IDDIRECTIONUP 1612 //#define IDDIRECTIONDOWN 1613