-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: list items require multiple backspace presses to delete (#6408)
#### What type of PR is this? /kind bug /area editor /milestone 2.18.x #### What this PR does / why we need it: 目前当编辑器中列表内容为空时,需要按退格键多次才能删除掉此列表内容。 本 PR 在执行单行删除逻辑之前,会检查列表是否处于活动状态,如果是则不再执行单行删除的逻辑。列表会执行 ListKeyMap 相关快捷键。 #### How to test it? 1. 在默认富文本键入一个列表。 2. 使用退格键删除这个列表。 3. 查看是否可以一次就删除。 #### Which issue(s) this PR fixes: Fixes #6389 #### Does this PR introduce a user-facing change? ```release-note 修复默认编辑器中列表项需要按多次退格键才可以删除的问题 ```
- Loading branch information
Showing
3 changed files
with
51 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
callOrReturn, | ||
CoreEditor, | ||
getExtensionField, | ||
isActive, | ||
type NodeConfig, | ||
} from "@/tiptap"; | ||
|
||
/** | ||
* Check if a list is active | ||
* | ||
* @param state - The state of the editor | ||
* @returns Whether a list is active | ||
* @example | ||
* ```ts | ||
* const isActive = isListActive(editor.state); | ||
* ``` | ||
**/ | ||
export const isListActive = (editor: CoreEditor) => { | ||
const extensions = editor.extensionManager.extensions; | ||
const listExtensions = extensions.filter((extension) => { | ||
const context = { | ||
name: extension.name, | ||
options: extension.options, | ||
storage: extension.storage, | ||
}; | ||
|
||
const group = callOrReturn( | ||
getExtensionField<NodeConfig["group"]>(extension, "group", context) | ||
); | ||
|
||
if (typeof group !== "string") { | ||
return false; | ||
} | ||
|
||
return group.split(" ").includes("list"); | ||
}); | ||
|
||
return listExtensions.some((extension) => { | ||
return isActive(editor.state, extension.name); | ||
}); | ||
}; |