Fix cursor and scroll position in codemirror after undo
This commit is contained in:
parent
aeb81fdfad
commit
89de5869c5
@ -218,6 +218,24 @@ define([
|
||||
});
|
||||
editor.focus();
|
||||
|
||||
// Fix cursor and scroll position after undo/redo
|
||||
var undoData;
|
||||
editor.on('beforeChange', function (editor, change) {
|
||||
if (change.origin !== "undo" && change.origin !== "redo") { return; }
|
||||
undoData = editor.getValue();
|
||||
});
|
||||
editor.on('change', function (editor, change) {
|
||||
if (change.origin !== "undo" && change.origin !== "redo") { return; }
|
||||
if (typeof(undoData) === "undefined") { return; }
|
||||
var doc = editor.getValue();
|
||||
var ops = ChainPad.Diff.diff(undoData, doc);
|
||||
undoData = undefined;
|
||||
if (!ops.length) { return; }
|
||||
var cursor = posToCursor(ops[0].offset, doc);
|
||||
editor.setCursor(cursor);
|
||||
editor.scrollIntoView(cursor);
|
||||
});
|
||||
|
||||
var setMode = exp.setMode = function (mode, cb) {
|
||||
exp.highlightMode = mode;
|
||||
if (mode === 'markdown') { mode = 'gfm'; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user