Skip to content

Commit

Permalink
Fix PickPlugin will not remove nodes with other tags other than <a> t…
Browse files Browse the repository at this point in the history
…ag (#2116)
  • Loading branch information
Leah-Xia-Microsoft authored Sep 29, 2023
1 parent 3e3429a commit 1d70f8a
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,11 @@ export default class PickerPlugin<T extends PickerDataProvider = PickerDataProvi
} else if (keyboardEvent.key == DELETE_CHAR_CODE) {
let searcher = this.editor?.getContentSearcherOfCursor(event);
if (searcher) {
let nodeAfterCursor = searcher.getInlineElementAfter()
? searcher.getInlineElementAfter()?.getContainerNode()
const inlineElementAfter = searcher.getInlineElementAfter();
let nodeAfterCursor = inlineElementAfter
? inlineElementAfter.getContainerNode()
: null;
nodeAfterCursor = this.getParentNodeIfTextNode(nodeAfterCursor);
let nodeId = nodeAfterCursor ? this.getIdValue(nodeAfterCursor) : null;
if (
nodeId &&
Expand All @@ -483,6 +485,13 @@ export default class PickerPlugin<T extends PickerDataProvider = PickerDataProvi
}
}

private getParentNodeIfTextNode(node: Node | null): Node | null {
if (safeInstanceOf(node, 'Text')) {
node = node.parentNode;
}
return node;
}

private onAndroidInputEvent(event: PluginInputEvent) {
this.newInputLength = this.calcInputLength(event);

Expand All @@ -506,16 +515,14 @@ export default class PickerPlugin<T extends PickerDataProvider = PickerDataProvi
if (!this.editor) {
return false;
}

const searcher = this.editor.getContentSearcherOfCursor(event);
if (!searcher) {
return false;
}

const inlineElementBefore = searcher.getInlineElementBefore();
const nodeBeforeCursor = inlineElementBefore
? inlineElementBefore.getContainerNode()
: null;
let nodeBeforeCursor = inlineElementBefore ? inlineElementBefore.getContainerNode() : null;
nodeBeforeCursor = this.getParentNodeIfTextNode(nodeBeforeCursor);
const nodeId = nodeBeforeCursor ? this.getIdValue(nodeBeforeCursor) : null;
const inlineElementAfter = searcher.getInlineElementAfter();

Expand Down Expand Up @@ -606,3 +613,4 @@ export default class PickerPlugin<T extends PickerDataProvider = PickerDataProvi
);
}
}

0 comments on commit 1d70f8a

Please sign in to comment.