mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
This commit is contained in:
parent
4019ec3def
commit
bd6cf65266
2 changed files with 23 additions and 11 deletions
|
|
@ -542,11 +542,12 @@ export const initKeyboardToolbar = () => {
|
|||
const slashBtnElement = hasClosestByClassName(event.target as HTMLElement, "keyboard__slash-item");
|
||||
if (slashBtnElement && !slashBtnElement.getAttribute("data-type")) {
|
||||
const dataValue = decodeURIComponent(slashBtnElement.getAttribute("data-value"));
|
||||
protyle.hint.fill(dataValue, protyle, false); // 点击后 range 会改变
|
||||
if (dataValue !== Constants.ZWSP + 3) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (dataValue === Constants.ZWSP + 3) {
|
||||
return;
|
||||
}
|
||||
protyle.hint.fill(dataValue, protyle, false); // 点击后 range 会改变
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (slashBtnElement.getAttribute("data-focus") === "true") {
|
||||
focusByRange(protyle.toolbar.range);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import {
|
|||
hasPreviousSibling,
|
||||
isNotEditBlock
|
||||
} from "../wysiwyg/getBlock";
|
||||
import {hasClosestByAttribute, hasClosestByTag} from "./hasClosest";
|
||||
import {hasClosestBlock, hasClosestByAttribute, hasClosestByTag} from "./hasClosest";
|
||||
import {countBlockWord, countSelectWord} from "../../layout/status";
|
||||
import {hideElements} from "../ui/hideElements";
|
||||
import {genRenderFrame} from "../render/util";
|
||||
|
|
@ -140,12 +140,23 @@ export const getEditorRange = (element: Element): Range => {
|
|||
if (getSelection().rangeCount > 0) {
|
||||
range = getSelection().getRangeAt(0);
|
||||
if (element === range.startContainer || element.contains(range.startContainer)) {
|
||||
// 有时候点击编辑器头部需要矫正到第一个块中
|
||||
if (range.toString() === "" && range.startContainer.nodeType === 1 && range.startOffset === 0 &&
|
||||
(range.startContainer as HTMLElement).classList.contains("protyle-wysiwyg")) {
|
||||
const focusRange = focusBlock(range.startContainer.firstChild as Element);
|
||||
if (focusRange) {
|
||||
return focusRange;
|
||||
if (range.toString() === "" && range.startContainer.nodeType === 1) {
|
||||
// 有时候点击编辑器头部需要矫正到第一个块中
|
||||
if (range.startOffset === 0 && (range.startContainer as HTMLElement).classList.contains("protyle-wysiwyg")) {
|
||||
const focusRange = focusBlock(range.startContainer.firstChild as Element);
|
||||
if (focusRange) {
|
||||
return focusRange;
|
||||
}
|
||||
}
|
||||
// 移动端获取有偏差 https://github.com/siyuan-note/siyuan/issues/15998
|
||||
if (getContenteditableElement(range.startContainer as Element)) {
|
||||
const blockElement = hasClosestBlock(range.startContainer);
|
||||
if (blockElement) {
|
||||
const focusRange = focusBlock(blockElement);
|
||||
if (focusRange) {
|
||||
return focusRange;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return range;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue