mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 16:58:49 +01:00
This commit is contained in:
parent
c8834231af
commit
0e07612940
2 changed files with 21 additions and 18 deletions
|
|
@ -3,8 +3,7 @@ import {hasClosestBlock, hasClosestByMatchTag} from "../../protyle/util/hasClose
|
|||
import {insertEmptyBlock} from "../../block/util";
|
||||
import {moveToDown, moveToUp} from "../../protyle/wysiwyg/move";
|
||||
import {Constants} from "../../constants";
|
||||
import {focusByRange} from "../../protyle/util/selection";
|
||||
import {scrollCenter} from "../../util/highlightById";
|
||||
import {focusByRange, getSelectionPosition} from "../../protyle/util/selection";
|
||||
|
||||
export const showKeyboardToolbar = (bottom = 0) => {
|
||||
if (getSelection().rangeCount > 0) {
|
||||
|
|
@ -22,14 +21,26 @@ export const showKeyboardToolbar = (bottom = 0) => {
|
|||
}
|
||||
toolbarElement.classList.remove("fn__none");
|
||||
toolbarElement.style.bottom = bottom + "px";
|
||||
if ("android" === window.siyuan.config.system.container && window.JSAndroid) {
|
||||
// Android 端事件需要滞后一些,所以这里延迟一下
|
||||
setTimeout(() => {
|
||||
scrollCenter(window.siyuan.mobileEditor.protyle, undefined, false, (window.outerHeight - 65) / 2 - 30);
|
||||
}, 100);
|
||||
} else {
|
||||
scrollCenter(window.siyuan.mobileEditor.protyle, undefined, false, (window.outerHeight - 65) / 2 - 30);
|
||||
|
||||
const contentElement = window.siyuan.mobileEditor.protyle.contentElement
|
||||
const cursorTop = getSelectionPosition(contentElement).top - contentElement.getBoundingClientRect().top;
|
||||
if (cursorTop < window.innerHeight - 96) {
|
||||
return;
|
||||
}
|
||||
contentElement.scroll({
|
||||
top: contentElement.scrollTop + cursorTop - ((window.outerHeight - 65) / 2 - 30),
|
||||
left: contentElement.scrollLeft,
|
||||
behavior: "smooth"
|
||||
});
|
||||
alert(cursorTop + "," + window.innerHeight);
|
||||
// if ("android" === window.siyuan.config.system.container && window.JSAndroid) {
|
||||
// // Android 端事件需要滞后一些,所以这里延迟一下
|
||||
// setTimeout(() => {
|
||||
// scrollCenter(window.siyuan.mobileEditor.protyle, undefined, false, (window.outerHeight - 65) / 2 - 30);
|
||||
// }, 100);
|
||||
// } else {
|
||||
// scrollCenter(window.siyuan.mobileEditor.protyle, undefined, false, (window.outerHeight - 65) / 2 - 30);
|
||||
// }
|
||||
};
|
||||
|
||||
export const hideKeyboardToolbar = () => {
|
||||
|
|
|
|||
|
|
@ -38,18 +38,10 @@ export const highlightById = (protyle: IProtyle, id: string, top = false) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = false, offset = 0) => {
|
||||
export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = false) => {
|
||||
if (!top && getSelection().rangeCount > 0 && hasClosestBlock(getSelection().getRangeAt(0).startContainer)) {
|
||||
const editorElement = protyle.contentElement;
|
||||
const cursorTop = getSelectionPosition(editorElement).top - editorElement.getBoundingClientRect().top;
|
||||
if (offset) { // 仅移动端弹起键盘用到
|
||||
editorElement.scroll({
|
||||
top: editorElement.scrollTop + cursorTop - offset,
|
||||
left: editorElement.scrollLeft,
|
||||
behavior: "smooth"
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (cursorTop < 0) {
|
||||
editorElement.scrollTop = editorElement.scrollTop + cursorTop;
|
||||
} else if (cursorTop > editorElement.clientHeight - 34) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue