From 4ee2d3876f9befd5ca00db344ab6584239d59dc7 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Tue, 27 Aug 2019 13:55:05 +0200 Subject: [PATCH 1/2] + chg: allow each modification step to split undo typing sequence (set timeout < 20ms) --- Versions/build.txt | 2 +- res/Notepad3.exe.manifest.conf | 2 +- src/Config/Config.cpp | 6 ++---- src/Notepad3.c | 15 ++++++++++++--- src/VersionEx.h | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Versions/build.txt b/Versions/build.txt index 45c4a6b22..bf88273b1 100644 --- a/Versions/build.txt +++ b/Versions/build.txt @@ -1 +1 @@ -2599 +2600 diff --git a/res/Notepad3.exe.manifest.conf b/res/Notepad3.exe.manifest.conf index dbb9431b9..deb4791b1 100644 --- a/res/Notepad3.exe.manifest.conf +++ b/res/Notepad3.exe.manifest.conf @@ -3,7 +3,7 @@ Notepad3 BETA diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 8c06018c3..2fb0292d5 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -631,10 +631,8 @@ void LoadSettings() FileWatching.AutoReloadTimeout = Settings2.AutoReloadTimeout; Defaults2.UndoRedoSplitTimeout = 0UL; - Settings2.UndoRedoSplitTimeout = IniSectionGetInt(Settings2_Section, L"UndoRedoSplitTimeout", Defaults2.UndoRedoSplitTimeout); - if (Settings2.UndoRedoSplitTimeout != 0) { - Settings2.UndoRedoSplitTimeout = clampul(Settings2.UndoRedoSplitTimeout, 100UL, 86400000UL); // max: 24h - } + Settings2.UndoRedoSplitTimeout = clampul(IniSectionGetInt(Settings2_Section, L"UndoRedoSplitTimeout", + Defaults2.UndoRedoSplitTimeout), 0UL, 86400000UL); // deprecated Defaults.RenderingTechnology = IniSectionGetInt(Settings2_Section, L"SciDirectWriteTech", -111); diff --git a/src/Notepad3.c b/src/Notepad3.c index e049ac8b9..aecd38837 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -459,6 +459,7 @@ static int msgcmp(void* mqc1, void* mqc2) } // ---------------------------------------------------------------------------- +#define _MQ_IMMEDIATE (2 * USER_TIMER_MINIMUM - 1) #define _MQ_ms(T) ((T) / USER_TIMER_MINIMUM) static void _MQ_AppendCmd(CmdMessageQueue_t* const pMsgQCmd, int cycles) @@ -6976,7 +6977,7 @@ inline static LRESULT _MsgNotifyLean(const LPNMHDR pnmh, const SCNotification* c _SaveRedoSelection(_SaveUndoSelection()); } } - if (Settings2.UndoRedoSplitTimeout != 0) { + if (Settings2.UndoRedoSplitTimeout > _MQ_IMMEDIATE) { _DelayUndoRedoTypingSequenceSplit(Settings2.UndoRedoSplitTimeout); } bModified = false; // not yet @@ -6991,7 +6992,12 @@ inline static LRESULT _MsgNotifyLean(const LPNMHDR pnmh, const SCNotification* c RestoreAction(scn->token, REDO); } } - if (bModified) { _SetSaveNeededFlag(true); } + if (bModified) { + if ((Settings2.UndoRedoSplitTimeout > 0UL) && (Settings2.UndoRedoSplitTimeout <= _MQ_IMMEDIATE)) { + SciCall_BeginUndoAction(); SciCall_EndUndoAction(); + } + _SetSaveNeededFlag(true); + } } else if (pnmh->code == SCN_SAVEPOINTREACHED) { _SetSaveNeededFlag(false); @@ -7063,7 +7069,7 @@ static LRESULT _MsgNotifyFromEdit(HWND hwnd, const LPNMHDR pnmh, const SCNotific _SaveRedoSelection(_SaveUndoSelection()); } } - if (Settings2.UndoRedoSplitTimeout != 0) { + if (Settings2.UndoRedoSplitTimeout > _MQ_IMMEDIATE) { _DelayUndoRedoTypingSequenceSplit(Settings2.UndoRedoSplitTimeout); } bModified = false; // not yet @@ -7085,6 +7091,9 @@ static LRESULT _MsgNotifyFromEdit(HWND hwnd, const LPNMHDR pnmh, const SCNotific if (scn->linesAdded != 0) { UpdateMarginWidth(); } + if ((Settings2.UndoRedoSplitTimeout > 0UL) && (Settings2.UndoRedoSplitTimeout <= _MQ_IMMEDIATE)) { + SciCall_BeginUndoAction(); SciCall_EndUndoAction(); + } _SetSaveNeededFlag(true); } diff --git a/src/VersionEx.h b/src/VersionEx.h index ce0de48aa..b27991c24 100644 --- a/src/VersionEx.h +++ b/src/VersionEx.h @@ -8,7 +8,7 @@ #define VERSION_MAJOR 5 #define VERSION_MINOR 19 #define VERSION_REV 827 -#define VERSION_BUILD 2599 +#define VERSION_BUILD 2600 #define SCINTILLA_VER 420 #define ONIGURUMA_REGEX_VER 6.9.3 #define UCHARDET_VER 2018.09.27 From c4bd8c212f2e773cba35a0470803f8833e57b8e7 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Tue, 27 Aug 2019 16:17:31 +0200 Subject: [PATCH 2/2] + fix: small bug with timeout undo transaction on selection --- Versions/build.txt | 2 +- res/Notepad3.exe.manifest.conf | 2 +- src/Notepad3.c | 53 +++++++++++++++++++++++++--------- src/VersionEx.h | 2 +- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/Versions/build.txt b/Versions/build.txt index bf88273b1..d00194588 100644 --- a/Versions/build.txt +++ b/Versions/build.txt @@ -1 +1 @@ -2600 +2601 diff --git a/res/Notepad3.exe.manifest.conf b/res/Notepad3.exe.manifest.conf index deb4791b1..d25f82f33 100644 --- a/res/Notepad3.exe.manifest.conf +++ b/res/Notepad3.exe.manifest.conf @@ -3,7 +3,7 @@ Notepad3 BETA diff --git a/src/Notepad3.c b/src/Notepad3.c index aecd38837..9b706dbdb 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -386,6 +386,7 @@ static bool _InUndoRedoTransaction(); static void _SaveRedoSelection(int token); static int _SaveUndoSelection(); static int _UndoRedoActionMap(int token, UndoRedoSelection_t** selection); +static void _SplitUndoTransaction(); // ---------------------------------------------------------------------------- @@ -3483,8 +3484,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) break; case IDT_TIMER_UNDO_REDO_SPLIT: - SciCall_BeginUndoAction(); - SciCall_EndUndoAction(); + _SplitUndoTransaction(); break; @@ -6977,9 +6977,6 @@ inline static LRESULT _MsgNotifyLean(const LPNMHDR pnmh, const SCNotification* c _SaveRedoSelection(_SaveUndoSelection()); } } - if (Settings2.UndoRedoSplitTimeout > _MQ_IMMEDIATE) { - _DelayUndoRedoTypingSequenceSplit(Settings2.UndoRedoSplitTimeout); - } bModified = false; // not yet } // check for ADDUNDOACTION step @@ -6992,9 +6989,17 @@ inline static LRESULT _MsgNotifyLean(const LPNMHDR pnmh, const SCNotification* c RestoreAction(scn->token, REDO); } } - if (bModified) { - if ((Settings2.UndoRedoSplitTimeout > 0UL) && (Settings2.UndoRedoSplitTimeout <= _MQ_IMMEDIATE)) { - SciCall_BeginUndoAction(); SciCall_EndUndoAction(); + if (bModified) { + DWORD const timeout = Settings2.UndoRedoSplitTimeout; + if (timeout != 0UL) { + if (timeout > _MQ_IMMEDIATE) { + _DelayUndoRedoTypingSequenceSplit(timeout); + } + else { + if (!((iModType & SC_PERFORMED_UNDO) || (iModType & SC_PERFORMED_REDO))) { + _SplitUndoTransaction(); + } + } } _SetSaveNeededFlag(true); } @@ -7069,9 +7074,6 @@ static LRESULT _MsgNotifyFromEdit(HWND hwnd, const LPNMHDR pnmh, const SCNotific _SaveRedoSelection(_SaveUndoSelection()); } } - if (Settings2.UndoRedoSplitTimeout > _MQ_IMMEDIATE) { - _DelayUndoRedoTypingSequenceSplit(Settings2.UndoRedoSplitTimeout); - } bModified = false; // not yet } if (iModType & SC_MOD_CONTAINER) { @@ -7089,10 +7091,21 @@ static LRESULT _MsgNotifyFromEdit(HWND hwnd, const LPNMHDR pnmh, const SCNotific UpdateVisibleHotspotIndicators(); if (scn->linesAdded != 0) { + if (Settings.SplitUndoTypingSeqOnLnBreak) { + _SplitUndoTransaction(); + } UpdateMarginWidth(); } - if ((Settings2.UndoRedoSplitTimeout > 0UL) && (Settings2.UndoRedoSplitTimeout <= _MQ_IMMEDIATE)) { - SciCall_BeginUndoAction(); SciCall_EndUndoAction(); + DWORD const timeout = Settings2.UndoRedoSplitTimeout; + if (timeout != 0UL) { + if (timeout > _MQ_IMMEDIATE) { + _DelayUndoRedoTypingSequenceSplit(timeout); + } + else { + if (!((iModType & SC_PERFORMED_UNDO) || (iModType & SC_PERFORMED_REDO))) { + _SplitUndoTransaction(); + } + } } _SetSaveNeededFlag(true); } @@ -7221,7 +7234,6 @@ static LRESULT _MsgNotifyFromEdit(HWND hwnd, const LPNMHDR pnmh, const SCNotific switch (ich) { case '\r': case '\n': - if (Settings.SplitUndoTypingSeqOnLnBreak) { SciCall_BeginUndoAction(); SciCall_EndUndoAction(); } if (Settings.AutoIndent) { _HandleAutoIndent(ich); } break; case '>': @@ -9295,6 +9307,19 @@ static int _UndoRedoActionMap(int token, UndoRedoSelection_t** selection) } +//============================================================================= +// +// _SplitUndoTransaction() +// +// +static void _SplitUndoTransaction() { + if (!_InUndoRedoTransaction()) { + SciCall_BeginUndoAction(); + SciCall_EndUndoAction(); + } +} + + //============================================================================= // // FileIO() diff --git a/src/VersionEx.h b/src/VersionEx.h index b27991c24..49139491c 100644 --- a/src/VersionEx.h +++ b/src/VersionEx.h @@ -8,7 +8,7 @@ #define VERSION_MAJOR 5 #define VERSION_MINOR 19 #define VERSION_REV 827 -#define VERSION_BUILD 2600 +#define VERSION_BUILD 2601 #define SCINTILLA_VER 420 #define ONIGURUMA_REGEX_VER 6.9.3 #define UCHARDET_VER 2018.09.27