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: 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..3ad90ea66 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,7 @@ import { markRaw } from "vue"; import { i18n } from "@/locales"; import type { ExtensionOptions, NodeBubbleMenu } from "@/types"; import { BlockActionSeparator, ToolboxItem } from "@/components"; +import { hasTableBefore, isTableSelected } from "./util"; function updateColumns( node: ProseMirrorNode, @@ -375,6 +381,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; +};