[scintilla:bugs] #2491 Undo added text at end of document

0 views
Skip to first unread message

Chinh Nguyen

unread,
Dec 18, 2025, 11:36:29 AM12/18/25
to scintill...@googlegroups.com

[bugs:#2491] Undo added text at end of document

Status: open
Group: Bug
Labels: undo
Created: Thu Dec 18, 2025 04:36 PM UTC by Chinh Nguyen
Last Updated: Thu Dec 18, 2025 04:36 PM UTC
Owner: nobody

If I add a character to the end of a document and then select Undo to remove the character, the lexer is not called to lex. Manually deleting the character is fine and an undo that results in text being added back is fine too.


Sent from sourceforge.net because scintill...@googlegroups.com is subscribed to https://sourceforge.net/p/scintilla/bugs/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/scintilla/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.

Neil Hodgson

unread,
Dec 18, 2025, 4:55:47 PM12/18/25
to scintill...@googlegroups.com

There's a difference between Document::DeleteChars and Document::Undo:

        // DeleteChars:        
        if ((pos < LengthNoExcept()) || (pos == 0))
            ModifiedAt(pos);
        else
            ModifiedAt(pos-1);

         // Undo:
        ModifiedAt(action.position);

Neil Hodgson

unread,
Dec 18, 2025, 10:19:09 PM12/18/25
to scintill...@googlegroups.com

Potential narrow fix. There may be related issues not fixed by this patch.

diff -r 4b8c335b8c50 src/Document.cxx
--- a/src/Document.cxx  Thu Dec 18 14:49:28 2025 +1100
+++ b/src/Document.cxx  Fri Dec 19 14:16:29 2025 +1100
@@ -1590,7 +1590,10 @@
                }
                cb.PerformUndoStep();
                if (action.at != ActionType::container) {
-                   ModifiedAt(action.position);
+                   if ((action.at == ActionType::remove) || (action.position < LengthNoExcept()) || (action.position == 0))
+                       ModifiedAt(action.position);
+                   else
+                       ModifiedAt(action.position - 1);
                    newPos = action.position;
                }

Some of this could be hoisted into a common method with DeleteChars but there is an extra clause in the condition for Undo.


[bugs:#2491] Undo added text at end of document

Status: open
Group: Bug
Labels: undo
Created: Thu Dec 18, 2025 04:36 PM UTC by Chinh Nguyen

Last Updated: Thu Dec 18, 2025 09:55 PM UTC
Owner: nobody

Neil Hodgson

unread,
Jan 6, 2026, 7:53:36 PM (3 days ago) Jan 6
to scintill...@googlegroups.com
  • status: open --> open-fixed
  • Comment:

Committed fix with [7a533d]. Code is different from above to emphasize that the pos-1 branch is the unusual case.


[bugs:#2491] Undo added text at end of document

Status: open-fixed


Group: Bug
Labels: undo
Created: Thu Dec 18, 2025 04:36 PM UTC by Chinh Nguyen

Last Updated: Fri Dec 19, 2025 03:19 AM UTC
Owner: nobody

Neil Hodgson

unread,
Jan 6, 2026, 7:53:44 PM (3 days ago) Jan 6
to scintill...@googlegroups.com
  • labels: undo --> undo, scintilla

[bugs:#2491] Undo added text at end of document

Status: open-fixed
Group: Bug
Labels: undo scintilla

Created: Thu Dec 18, 2025 04:36 PM UTC by Chinh Nguyen

Last Updated: Wed Jan 07, 2026 12:53 AM UTC
Owner: nobody

Reply all
Reply to author
Forward
0 new messages