From 90176b21aeff5f9bdbac2d425854b390e95ee74c Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Thu, 21 Nov 2019 10:42:06 -0500 Subject: [PATCH] Make 'Clear all marks' respect 'In selection' choice Fix #6271, close #7636 --- .../src/ScitillaComponent/FindReplaceDlg.cpp | 53 ++++++++++++++----- .../src/ScitillaComponent/FindReplaceDlg.h | 1 + 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index 33afdbfa5..fa2788f40 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -1366,12 +1366,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM if (_currentStatus == MARK_DLG) { if (isMacroRecording) saveInMacro(wParam, FR_OP_FIND); - (*_ppEditView)->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE); - if (_options._doMarkLine) - { - (*_ppEditView)->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK); - } - setStatusbarMessage(TEXT(""), FSNoMessage); + clearMarks(_options); } } return TRUE; @@ -2579,6 +2574,7 @@ void FindReplaceDlg::saveInMacro(size_t cmd, int cmdType) if (cmd == IDC_CLEAR_ALL) { booleans = _options._doMarkLine ? IDF_MARKLINE_CHECK : 0; + booleans |= _options._isInSelection ? IDF_IN_SELECTION_CHECK : 0; } ::SendMessage(_hParent, WM_FRSAVE_INT, IDC_FRCOMMAND_BOOLEANS, booleans); ::SendMessage(_hParent, WM_FRSAVE_INT, IDC_FRCOMMAND_EXEC, cmd); @@ -2811,12 +2807,7 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st case IDC_CLEAR_ALL: { - (*_ppEditView)->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE); - if (_env->_doMarkLine) - { - (*_ppEditView)->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK); - } - setStatusbarMessage(TEXT(""), FSNoMessage); + clearMarks(*_env); break; } @@ -2838,6 +2829,44 @@ void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_st } } +void FindReplaceDlg::clearMarks(const FindOption& opt) +{ + if (opt._isInSelection) + { + Sci_CharacterRange cr = (*_ppEditView)->getSelection(); + + int startPosition = cr.cpMin; + int endPosition = cr.cpMax; + + (*_ppEditView)->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE); + (*_ppEditView)->execute(SCI_INDICATORCLEARRANGE, startPosition, endPosition); + + if (opt._doMarkLine) + { + auto lineNumber = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, startPosition); + auto lineNumberEnd = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, endPosition - 1); + + for (auto i = lineNumber; i <= lineNumberEnd; ++i) + { + auto state = (*_ppEditView)->execute(SCI_MARKERGET, i); + + if (state & (1 << MARK_BOOKMARK)) + (*_ppEditView)->execute(SCI_MARKERDELETE, i, MARK_BOOKMARK); + } + } + } + else + { + (*_ppEditView)->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE); + if (opt._doMarkLine) + { + (*_ppEditView)->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK); + } + } + + setStatusbarMessage(TEXT(""), FSNoMessage); +} + void FindReplaceDlg::setFindInFilesDirFilter(const TCHAR *dir, const TCHAR *filters) { if (dir) diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h index 2bb7a4f1a..992d156b5 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h @@ -330,6 +330,7 @@ public : }; void execSavedCommand(int cmd, uptr_t intValue, const generic_string& stringValue); + void clearMarks(const FindOption& opt); void setStatusbarMessage(const generic_string & msg, FindStatus staus); Finder * createFinder(); bool removeFinder(Finder *finder2remove);