Lexical: Changed table esacpe handling
Avoids misuse of selectPrevious/Next as per prior commit which was then causing problems elsewhere, and is probably best to avoid creation in those select methods anyway.
This commit is contained in:
parent
a43a1832f5
commit
2e718c12e1
|
@ -48,7 +48,6 @@ import {
|
|||
internalMarkNodeAsDirty,
|
||||
removeFromParent,
|
||||
} from './LexicalUtils';
|
||||
import {$insertAndSelectNewEmptyAdjacentNode} from "../../utils/nodes";
|
||||
|
||||
export type NodeMap = Map<NodeKey, LexicalNode>;
|
||||
|
||||
|
@ -1131,7 +1130,7 @@ export class LexicalNode {
|
|||
const prevSibling = this.getPreviousSibling();
|
||||
const parent = this.getParentOrThrow();
|
||||
if (prevSibling === null) {
|
||||
return $insertAndSelectNewEmptyAdjacentNode(this, false);
|
||||
return parent.select(0, 0);
|
||||
}
|
||||
if ($isElementNode(prevSibling)) {
|
||||
return prevSibling.select();
|
||||
|
@ -1153,7 +1152,7 @@ export class LexicalNode {
|
|||
const nextSibling = this.getNextSibling();
|
||||
const parent = this.getParentOrThrow();
|
||||
if (nextSibling === null) {
|
||||
return $insertAndSelectNewEmptyAdjacentNode(this, true);
|
||||
return parent.select();
|
||||
}
|
||||
if ($isElementNode(nextSibling)) {
|
||||
return nextSibling.select(0, 0);
|
||||
|
|
|
@ -71,6 +71,7 @@ import {TableDOMTable, TableObserver} from './LexicalTableObserver';
|
|||
import {$isTableRowNode} from './LexicalTableRowNode';
|
||||
import {$isTableSelection} from './LexicalTableSelection';
|
||||
import {$computeTableMap, $getNodeTriplet} from './LexicalTableUtils';
|
||||
import {$selectOrCreateAdjacent} from "../../utils/nodes";
|
||||
|
||||
const LEXICAL_ELEMENT_KEY = '__lexicalTableSelection';
|
||||
|
||||
|
@ -1113,7 +1114,7 @@ const selectTableNodeInDirection = (
|
|||
false,
|
||||
);
|
||||
} else {
|
||||
tableNode.selectPrevious();
|
||||
$selectOrCreateAdjacent(tableNode, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1125,7 +1126,7 @@ const selectTableNodeInDirection = (
|
|||
true,
|
||||
);
|
||||
} else {
|
||||
tableNode.selectNext();
|
||||
$selectOrCreateAdjacent(tableNode, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
import {$isImageNode} from "@lexical/rich-text/LexicalImageNode";
|
||||
import {$isMediaNode} from "@lexical/rich-text/LexicalMediaNode";
|
||||
import {getLastSelection} from "../utils/selection";
|
||||
import {$getNearestNodeBlockParent, $getParentOfType} from "../utils/nodes";
|
||||
import {$getNearestNodeBlockParent, $getParentOfType, $selectOrCreateAdjacent} from "../utils/nodes";
|
||||
import {$setInsetForSelection} from "../utils/lists";
|
||||
import {$isListItemNode} from "@lexical/list";
|
||||
import {$isDetailsNode, DetailsNode} from "@lexical/rich-text/LexicalDetailsNode";
|
||||
|
@ -81,13 +81,8 @@ function focusAdjacentOrInsertForSingleSelectNode(editor: LexicalEditor, event:
|
|||
|
||||
event?.preventDefault();
|
||||
const node = selectionNodes[0];
|
||||
|
||||
editor.update(() => {
|
||||
if (after) {
|
||||
node.selectNext();
|
||||
} else {
|
||||
node.selectPrevious();
|
||||
}
|
||||
$selectOrCreateAdjacent(node, after);
|
||||
});
|
||||
|
||||
return true;
|
||||
|
|
|
@ -118,15 +118,20 @@ export function $sortNodes(nodes: LexicalNode[]): LexicalNode[] {
|
|||
return sorted;
|
||||
}
|
||||
|
||||
export function $insertAndSelectNewEmptyAdjacentNode(node: LexicalNode, after: boolean): RangeSelection {
|
||||
const target = $createParagraphNode();
|
||||
if (after) {
|
||||
node.insertAfter(target)
|
||||
} else {
|
||||
node.insertBefore(target);
|
||||
export function $selectOrCreateAdjacent(node: LexicalNode, after: boolean): RangeSelection {
|
||||
const nearestBlock = $getNearestNodeBlockParent(node) || node;
|
||||
let target = after ? nearestBlock.getNextSibling() : nearestBlock.getPreviousSibling()
|
||||
|
||||
if (!target) {
|
||||
target = $createParagraphNode();
|
||||
if (after) {
|
||||
node.insertAfter(target)
|
||||
} else {
|
||||
node.insertBefore(target);
|
||||
}
|
||||
}
|
||||
|
||||
return target.select();
|
||||
return after ? target.selectStart() : target.selectEnd();
|
||||
}
|
||||
|
||||
export function nodeHasAlignment(node: object): node is NodeHasAlignment {
|
||||
|
|
Loading…
Reference in New Issue