Skip to content

Commit

Permalink
Merge branch 'main' into feat/mfa
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing authored Jan 15, 2024
2 parents 7946585 + 9615528 commit daf4334
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/halo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions console/packages/editor/src/extensions/list-keymap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const ExtensionListKeymap = ListKeymap.extend<ListKeymapOptions>({
let handled = false;

if (!editor.state.selection.empty) {
editor.commands.deleteSelection();
return true;
return false;
}

this.options.listTypes.forEach(
Expand Down
46 changes: 45 additions & 1 deletion console/packages/editor/src/extensions/table/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -375,6 +381,44 @@ const Table = TiptapTable.extend<ExtensionOptions & TableOptions>({
},
};
},

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;
16 changes: 15 additions & 1 deletion console/packages/editor/src/extensions/table/util.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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;
};

0 comments on commit daf4334

Please sign in to comment.