Menu

#2491 Undo added text at end of document

Bug
closed-fixed
nobody
5
2026-02-24
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 - 2025-12-18

    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 - 2025-12-19

    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.

     
  • Neil Hodgson

    Neil Hodgson - 2026-01-07
    • status: open --> open-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2026-01-07

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

     

    Related

    Commit: [7a533d]

  • Neil Hodgson

    Neil Hodgson - 2026-01-07
    • labels: undo --> undo, scintilla
     
  • Neil Hodgson

    Neil Hodgson - 2026-02-24
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB