From d3bb31b0ecc42370ee10fdced38d2bec40f8c40b Mon Sep 17 00:00:00 2001 From: xomx Date: Fri, 3 Oct 2025 22:30:44 +0200 Subject: [PATCH] Fix Monitoring in one view affects selections and position in second view Fix #17046, close #17056 --- PowerEditor/src/Notepad_plus.cpp | 32 +++++++++++++++++++++++--------- PowerEditor/src/Notepad_plus.h | 2 +- PowerEditor/src/NppCommands.cpp | 6 +++--- PowerEditor/src/NppIO.cpp | 13 +++++++++---- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index dcd29d497..090b47e7f 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -9030,19 +9030,33 @@ HBITMAP Notepad_plus::generateSolidColourMenuItemIcon(COLORREF colour) return hNewBitmap; } - -void Notepad_plus::clearChangesHistory() +void Notepad_plus::clearChangesHistory(int iView) { - Sci_Position pos = (Sci_Position)::SendMessage(_pEditView->getHSelf(), SCI_GETCURRENTPOS, 0, 0); - int chFlags = (int)::SendMessage(_pEditView->getHSelf(), SCI_GETCHANGEHISTORY, 0, 0); + // use current view by default + ScintillaEditView* pViewToChange = _pEditView; + ScintillaEditView* pAnotherView = _pNonEditView; - _pEditView->execute(SCI_EMPTYUNDOBUFFER); - _pEditView->execute(SCI_SETCHANGEHISTORY, SC_CHANGE_HISTORY_DISABLED); - _pEditView->execute(SCI_SETCHANGEHISTORY, chFlags); - _pEditView->execute(SCI_GOTOPOS, pos); + if (iView == MAIN_VIEW) + { + pViewToChange = &_mainEditView; + pAnotherView = &_subEditView; + } + else if (iView == SUB_VIEW) + { + pViewToChange = &_subEditView; + pAnotherView = &_mainEditView; + } + + Sci_Position pos = static_cast(::SendMessage(pViewToChange->getHSelf(), SCI_GETCURRENTPOS, 0, 0)); + int chFlags = static_cast(::SendMessage(pViewToChange->getHSelf(), SCI_GETCHANGEHISTORY, 0, 0)); + + pViewToChange->execute(SCI_EMPTYUNDOBUFFER); + pViewToChange->execute(SCI_SETCHANGEHISTORY, SC_CHANGE_HISTORY_DISABLED); + pViewToChange->execute(SCI_SETCHANGEHISTORY, chFlags); + pViewToChange->execute(SCI_GOTOPOS, pos); checkUndoState(); - _pNonEditView->redraw(); // Prevent cloned document visual glichy on another view + pAnotherView->redraw(); // Prevent cloned document visual glitch on another view } // Based on https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12248#issuecomment-1258561261. diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index f35a22750..48ae88f84 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -662,7 +662,7 @@ private: HBITMAP generateSolidColourMenuItemIcon(COLORREF colour); - void clearChangesHistory(); + void clearChangesHistory(int iView); void changedHistoryGoTo(int idGoTo); HMENU createMenuFromMenu(HMENU hSourceMenu, const std::vector& commandIds); diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 76fe52769..6e7cd243b 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1782,9 +1782,9 @@ void Notepad_plus::command(int id) changedHistoryGoTo(id); break; - case IDM_SEARCH_CLEAR_CHANGE_HISTORY: - clearChangesHistory(); - break; + case IDM_SEARCH_CLEAR_CHANGE_HISTORY: + clearChangesHistory(currentView()); + break; case IDM_LANG_USER_DLG : { diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index c3708bc3d..97a4506be 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -609,15 +609,21 @@ bool Notepad_plus::doReload(BufferID id, bool alert) _subEditView.restoreCurrentPosPreStep(); } + auto svp = NppParameters::getInstance().getSVP(); + // Once reload is complete, activate buffer which will take care of // many settings such as update status bar, clickable link etc. if ( ((currentView() == MAIN_VIEW) && mainVisible) || ((currentView() == SUB_VIEW) && subVisible)) { activateBuffer(id, currentView(), true); + + if (svp._isChangeHistoryMarginEnabled || svp._isChangeHistoryIndicatorEnabled) + clearChangesHistory(currentView()); } else { // handle also the less usual case when the reloaded buffer is not in the current active view + int originalActiveView = currentView(); BufferID originalActiveBufferID = nullptr; if (mainVisible) @@ -631,11 +637,10 @@ bool Notepad_plus::doReload(BufferID id, bool alert) activateBuffer(id, SUB_VIEW, true); } activateBuffer(originalActiveBufferID, originalActiveView, true); // set back the original - } - auto svp = NppParameters::getInstance().getSVP(); - if (svp._isChangeHistoryMarginEnabled || svp._isChangeHistoryIndicatorEnabled) - clearChangesHistory(); + if (svp._isChangeHistoryMarginEnabled || svp._isChangeHistoryIndicatorEnabled) + clearChangesHistory(otherView()); + } return res; }