Skip to content

Commit d3bb31b

Browse files
xomxdonho
authored andcommitted
Fix Monitoring in one view affects selections and position in second view
Fix notepad-plus-plus#17046, close notepad-plus-plus#17056
1 parent f424ec1 commit d3bb31b

4 files changed

Lines changed: 36 additions & 17 deletions

File tree

PowerEditor/src/Notepad_plus.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9030,19 +9030,33 @@ HBITMAP Notepad_plus::generateSolidColourMenuItemIcon(COLORREF colour)
90309030
return hNewBitmap;
90319031
}
90329032

9033-
9034-
void Notepad_plus::clearChangesHistory()
9033+
void Notepad_plus::clearChangesHistory(int iView)
90359034
{
9036-
Sci_Position pos = (Sci_Position)::SendMessage(_pEditView->getHSelf(), SCI_GETCURRENTPOS, 0, 0);
9037-
int chFlags = (int)::SendMessage(_pEditView->getHSelf(), SCI_GETCHANGEHISTORY, 0, 0);
9035+
// use current view by default
9036+
ScintillaEditView* pViewToChange = _pEditView;
9037+
ScintillaEditView* pAnotherView = _pNonEditView;
9038+
9039+
if (iView == MAIN_VIEW)
9040+
{
9041+
pViewToChange = &_mainEditView;
9042+
pAnotherView = &_subEditView;
9043+
}
9044+
else if (iView == SUB_VIEW)
9045+
{
9046+
pViewToChange = &_subEditView;
9047+
pAnotherView = &_mainEditView;
9048+
}
9049+
9050+
Sci_Position pos = static_cast<Sci_Position>(::SendMessage(pViewToChange->getHSelf(), SCI_GETCURRENTPOS, 0, 0));
9051+
int chFlags = static_cast<int>(::SendMessage(pViewToChange->getHSelf(), SCI_GETCHANGEHISTORY, 0, 0));
90389052

9039-
_pEditView->execute(SCI_EMPTYUNDOBUFFER);
9040-
_pEditView->execute(SCI_SETCHANGEHISTORY, SC_CHANGE_HISTORY_DISABLED);
9041-
_pEditView->execute(SCI_SETCHANGEHISTORY, chFlags);
9042-
_pEditView->execute(SCI_GOTOPOS, pos);
9053+
pViewToChange->execute(SCI_EMPTYUNDOBUFFER);
9054+
pViewToChange->execute(SCI_SETCHANGEHISTORY, SC_CHANGE_HISTORY_DISABLED);
9055+
pViewToChange->execute(SCI_SETCHANGEHISTORY, chFlags);
9056+
pViewToChange->execute(SCI_GOTOPOS, pos);
90439057

90449058
checkUndoState();
9045-
_pNonEditView->redraw(); // Prevent cloned document visual glichy on another view
9059+
pAnotherView->redraw(); // Prevent cloned document visual glitch on another view
90469060
}
90479061

90489062
// Based on https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12248#issuecomment-1258561261.

PowerEditor/src/Notepad_plus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ friend class FileManager;
662662

663663
HBITMAP generateSolidColourMenuItemIcon(COLORREF colour);
664664

665-
void clearChangesHistory();
665+
void clearChangesHistory(int iView);
666666
void changedHistoryGoTo(int idGoTo);
667667

668668
HMENU createMenuFromMenu(HMENU hSourceMenu, const std::vector<int>& commandIds);

PowerEditor/src/NppCommands.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,9 +1782,9 @@ void Notepad_plus::command(int id)
17821782
changedHistoryGoTo(id);
17831783
break;
17841784

1785-
case IDM_SEARCH_CLEAR_CHANGE_HISTORY:
1786-
clearChangesHistory();
1787-
break;
1785+
case IDM_SEARCH_CLEAR_CHANGE_HISTORY:
1786+
clearChangesHistory(currentView());
1787+
break;
17881788

17891789
case IDM_LANG_USER_DLG :
17901790
{

PowerEditor/src/NppIO.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,21 @@ bool Notepad_plus::doReload(BufferID id, bool alert)
609609
_subEditView.restoreCurrentPosPreStep();
610610
}
611611

612+
auto svp = NppParameters::getInstance().getSVP();
613+
612614
// Once reload is complete, activate buffer which will take care of
613615
// many settings such as update status bar, clickable link etc.
614616
if ( ((currentView() == MAIN_VIEW) && mainVisible) || ((currentView() == SUB_VIEW) && subVisible))
615617
{
616618
activateBuffer(id, currentView(), true);
619+
620+
if (svp._isChangeHistoryMarginEnabled || svp._isChangeHistoryIndicatorEnabled)
621+
clearChangesHistory(currentView());
617622
}
618623
else
619624
{
620625
// handle also the less usual case when the reloaded buffer is not in the current active view
626+
621627
int originalActiveView = currentView();
622628
BufferID originalActiveBufferID = nullptr;
623629
if (mainVisible)
@@ -631,11 +637,10 @@ bool Notepad_plus::doReload(BufferID id, bool alert)
631637
activateBuffer(id, SUB_VIEW, true);
632638
}
633639
activateBuffer(originalActiveBufferID, originalActiveView, true); // set back the original
634-
}
635640

636-
auto svp = NppParameters::getInstance().getSVP();
637-
if (svp._isChangeHistoryMarginEnabled || svp._isChangeHistoryIndicatorEnabled)
638-
clearChangesHistory();
641+
if (svp._isChangeHistoryMarginEnabled || svp._isChangeHistoryIndicatorEnabled)
642+
clearChangesHistory(otherView());
643+
}
639644

640645
return res;
641646
}

0 commit comments

Comments
 (0)