Marked text and undo Bug #675

bspoel opened this Issue Jul 30, 2012 · 1 comment


None yet
2 participants

bspoel commented Jul 30, 2012

Synopsis: When a line, that contains text marked through markText(), is affected by undo, the marked text disappears.

Reproduce: Open the following page,

<!doctype html>
    <meta charset="utf-8">
    <title>CodeMirror: Marked text and undo Bug</title>
    <script src="../lib/codemirror.js"></script>
    <link rel="stylesheet" href="../lib/codemirror.css">
    <h1>CodeMirror: Marked text and undo Bug</h1>
    <textarea id="code" name="code">This is a keyword</textarea>
      var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
        mode: 'text/plain',
        tabMode: 'indent'
      onload = function() {
        editor.markText({line:0, ch:0}, {line:0, ch:5}, 'cm-keyword');


Type something, press CTRL+Z. 'this' isn't marked anymore, while I expected it to be unaffected.

Occurs in:
CodeMirror 2.32 and the latest development snapshot
FireFox 14.0.1, Chrome 18.0.1025.168 (Developer Build 134367 Linux) Ubuntu 12.04
Ubuntu 12.04


marijnh commented Jul 30, 2012

This is a known issue, but I consider it to be acceptable behavior. On the one hand, it's nice if undo really goes back to the old state, but on the other hand, replacing text will remove any markers on it, and delete+undo can be seen as a replace operation.

On the practical side, doing this properly would reduce the efficiency of the undo history implementation quite a bit, and complicate things significantly, so I'm hesitant to make that change.

@marijnh marijnh closed this in 40c42b5 Sep 10, 2012

marijnh added a commit that referenced this issue Sep 10, 2012

Make undo/redo preserve text markers and bookmarks
Cleans up the implementation of marked ranges, makes the data
structure for markers-within-a-line persistant, and attaches them to
the lines stored in the undo history when necessary.

Closes #675
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment