From b6a99ce7526c7c74bc82b886093167586fc37ed7 Mon Sep 17 00:00:00 2001 From: Charley DAVID Date: Mon, 19 Aug 2019 18:12:55 +0200 Subject: [PATCH] Fix removing marks generate useless operations (#2946) --- packages/slate/src/commands/by-path.js | 4 +++ .../slate/test/history/undo/toggle-mark.js | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 packages/slate/test/history/undo/toggle-mark.js diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index 56ddfaacc..4d08472b9 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -237,6 +237,10 @@ Commands.removeMarksByPath = (editor, path, offset, length, marks) => { const { document } = value const node = document.assertNode(path) + if (marks.intersect(node.marks).isEmpty()) { + return + } + editor.withoutNormalizing(() => { // If it ends before the end of the node, we'll need to split to create a new // text with different marks. diff --git a/packages/slate/test/history/undo/toggle-mark.js b/packages/slate/test/history/undo/toggle-mark.js new file mode 100644 index 000000000..ac08ecf5c --- /dev/null +++ b/packages/slate/test/history/undo/toggle-mark.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../helpers/h' + +export default function(editor) { + editor.addMark('bold') + editor.flush().removeMark('bold') + editor.flush().undo() +} + +export const input = ( + + + + one two three + + + +) + +export const output = ( + + + + one{' '} + + two + + three + + + +)