This commit is contained in:
Vanessa 2023-05-07 23:38:03 +08:00
parent 1b2a6b8d69
commit 0df92e59fa
2 changed files with 15 additions and 4 deletions

View file

@ -125,6 +125,17 @@ export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range)
countBlockWord(ids, protyle.block.rootID);
};
// https://github.com/siyuan-note/siyuan/issues/8196
export const getRangeByPoint = (x: number, y: number) => {
const range = document.caretRangeFromPoint(x, y);
const imgElement = hasClosestByAttribute(range.startContainer, "data-type", "img")
if (imgElement) {
range.setStart(imgElement.nextSibling, 0);
range.collapse();
}
return range;
}
export const getEditorRange = (element: Element) => {
let range: Range;
if (getSelection().rangeCount > 0) {