From 2516d1ff0a5952b4ecc97afac097fd49cd1ad060 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 16 Nov 2022 21:27:51 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/6613 --- app/src/protyle/wysiwyg/keydown.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index f715c6ef4..71ce52a4a 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -57,6 +57,7 @@ import {countBlockWord} from "../../layout/status"; import {openMobileFileById} from "../../mobile/editor"; import {moveToDown, moveToUp} from "./move"; import {pasteAsPlainText} from "../util/paste"; +import {preventScroll} from "../scroll/preventScroll"; export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => { @@ -359,6 +360,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { const previousElement = getPreviousBlock(startEndElement.endElement); if (previousElement) { previousElement.setAttribute("select-end", "true"); + if (previousElement.getBoundingClientRect().top <= protyle.contentElement.getBoundingClientRect().top) { + preventScroll(protyle) + previousElement.scrollIntoView(true) + } } } } @@ -392,6 +397,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { const nextElement = getNextBlock(startEndElement.endElement); if (nextElement) { nextElement.setAttribute("select-end", "true"); + if (nextElement.getBoundingClientRect().bottom >= protyle.contentElement.getBoundingClientRect().bottom) { + preventScroll(protyle) + nextElement.scrollIntoView(false) + } } } }