From cf5fa812ca00d06b6e02c2a1c2c68cb294bcc342 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Fri, 13 Sep 2024 22:25:54 +0700 Subject: [PATCH 1/3] fix: add some space for gapcursor Signed-off-by: Alexander Onnikov --- packages/theme/styles/_text-editor.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/theme/styles/_text-editor.scss b/packages/theme/styles/_text-editor.scss index b2cc2eea038..41c6f2e7dee 100644 --- a/packages/theme/styles/_text-editor.scss +++ b/packages/theme/styles/_text-editor.scss @@ -10,6 +10,7 @@ .text-editor-view { // overflow-y: auto; color: var(--theme-text-primary-color); + margin: 0.25rem 0; .suggestion { padding-left: 0.25rem; From 6fa4692b173b5e620d433400383544e9ad674e32 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Fri, 13 Sep 2024 22:26:16 +0700 Subject: [PATCH 2/3] fix: adjust paragraphs styles in editor Signed-off-by: Alexander Onnikov --- packages/theme/styles/_text-editor.scss | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/theme/styles/_text-editor.scss b/packages/theme/styles/_text-editor.scss index 41c6f2e7dee..50fb11ff2b7 100644 --- a/packages/theme/styles/_text-editor.scss +++ b/packages/theme/styles/_text-editor.scss @@ -64,6 +64,7 @@ p { margin-block-start: 0.5rem; + margin-block-end: 0.5rem; } >*+* { @@ -73,6 +74,8 @@ ul, ol { + margin-top: 0.5rem; + margin-bottom: 0.5rem; margin-right: .25rem; margin-left: .75rem; padding: 0; @@ -89,8 +92,7 @@ ul[data-type="todoList"] { list-style: none; - margin: 0; - padding: 0; + margin-left: 0; li { margin: 0; From 682dbd7c00b95fb53abb57c982c7433d84d31a64 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Fri, 13 Sep 2024 23:23:52 +0700 Subject: [PATCH 3/3] fix left menu insert logic Signed-off-by: Alexander Onnikov --- .../components/CollaborativeTextEditor.svelte | 34 +++++-------------- .../src/components/extension/leftMenu.ts | 7 ++-- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte b/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte index 60494cc0504..feb3c7e23b4 100644 --- a/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte +++ b/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte @@ -161,15 +161,7 @@ editor?.commands.insertTable(options) }, insertCodeBlock: () => { - editor?.commands.insertContent( - { - type: 'codeBlock', - content: [{ type: 'text', text: ' ' }] - }, - { - updateSelection: false - } - ) + editor?.commands.setCodeBlock() }, insertContent: (content) => { editor?.commands.insertContent(content) @@ -341,28 +333,18 @@ targetItem instanceof MouseEvent ? getEventPositionElement(targetItem) : getPopupPositionElement(targetItem) } - // We need to trigger it asynchronously in order for the editor to finish its focus event - // Otherwise, it hoggs the focus from the popup and keyboard navigation doesn't work - setTimeout(() => { - addTableHandler(editor.commands.insertTable, position) - }) + // addTableHandler opens popup so the editor loses focus + // so in the callback we need to refocus again + void addTableHandler((options: { rows?: number, cols?: number, withHeaderRow?: boolean }) => { + editor.chain().insertTable(options).focus(pos).run() + }, position) break } case 'code-block': - // For some reason .setCodeBlock doesnt work in our case - editor.commands.insertContent( - { - type: 'codeBlock', - content: [{ type: 'text', text: ' ' }] - }, - { - updateSelection: false - } - ) - editor.commands.focus(pos, { scrollIntoView: false }) + editor.commands.insertContentAt(pos, { type: 'codeBlock' }) break case 'todo-list': - editor.commands.toggleTaskList() + editor.chain().insertContentAt(pos, { type: 'paragraph' }).toggleTaskList().run() break case 'separator-line': editor.commands.setHorizontalRule() diff --git a/plugins/text-editor-resources/src/components/extension/leftMenu.ts b/plugins/text-editor-resources/src/components/extension/leftMenu.ts index 214eba92ba9..c3b27a1cdf8 100644 --- a/plugins/text-editor-resources/src/components/extension/leftMenu.ts +++ b/plugins/text-editor-resources/src/components/extension/leftMenu.ts @@ -45,10 +45,12 @@ function posAtLeftMenuElement (view: EditorView, leftMenuElement: HTMLElement, o }) if (position === null) { - return -1 + return 0 } - return position.inside >= 0 ? position.inside : position.pos + const pos = position.inside >= 0 ? position.inside : position.pos + const $pos = view.state.doc.resolve(pos) + return $pos.depth === 0 ? $pos.pos : $pos.before($pos.depth) } function LeftMenu (options: LeftMenuOptions): Plugin { @@ -106,7 +108,6 @@ function LeftMenu (options: LeftMenuOptions): Plugin { (val) => { if (leftMenuElement === null) return const pos = posAtLeftMenuElement(view, leftMenuElement, offsetX) - void options.handleSelect(val, pos, e) } )