mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
🐛 back to the zoom in block
This commit is contained in:
parent
9383c943b3
commit
a974bbdece
5 changed files with 46 additions and 49 deletions
|
|
@ -53,8 +53,8 @@ const focusStack = async (stack: IBackStack) => {
|
|||
const editor = new Editor({
|
||||
tab,
|
||||
scrollAttr,
|
||||
blockId: stack.isZoom ? stack.id : stack.protyle.block.rootID,
|
||||
action: stack.isZoom ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS]
|
||||
blockId: stack.zoomId || stack.protyle.block.rootID,
|
||||
action: stack.zoomId ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS]
|
||||
});
|
||||
tab.addModel(editor);
|
||||
}
|
||||
|
|
@ -110,6 +110,8 @@ const focusStack = async (stack: IBackStack) => {
|
|||
if (stack.protyle.title.editElement.getBoundingClientRect().height === 0) {
|
||||
// 切换 tab
|
||||
stack.protyle.model.parent.parent.switchTab(stack.protyle.model.parent.headElement);
|
||||
// 需要更新 range,否则 resize 中 `保持光标位置不变` 会导致光标跳动
|
||||
stack.protyle.toolbar.range = undefined;
|
||||
}
|
||||
focusByOffset(stack.protyle.title.editElement, stack.position.start, stack.position.end);
|
||||
return true;
|
||||
|
|
@ -125,34 +127,15 @@ const focusStack = async (stack: IBackStack) => {
|
|||
// 切换 tab
|
||||
stack.protyle.model.parent.parent.switchTab(stack.protyle.model.parent.headElement);
|
||||
}
|
||||
if (stack.isZoom) {
|
||||
zoomOut(stack.protyle, stack.id, undefined, false);
|
||||
return true;
|
||||
}
|
||||
if (blockElement && !stack.protyle.block.showAll) {
|
||||
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
|
||||
scrollCenter(stack.protyle, blockElement, true);
|
||||
return true;
|
||||
}
|
||||
// 缩放不一致
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: stack.id,
|
||||
mode: stack.isZoom ? 0 : 3,
|
||||
size: stack.isZoom ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, stack.protyle, [Constants.CB_GET_HTML]);
|
||||
Array.from(stack.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find(item => {
|
||||
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
|
||||
blockElement = item;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
|
||||
setTimeout(() => {
|
||||
// 图片、视频等加载完成后再定位
|
||||
if (stack.zoomId && stack.zoomId !== stack.protyle.block.id) {
|
||||
zoomOut(stack.protyle, stack.zoomId, undefined, false, () => {
|
||||
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
|
||||
scrollCenter(stack.protyle, blockElement, true);
|
||||
}, Constants.TIMEOUT_LOAD);
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
|
||||
scrollCenter(stack.protyle, blockElement, true);
|
||||
return true;
|
||||
}
|
||||
if (stack.protyle.element.parentElement) {
|
||||
|
|
@ -165,11 +148,11 @@ const focusStack = async (stack: IBackStack) => {
|
|||
return false;
|
||||
}
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: stack.id,
|
||||
mode: stack.isZoom ? 0 : 3,
|
||||
size: stack.isZoom ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
|
||||
id: stack.zoomId ? stack.zoomId : stack.id,
|
||||
mode: stack.zoomId ? 0 : 3,
|
||||
size: stack.zoomId ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, stack.protyle, stack.isZoom ? [Constants.CB_GET_HTML, Constants.CB_GET_ALL] : [Constants.CB_GET_HTML]);
|
||||
onGet(getResponse, stack.protyle, stack.zoomId ? [Constants.CB_GET_HTML, Constants.CB_GET_ALL] : [Constants.CB_GET_HTML]);
|
||||
Array.from(stack.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find(item => {
|
||||
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
|
||||
blockElement = item;
|
||||
|
|
@ -262,8 +245,9 @@ export const pushBack = (protyle: IProtyle, range?: Range, blockElement?: Elemen
|
|||
const position = getSelectionOffset(editElement, undefined, range);
|
||||
const id = blockElement.getAttribute("data-node-id") || protyle.block.rootID;
|
||||
const lastStack = window.siyuan.backStack[window.siyuan.backStack.length - 1];
|
||||
const isZoom = protyle.block.showAll;
|
||||
if (lastStack && lastStack.id === id && lastStack.isZoom === isZoom) {
|
||||
if (lastStack && lastStack.id === id && (
|
||||
(protyle.block.showAll && lastStack.zoomId === protyle.block.id) || (!lastStack.zoomId && !protyle.block.showAll)
|
||||
)) {
|
||||
lastStack.position = position;
|
||||
} else {
|
||||
if (forwardStack.length > 0) {
|
||||
|
|
@ -277,7 +261,7 @@ export const pushBack = (protyle: IProtyle, range?: Range, blockElement?: Elemen
|
|||
position,
|
||||
id,
|
||||
protyle,
|
||||
isZoom
|
||||
zoomId: protyle.block.showAll ? protyle.block.id : undefined,
|
||||
});
|
||||
if (window.siyuan.backStack.length > Constants.SIZE_UNDO) {
|
||||
window.siyuan.backStack.shift();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue