fix: Split undo transactions before line breaks, rather than after them - #5992
Open
lhmouse wants to merge 1 commit into
Open
fix: Split undo transactions before line breaks, rather than after them#5992lhmouse wants to merge 1 commit into
lhmouse wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new newline check dereferences scn->text without a NULL guard, which can lead to a crash if an insert-check notification arrives without text.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adjusts Notepad3’s Scintilla notification handling so undo transaction boundaries are split before a typed line break, aligning undo behavior with common editors by grouping the newline together with the subsequent auto-indentation.
Changes:
- Move the “split undo transaction on line break” logic from the post-modification
linesAddedpath into the pre-insertSC_MOD_INSERTCHECKpath when the inserted text begins with\r/\n. - Remove the old split behavior that triggered after any insertion that increased
linesAdded.
File summaries
| File | Description |
|---|---|
| src/Notepad3.c | Shifts undo-transaction splitting to occur before newline insertion so newline + auto-indent land in the same undo step. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| bool const bInUndoRedoStep = (iModType & (SC_PERFORMED_UNDO | SC_PERFORMED_REDO)); | ||
| if (iModType & SC_MOD_INSERTCHECK) { | ||
| if (!bInUndoRedoStep) { | ||
| if (Settings.SplitUndoTypingSeqOnLnBreak && (scn->length > 0) && ((scn->text[0] == '\r') || (scn->text[0] == '\n'))) { |
Previously, an undo transaction was started after a line break, so the line break itself was in the end of the previous transaction, and a subsequent auto indentation that was triggered by the line break started a new transaction. Pressing Ctrl+Z undid the auto indentation, and pressing Ctrl+Z a second time undid the line break with previous inputs. In order to be consistent with other editors, a new undo transaction should start after the line break, so they are in the same transaction. Signed-off-by: LIU Hao <lh_mouse@126.com>
Contributor
Author
|
@RaiKoHoff When |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, an undo transaction was started after a line break, so the line break itself was in the end of the previous transaction, and a subsequent auto indention that was triggered by the line break started a new transaction. Pressing Ctrl+Z undid the auto indention, and pressing Ctrl+Z a second time undid the line break with previous inputs.
In order to be consistent with other editors, a new undo transaction should start after the line break, so they are in the same transaction.
Steps to reproduce
aa(space space A A).aawith the line break.Expected behavior
Like in Visual Studio, step 5 should undo the auto indention and the line break, and step 6 should undo
aa(since there's no longer a line break to undo).