Preserve editor undo when switching requests and don't allow undo initial value

This commit is contained in:
Gregory Schier 2018-05-24 23:01:47 -04:00
parent 020b8b301f
commit 0d63a6e7c1

View File

@ -233,7 +233,8 @@ class CodeEditor extends React.Component {
editorStates[uniquenessKey] = {
scroll: this.codeMirror.getScrollInfo(),
selections: this.codeMirror.listSelections(),
cursor: this.codeMirror.getCursor()
cursor: this.codeMirror.getCursor(),
history: this.codeMirror.getHistory(),
};
}
@ -243,8 +244,9 @@ class CodeEditor extends React.Component {
return;
}
const {scroll, selections, cursor} = editorStates[uniquenessKey];
const {scroll, selections, cursor, history} = editorStates[uniquenessKey];
this.codeMirror.scrollTo(scroll.left, scroll.top);
this.codeMirror.setHistory(history);
// NOTE: These won't be visible unless the editor is focused
this.codeMirror.setCursor(cursor.line, cursor.ch, {scroll: false});
@ -304,6 +306,9 @@ class CodeEditor extends React.Component {
// Actually set the value
this._codemirrorSetValue(defaultValue || '');
// Clear history so we can't undo the initial set
this.codeMirror.clearHistory();
// Setup nunjucks listeners
if (this.props.render && !this.props.nunjucksPowerUserMode) {
this.codeMirror.enableNunjucksTags(this.props.render);