Skip to content

Commit

Permalink
fix: deleting selected text in a list with the backspace key causes t…
Browse files Browse the repository at this point in the history
…he list to revert (halo-dev#5938)

#### What type of PR is this?

/kind bug
/area editor
/milestone 2.16.x

#### What this PR does / why we need it:

移除使用 `Backspace` 进行缩进的功能。此功能会导致选中无序列表文本至起始位置时,按 `Backspace` 快捷键会导致无序列表解除当前层级。

#### How to test it?

测试从后往前选中无序列表文本至文本起始位置,然后按下 `Backspace` 快捷键。此时应当只删除文本而不会调整无序列表层级。

#### Which issue(s) this PR fixes:

Fixes halo-dev#5925 

#### Does this PR introduce a user-facing change?
```release-note
修复默认编辑器中列表使用 Backspace 快捷键删除选中文本的错误行为
```
  • Loading branch information
LIlGG authored May 22, 2024
1 parent b762a9d commit d29da31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions ui/packages/editor/src/extensions/indent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
type KeyboardShortcutCommand,
Extension,
isList,
Editor,
} from "@/tiptap/vue-3";
CoreEditor,
} from "@/tiptap";
import { TextSelection, Transaction } from "@/tiptap/pm";

declare module "@/tiptap" {
Expand Down Expand Up @@ -104,7 +104,6 @@ const Indent = Extension.create<IndentOptions, never>({
return {
Tab: getIndent(),
"Shift-Tab": getOutdent(false),
Backspace: getOutdent(true),
"Mod-]": getIndent(),
"Mod-[": getOutdent(false),
};
Expand Down Expand Up @@ -196,15 +195,15 @@ const isTextIndent = (tr: Transaction, currNodePos: number) => {
return false;
};

const isListActive = (editor: Editor) => {
const isListActive = (editor: CoreEditor) => {
return (
editor.isActive("bulletList") ||
editor.isActive("orderedList") ||
editor.isActive("taskList")
);
};

const isFilterActive = (editor: Editor) => {
const isFilterActive = (editor: CoreEditor) => {
return editor.isActive("table") || editor.isActive("columns");
};

Expand Down Expand Up @@ -232,11 +231,11 @@ export const getOutdent: (
if (outdentOnlyAtHead && editor.state.selection.$head.parentOffset > 0) {
return false;
}
// @ts-ignore

if (isFilterActive(editor)) {
return false;
}
// @ts-ignore

if (isListActive(editor)) {
const name = editor.can().liftListItem("listItem")
? "listItem"
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/editor/src/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
}

ul {
@apply list-disc;
list-style-type: revert-layer;
}

code br {
Expand Down

0 comments on commit d29da31

Please sign in to comment.