diff --git a/lib/models/selection.js b/lib/models/selection.js index 3117bc173..ceb2de400 100644 --- a/lib/models/selection.js +++ b/lib/models/selection.js @@ -11,7 +11,7 @@ const EDGE_METHODS = [ 'has%AtStartOf', 'has%AtEndOf', 'has%Between', - 'has%In' + 'has%In', ] /** @@ -24,7 +24,8 @@ const DEFAULTS = { focusKey: null, focusOffset: 0, isBackward: null, - isFocused: false + isFocused: false, + marks: null, } /** diff --git a/lib/models/state.js b/lib/models/state.js index fbfcb18aa..f05e3207b 100644 --- a/lib/models/state.js +++ b/lib/models/state.js @@ -21,7 +21,6 @@ const History = new Record({ */ const DEFAULTS = { - cursorMarks: null, document: new Document(), selection: new Selection(), history: new History(), @@ -315,7 +314,7 @@ class State extends new Record(DEFAULTS) { */ get marks() { - return this.cursorMarks || this.document.getMarksAtRange(this.selection) + return this.selection.marks || this.document.getMarksAtRange(this.selection) } /** diff --git a/lib/models/transform.js b/lib/models/transform.js index 9917113d2..cad74ee6b 100644 --- a/lib/models/transform.js +++ b/lib/models/transform.js @@ -102,7 +102,8 @@ class Transform { apply(options = {}) { let { state, operations } = this - let { cursorMarks, history, selection } = state + let { history, selection } = state + let { marks } = selection let { undos, redos } = history // Determine whether we need to create a new snapshot. @@ -121,10 +122,9 @@ class Transform { } // If there are cursor marks and they haven't changed, remove them. - if (state.cursorMarks && state.cursorMarks == cursorMarks) { - state = state.merge({ - cursorMarks: null - }) + if (state.selection.marks && state.selection.marks == marks) { + selection = selection.merge({ marks: null }) + state = state.merge({ selection }) } // Apply the "isNative" flag, which is used to allow for natively-handled @@ -144,7 +144,7 @@ class Transform { shouldSnapshot() { const { state, operations } = this - const { cursorMarks, history, selection } = state + const { history, selection } = state const { undos, redos } = history const previous = undos.peek() diff --git a/lib/plugins/core.js b/lib/plugins/core.js index 746431242..28dc609e5 100644 --- a/lib/plugins/core.js +++ b/lib/plugins/core.js @@ -90,7 +90,7 @@ function Plugin(options = {}) { const isNative = ( state.isCollapsed && state.startText.text != '' && - state.cursorMarks == null && + state.selection.marks == null && chars.equals(nextChars) ) diff --git a/lib/transforms/at-current-range.js b/lib/transforms/at-current-range.js index 9a36ea770..a807f5ac4 100644 --- a/lib/transforms/at-current-range.js +++ b/lib/transforms/at-current-range.js @@ -35,12 +35,13 @@ import { export function addMark(transform, mark) { mark = Normalize.mark(mark) let { state } = transform - let { cursorMarks, document, selection } = state + let { document, selection } = state // If the selection is collapsed, add the mark to the cursor instead. if (selection.isCollapsed) { const marks = document.getMarksAtRange(selection) - state = state.merge({ cursorMarks: marks.add(mark) }) + selection = selection.merge({ marks: marks.add(mark) }) + state = state.merge({ selection }) transform.state = state return transform } @@ -377,7 +378,7 @@ export function insertInline(transform, inline) { export function insertText(transform, text, marks) { let { state } = transform - let { cursorMarks, document, selection } = state + let { document, selection } = state let after const isVoid = document.hasVoidParent(state.startText) @@ -395,7 +396,8 @@ export function insertText(transform, text, marks) { } // Insert the text and update the selection. - state = insertTextAtRange(transform, selection, text, marks || cursorMarks) + marks = marks || selection.marks + state = insertTextAtRange(transform, selection, text, marks) state = transform.state state = state.merge({ selection: after }) transform.state = state @@ -499,12 +501,13 @@ export function splitInline(transform, depth = Infinity) { export function removeMark(transform, mark) { mark = Normalize.mark(mark) let { state } = transform - let { cursorMarks, document, selection } = state + let { document, selection } = state // If the selection is collapsed, remove the mark from the cursor instead. if (selection.isCollapsed) { const marks = document.getMarksAtRange(selection) - state = state.merge({ cursorMarks: marks.remove(mark) }) + selection = selection.merge({ marks: marks.remove(mark) }) + state = state.merge({ selection }) transform.state = state return transform }