@flozy/editor 3.3.3 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,6 +7,7 @@ import { ReactEditor, useSlate } from "slate-react";
|
|
|
7
7
|
import { Node, Path, Transforms } from "slate";
|
|
8
8
|
import useWindowResize from "../../hooks/useWindowResize";
|
|
9
9
|
import { MODES } from "./helper";
|
|
10
|
+
import { getSelectedText } from "../../utils/helper";
|
|
10
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
12
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
13
|
const scrollToAIInput = () => {
|
|
@@ -33,13 +34,20 @@ const updateAnchorEl = (setAnchorEl, editor) => {
|
|
|
33
34
|
if (!editor.selection) {
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
|
-
const focussedNode = Node.get(editor, editor.selection.anchor.path);
|
|
37
|
-
const focussedDom = ReactEditor.toDOMNode(editor, focussedNode);
|
|
38
37
|
const selection = window.getSelection();
|
|
39
38
|
if (selection.rangeCount) {
|
|
39
|
+
let caret;
|
|
40
|
+
if (getSelectedText(editor)) {
|
|
41
|
+
// selected text as caret
|
|
42
|
+
caret = selection.getRangeAt(0);
|
|
43
|
+
} else {
|
|
44
|
+
const focussedNode = Node.get(editor, editor?.selection?.anchor?.path);
|
|
45
|
+
// foccussed DOM as caret
|
|
46
|
+
caret = ReactEditor.toDOMNode(editor, focussedNode);
|
|
47
|
+
}
|
|
40
48
|
const getBoundingClientRect = () => {
|
|
41
49
|
const editorEle = document.querySelector(".ed-section-inner").getBoundingClientRect();
|
|
42
|
-
const caretPos =
|
|
50
|
+
const caretPos = caret.getBoundingClientRect();
|
|
43
51
|
return {
|
|
44
52
|
y: caretPos.y,
|
|
45
53
|
height: caretPos.height,
|