mobile: fix cursor bug on ios

This commit is contained in:
Ammar Ahmed
2025-04-28 11:22:21 +05:00
committed by Ammar Ahmed
parent 8ab05c5a98
commit 37dc409b60
4 changed files with 12 additions and 33 deletions

View File

@@ -177,7 +177,7 @@ export const useEditorEvents = (
useEffect(() => {
const handleKeyboardDidShow: KeyboardEventListener = () => {
editor.commands.keyboardShown(true);
//editor.postMessage(NativeEvents.keyboardShown, undefined);
editor.postMessage(NativeEvents.keyboardShown, undefined);
};
const handleKeyboardDidHide: KeyboardEventListener = () => {
editor.commands.keyboardShown(false);

View File

@@ -43,7 +43,11 @@ export default function TiptapEditorWrapper(props: {
sx={{
display: props.settings.noToolbar ? "none" : "flex",
overflowY: "hidden",
minHeight: "50px"
minHeight: "50px",
position: "absolute",
bottom: 0,
left: 0,
right: 0
}}
editor={editor}
location="bottom"

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Editor, scrollIntoViewById } from "@notesnook/editor";
import { keepLastLineInView } from "@notesnook/editor/extensions/keep-in-view/keep-in-view.js";
import { strings } from "@notesnook/intl";
import {
ThemeDefinition,
@@ -66,38 +67,12 @@ type Timers = {
scroll: NodeJS.Timeout | null;
};
function isInViewport(element: any) {
const rect = element.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <=
(window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
function scrollIntoView(editor: Editor) {
if (__PLATFORM__ == "android") return;
setTimeout(() => {
try {
const node = editor?.state.selection.$from;
const dom = node ? editor?.view?.domAtPos?.(node.pos) : null;
let domNode = dom?.node;
if (domNode) {
if (domNode.nodeType === Node.TEXT_NODE && domNode.parentNode) {
domNode = domNode.parentNode;
}
if (isInViewport(domNode)) return;
(domNode as HTMLElement).scrollIntoView({
behavior: "smooth",
block: "end"
});
}
} catch (e) {
/* empty */
}
}, 100);
if (!editor.isFocused) return;
keepLastLineInView(editor);
}, 1);
}
export type EditorController = {

View File

@@ -71,7 +71,7 @@ export const KeepInView = Extension.create<
export function keepLastLineInView(
editor: Editor,
THRESHOLD = 80,
THRESHOLD = 90,
SCROLL_THRESHOLD = 100
) {
if (