From 5ae9d8cca45fec94f22fa47e5a2f35637ba32164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 1 Dec 2020 14:55:11 +0100 Subject: [PATCH 1/7] fix history for collab demo --- docs/src/demos/Examples/CollaborativeEditing/index.vue | 2 +- packages/extension-collaboration/src/index.ts | 6 +++--- packages/extension-history/src/index.ts | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/src/demos/Examples/CollaborativeEditing/index.vue b/docs/src/demos/Examples/CollaborativeEditing/index.vue index 3c7f1248..30b0e41a 100644 --- a/docs/src/demos/Examples/CollaborativeEditing/index.vue +++ b/docs/src/demos/Examples/CollaborativeEditing/index.vue @@ -82,7 +82,7 @@ export default { this.editor = new Editor({ extensions: [ - ...defaultExtensions(), + ...defaultExtensions().filter(extension => extension.config.name !== 'history'), Collaboration.configure({ provider, }), diff --git a/packages/extension-collaboration/src/index.ts b/packages/extension-collaboration/src/index.ts index 976d1adb..6249c4bb 100644 --- a/packages/extension-collaboration/src/index.ts +++ b/packages/extension-collaboration/src/index.ts @@ -26,9 +26,9 @@ const Collaboration = Extension.create({ addKeyboardShortcuts() { return { - 'Mod-z': undo, - 'Mod-y': redo, - 'Mod-Shift-z': redo, + 'Mod-z': () => undo(this.editor.state), + 'Mod-y': () => redo(this.editor.state), + 'Mod-Shift-z': () => redo(this.editor.state), } }, diff --git a/packages/extension-history/src/index.ts b/packages/extension-history/src/index.ts index 6f389f2e..b5d48acf 100644 --- a/packages/extension-history/src/index.ts +++ b/packages/extension-history/src/index.ts @@ -7,6 +7,8 @@ export interface HistoryOptions { } const History = Extension.create({ + name: 'history', + defaultOptions: { depth: 100, newGroupDelay: 500, From 30d5ab5f39a0bce78bda10721060442f0e272235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 1 Dec 2020 21:58:29 +0100 Subject: [PATCH 2/7] dont add focus and blur transactions to history --- packages/core/src/extensions/focusEvents.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/core/src/extensions/focusEvents.ts b/packages/core/src/extensions/focusEvents.ts index 051571f4..fad279e6 100644 --- a/packages/core/src/extensions/focusEvents.ts +++ b/packages/core/src/extensions/focusEvents.ts @@ -16,7 +16,10 @@ export const FocusEvents = Extension.create({ focus: (view, event) => { editor.isFocused = true - const transaction = editor.state.tr.setMeta('focus', { event }) + const transaction = editor.state.tr + .setMeta('focus', { event }) + .setMeta('addToHistory', false) + view.dispatch(transaction) return true @@ -24,7 +27,10 @@ export const FocusEvents = Extension.create({ blur: (view, event) => { editor.isFocused = false - const transaction = editor.state.tr.setMeta('blur', { event }) + const transaction = editor.state.tr + .setMeta('blur', { event }) + .setMeta('addToHistory', false) + view.dispatch(transaction) return true From 532eaa4e869180d639a696f2feb26c7ca6d334d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 1 Dec 2020 23:32:39 +0100 Subject: [PATCH 3/7] fix chain again --- packages/core/src/CommandManager.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/core/src/CommandManager.ts b/packages/core/src/CommandManager.ts index b5ea87cd..c41dcb1f 100644 --- a/packages/core/src/CommandManager.ts +++ b/packages/core/src/CommandManager.ts @@ -68,7 +68,6 @@ export default class CommandManager { const callbacks: boolean[] = [] const hasStartTransaction = !!startTr const tr = startTr || state.tr - const props = this.buildProps(tr, shouldDispatch) return new Proxy({}, { get: (_, name: string, proxy) => { @@ -87,7 +86,9 @@ export default class CommandManager { } return (...args: any) => { + const props = this.buildProps(tr, shouldDispatch) const callback = command(...args)(props) + callbacks.push(callback) return proxy @@ -118,6 +119,10 @@ export default class CommandManager { const { editor, commands } = this const { state, view } = editor + if (state.storedMarks) { + tr.setStoredMarks(state.storedMarks) + } + const props = { tr, editor, @@ -141,6 +146,10 @@ export default class CommandManager { } public chainableState(tr: Transaction, state: EditorState): EditorState { + let { selection } = tr + let { doc } = tr + let { storedMarks } = tr + return { ...state, schema: state.schema, @@ -150,15 +159,19 @@ export default class CommandManager { reconfigure: state.reconfigure.bind(state), toJSON: state.toJSON.bind(state), get storedMarks() { - return tr.storedMarks + return storedMarks }, get selection() { - return tr.selection + return selection }, get doc() { - return tr.doc + return doc }, get tr() { + selection = tr.selection + doc = tr.doc + storedMarks = tr.storedMarks + return tr }, } From 1513f8ccc29287805b5ad1c5cd83be5e05d869b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 1 Dec 2020 23:45:01 +0100 Subject: [PATCH 4/7] improve toc demo --- .../Guide/NodeViews/TableOfContents/Component.vue | 2 ++ .../demos/Guide/NodeViews/TableOfContents/index.vue | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue b/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue index 85a9933f..f67c09fe 100644 --- a/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue +++ b/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue @@ -63,7 +63,9 @@ export default { margin-top: 0.75em; } } + +