mirror of
https://github.com/labring/FastGPT.git
synced 2026-04-26 02:07:28 +08:00
V4.14.9 features (#6602)
* fix: image read and json error (Agent) (#6502) * fix: 1.image read 2.JSON parsing error * dataset cite and pause * perf: plancall second parse * add test --------- Co-authored-by: archer <545436317@qq.com> * master message * remove invalid code * fix: sandbox download file * update lock * sub set * i18n * perf: system forbid sandbox * fix: i18n; next config * fix: authchat uid * update i18n * perf: check exists * stop in tool * stop in tool * fix: chat * update action * doc * deploy doc --------- Co-authored-by: YeYuheng <57035043+YYH211@users.noreply.github.com>
This commit is contained in:
+41
-33
@@ -64,52 +64,60 @@ export default function ListExitPlugin(): JSX.Element | null {
|
||||
};
|
||||
|
||||
const handleBackspaceKey = (event: KeyboardEvent) => {
|
||||
const selection = $getSelection();
|
||||
if (!$isRangeSelection(selection)) {
|
||||
let shouldHandle = false;
|
||||
|
||||
editor.getEditorState().read(() => {
|
||||
const selection = $getSelection();
|
||||
if (!$isRangeSelection(selection)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const anchorNode = selection.anchor.getNode();
|
||||
const listItemNode = $isListItemNode(anchorNode) ? anchorNode : anchorNode.getParent();
|
||||
|
||||
if ($isListItemNode(listItemNode)) {
|
||||
const textContent = listItemNode.getTextContent().trim();
|
||||
const cursorOffset = selection.anchor.offset;
|
||||
|
||||
if (textContent === '' && cursorOffset === 0) {
|
||||
shouldHandle = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!shouldHandle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const anchorNode = selection.anchor.getNode();
|
||||
const listItemNode = $isListItemNode(anchorNode) ? anchorNode : anchorNode.getParent();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if ($isListItemNode(listItemNode)) {
|
||||
// Check if cursor is at the beginning of an empty list item
|
||||
const textContent = listItemNode.getTextContent().trim();
|
||||
const cursorOffset = selection.anchor.offset;
|
||||
editor.update(() => {
|
||||
const selection = $getSelection();
|
||||
if (!$isRangeSelection(selection)) return;
|
||||
|
||||
// Only handle empty list items with cursor at the beginning
|
||||
if (textContent === '' && cursorOffset === 0) {
|
||||
// Prevent default backspace behavior
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const anchorNode = selection.anchor.getNode();
|
||||
const listItemNode = $isListItemNode(anchorNode) ? anchorNode : anchorNode.getParent();
|
||||
|
||||
editor.update(() => {
|
||||
const listNode = listItemNode.getParent();
|
||||
if (!$isListItemNode(listItemNode)) return;
|
||||
|
||||
if ($isListNode(listNode)) {
|
||||
// Create a new paragraph
|
||||
const paragraph = $createParagraphNode();
|
||||
const listNode = listItemNode.getParent();
|
||||
|
||||
// Always insert after the current list item and remove it
|
||||
// This ensures the paragraph appears at the current position
|
||||
listItemNode.insertAfter(paragraph);
|
||||
listItemNode.remove();
|
||||
if ($isListNode(listNode)) {
|
||||
const paragraph = $createParagraphNode();
|
||||
|
||||
// If the list is now empty, remove it
|
||||
if (listNode.getChildrenSize() === 0) {
|
||||
listNode.remove();
|
||||
}
|
||||
listItemNode.insertAfter(paragraph);
|
||||
listItemNode.remove();
|
||||
|
||||
// Focus the new paragraph
|
||||
paragraph.select();
|
||||
}
|
||||
});
|
||||
if (listNode.getChildrenSize() === 0) {
|
||||
listNode.remove();
|
||||
}
|
||||
|
||||
return true;
|
||||
paragraph.select();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
// Register the keyboard event handlers
|
||||
|
||||
Reference in New Issue
Block a user