From 0a812c497e1dc83a79f5cffdab52d2ffd0dab851 Mon Sep 17 00:00:00 2001 From: LIlGG <1103069291@qq.com> Date: Wed, 10 Jan 2024 11:04:59 +0800 Subject: [PATCH 1/3] feat: add shortcut for table deletion --- .../src/extensions/list-keymap/index.ts | 3 +- .../editor/src/extensions/table/index.ts | 47 ++++++++++++++++++- .../editor/src/extensions/table/util.ts | 16 ++++++- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/console/packages/editor/src/extensions/list-keymap/index.ts b/console/packages/editor/src/extensions/list-keymap/index.ts index 578afe34b..fb08a07a1 100644 --- a/console/packages/editor/src/extensions/list-keymap/index.ts +++ b/console/packages/editor/src/extensions/list-keymap/index.ts @@ -15,8 +15,7 @@ const ExtensionListKeymap = ListKeymap.extend({ let handled = false; if (!editor.state.selection.empty) { - editor.commands.deleteSelection(); - return true; + return false; } this.options.listTypes.forEach( diff --git a/console/packages/editor/src/extensions/table/index.ts b/console/packages/editor/src/extensions/table/index.ts index e1bb717c8..75e0ddf8d 100644 --- a/console/packages/editor/src/extensions/table/index.ts +++ b/console/packages/editor/src/extensions/table/index.ts @@ -1,5 +1,10 @@ import TiptapTable, { type TableOptions } from "@tiptap/extension-table"; -import { isActive, type Editor, type Range } from "@/tiptap/vue-3"; +import { + isActive, + type Editor, + type Range, + isNodeActive, +} from "@/tiptap/vue-3"; import type { Node as ProseMirrorNode, NodeView, @@ -25,6 +30,8 @@ import { markRaw } from "vue"; import { i18n } from "@/locales"; import type { ExtensionOptions, NodeBubbleMenu } from "@/types"; import { BlockActionSeparator, ToolboxItem } from "@/components"; +import { hasTableBefore, isTableSelected } from "./util"; +import { Editor } from "@tiptap/core"; function updateColumns( node: ProseMirrorNode, @@ -375,6 +382,44 @@ const Table = TiptapTable.extend({ }, }; }, + + addKeyboardShortcuts() { + const handleBackspace = () => { + const { editor } = this; + if (editor.commands.undoInputRule()) { + return true; + } + + // the node in the current active state is not a table + // and the previous node is a table + if ( + !isNodeActive(editor.state, Table.name) && + hasTableBefore(editor.state) + ) { + editor.commands.selectNodeBackward(); + return true; + } + + if (!isNodeActive(editor.state, Table.name)) { + return false; + } + + // If the table is currently selected, + // then delete the whole table + if (isTableSelected(editor.state.selection)) { + editor.commands.deleteTable(); + return true; + } + + return false; + }; + + return { + Backspace: () => handleBackspace(), + + "Mod-Backspace": () => handleBackspace(), + }; + }, }).configure({ resizable: true }); export default Table; diff --git a/console/packages/editor/src/extensions/table/util.ts b/console/packages/editor/src/extensions/table/util.ts index ead80228b..db9e27cc9 100644 --- a/console/packages/editor/src/extensions/table/util.ts +++ b/console/packages/editor/src/extensions/table/util.ts @@ -1,6 +1,6 @@ import { findParentNode } from "@/tiptap/vue-3"; import { Node, CellSelection, TableMap } from "@/tiptap/pm"; -import type { Selection, Transaction } from "@/tiptap/pm"; +import type { EditorState, Selection, Transaction } from "@/tiptap/pm"; export const selectTable = (tr: Transaction) => { const table = findTable(tr.selection); @@ -236,3 +236,17 @@ export const isTableSelected = (selection: any) => { return false; }; + +export const hasTableBefore = (editorState: EditorState) => { + const { $anchor } = editorState.selection; + + const previousNodePos = Math.max(0, $anchor.pos - 2); + + const previousNode = editorState.doc.resolve(previousNodePos).node(); + + if (!previousNode || !(previousNode.type.name === "table")) { + return false; + } + + return true; +}; From a6eda8d61192f07ff8cfb3f8b565baa94ea5601d Mon Sep 17 00:00:00 2001 From: LIlGG <1103069291@qq.com> Date: Wed, 10 Jan 2024 11:21:33 +0800 Subject: [PATCH 2/3] remove editor import --- console/packages/editor/src/extensions/table/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/console/packages/editor/src/extensions/table/index.ts b/console/packages/editor/src/extensions/table/index.ts index 75e0ddf8d..3ad90ea66 100644 --- a/console/packages/editor/src/extensions/table/index.ts +++ b/console/packages/editor/src/extensions/table/index.ts @@ -31,7 +31,6 @@ import { i18n } from "@/locales"; import type { ExtensionOptions, NodeBubbleMenu } from "@/types"; import { BlockActionSeparator, ToolboxItem } from "@/components"; import { hasTableBefore, isTableSelected } from "./util"; -import { Editor } from "@tiptap/core"; function updateColumns( node: ProseMirrorNode, From c59aed651002f1682ee81e9df124ddb1e1d66ac7 Mon Sep 17 00:00:00 2001 From: John Niang Date: Mon, 15 Jan 2024 00:16:48 +0800 Subject: [PATCH 3/3] Add codecov action into workflow Signed-off-by: John Niang --- .github/workflows/halo.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/halo.yaml b/.github/workflows/halo.yaml index 9ef2b734e..a812f232b 100644 --- a/.github/workflows/halo.yaml +++ b/.github/workflows/halo.yaml @@ -31,6 +31,8 @@ jobs: run: make -C console check - name: Check Halo core run: ./gradlew check + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 - name: Analyze code if: ${{ github.event_name == 'push' && env.SONAR_TOKEN != '' }} # Due to inability to access secrets during PR, only the code pushed into the branch can be analyzed. env: