Menu

#2491 Undo added text at end of document

Bug
open
nobody
undo (5)
5
7 days ago
2025-12-18
No

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.

Discussion

  • Neil Hodgson

    Neil Hodgson - 7 days ago

    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

    Neil Hodgson - 7 days ago

    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.

     

Log in to post a comment.