mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
This commit is contained in:
parent
b5b46afabd
commit
f742e664c7
4 changed files with 30 additions and 40 deletions
|
|
@ -312,6 +312,24 @@ export class Wnd {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const initData = currentTab.headElement.getAttribute("data-initdata")
|
||||||
|
if (initData) {
|
||||||
|
const json = JSON.parse(initData);
|
||||||
|
currentTab.addModel(new Editor({
|
||||||
|
tab: currentTab,
|
||||||
|
blockId: json.blockId,
|
||||||
|
mode: json.mode,
|
||||||
|
action: [json.action],
|
||||||
|
scrollAttr: json.scrollAttr,
|
||||||
|
}));
|
||||||
|
currentTab.headElement.removeAttribute("data-initdata");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentTab && target === currentTab.headElement && currentTab.model instanceof Graph) {
|
||||||
|
currentTab.model.onGraph(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (currentTab && currentTab.model instanceof Editor) {
|
if (currentTab && currentTab.model instanceof Editor) {
|
||||||
const keepCursorId = currentTab.headElement.getAttribute("keep-cursor");
|
const keepCursorId = currentTab.headElement.getAttribute("keep-cursor");
|
||||||
if (keepCursorId) {
|
if (keepCursorId) {
|
||||||
|
|
@ -343,29 +361,9 @@ export class Wnd {
|
||||||
if (update) {
|
if (update) {
|
||||||
updatePanelByEditor(currentTab.model.editor.protyle, true, pushBack);
|
updatePanelByEditor(currentTab.model.editor.protyle, true, pushBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切换到屏幕太高的页签 https://github.com/siyuan-note/siyuan/issues/5018
|
|
||||||
const protyle = currentTab.model.editor.protyle;
|
|
||||||
if (!protyle.scroll.element.classList.contains("fn__none") &&
|
|
||||||
protyle.wysiwyg.element.lastElementChild.getAttribute("data-eof") !== "true" &&
|
|
||||||
protyle.contentElement.scrollHeight > 0 &&
|
|
||||||
protyle.contentElement.scrollHeight <= protyle.contentElement.clientHeight) {
|
|
||||||
fetchPost("/api/filetree/getDoc", {
|
|
||||||
id: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
|
|
||||||
mode: 2,
|
|
||||||
k: protyle.options.key || "",
|
|
||||||
size: Constants.SIZE_GET,
|
|
||||||
}, getResponse => {
|
|
||||||
onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
updatePanelByEditor(undefined, false);
|
updatePanelByEditor(undefined, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentTab && target === currentTab.headElement && currentTab.model instanceof Graph) {
|
|
||||||
currentTab.model.onGraph(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTab(tab: Tab, keepCursor = false) {
|
public addTab(tab: Tab, keepCursor = false) {
|
||||||
|
|
|
||||||
|
|
@ -207,13 +207,7 @@ const JSONToCenter = (json: any, layout?: Layout | Wnd | Tab | Model) => {
|
||||||
}
|
}
|
||||||
(layout as Wnd).addTab(child);
|
(layout as Wnd).addTab(child);
|
||||||
} else if (json.instance === "Editor" && json.blockId) {
|
} else if (json.instance === "Editor" && json.blockId) {
|
||||||
(layout as Tab).addModel(new Editor({
|
(layout as Tab).headElement.setAttribute("data-initdata", JSON.stringify(json));
|
||||||
tab: (layout as Tab),
|
|
||||||
blockId: json.blockId,
|
|
||||||
mode: json.mode,
|
|
||||||
action: [json.action],
|
|
||||||
scrollAttr: json.scrollAttr,
|
|
||||||
}));
|
|
||||||
} else if (json.instance === "Asset") {
|
} else if (json.instance === "Asset") {
|
||||||
(layout as Tab).addModel(new Asset({
|
(layout as Tab).addModel(new Asset({
|
||||||
tab: (layout as Tab),
|
tab: (layout as Tab),
|
||||||
|
|
@ -308,15 +302,6 @@ export const JSONToLayout = (isStart: boolean) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
getAllModels().editor.find(item => {
|
|
||||||
if (item.headElement.classList.contains("item--focus")) {
|
|
||||||
updatePanelByEditor(item.editor.protyle, false, false);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 520);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
|
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {fetchPost} from "../../util/fetch";
|
||||||
import {onGet} from "../util/onGet";
|
import {onGet} from "../util/onGet";
|
||||||
import {showMessage} from "../../dialog/message";
|
import {showMessage} from "../../dialog/message";
|
||||||
import {updateHotkeyTip} from "../util/compatibility";
|
import {updateHotkeyTip} from "../util/compatibility";
|
||||||
|
import {isMobile} from "../../util/functions";
|
||||||
|
|
||||||
export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
|
export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
|
||||||
let elementRect = element.getBoundingClientRect();
|
let elementRect = element.getBoundingClientRect();
|
||||||
|
|
@ -21,8 +22,12 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
|
||||||
protyle.toolbar.element.style.top = top + "px";
|
protyle.toolbar.element.style.top = top + "px";
|
||||||
protyle.toolbar.element.style.display = "";
|
protyle.toolbar.element.style.display = "";
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!protyle.element.classList.contains("block__edit") && !isMobile()) {
|
||||||
|
protyle.contentElement.setAttribute("data-scrolltop", element.scrollTop.toString());
|
||||||
|
}
|
||||||
|
|
||||||
if (!window.siyuan.dragElement) { // https://ld246.com/article/1649638389841
|
if (!window.siyuan.dragElement) { // https://ld246.com/article/1649638389841
|
||||||
hideElements(["gutter"], protyle);
|
hideElements(["gutter"], protyle);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,15 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
||||||
const attr: IScrollAttr = {
|
const attr: IScrollAttr = {
|
||||||
startId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"),
|
startId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"),
|
||||||
endId: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
|
endId: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
|
||||||
scrollTop: protyle.contentElement.scrollTop
|
scrollTop: protyle.contentElement.scrollTop || parseInt(protyle.contentElement.getAttribute("data-scrolltop")) || 0,
|
||||||
}
|
}
|
||||||
let range: Range
|
let range: Range
|
||||||
if (getSelection().rangeCount > 0) {
|
if (getSelection().rangeCount > 0) {
|
||||||
range = getSelection().getRangeAt(0)
|
range = getSelection().getRangeAt(0)
|
||||||
}
|
}
|
||||||
|
if (!range || !protyle.wysiwyg.element.contains(range.startContainer)) {
|
||||||
|
range = protyle.toolbar.range
|
||||||
|
}
|
||||||
if (range && protyle.wysiwyg.element.contains(range.startContainer)) {
|
if (range && protyle.wysiwyg.element.contains(range.startContainer)) {
|
||||||
const blockElement = hasClosestBlock(range.startContainer);
|
const blockElement = hasClosestBlock(range.startContainer);
|
||||||
if (blockElement) {
|
if (blockElement) {
|
||||||
|
|
@ -23,9 +25,9 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
||||||
attr.focusId = blockElement.getAttribute("data-node-id");
|
attr.focusId = blockElement.getAttribute("data-node-id");
|
||||||
attr.focusStart = position.start
|
attr.focusStart = position.start
|
||||||
attr.focusEnd = position.end
|
attr.focusEnd = position.end
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protyle.block.showAll) {
|
if (protyle.block.showAll) {
|
||||||
attr.zoomInId = protyle.block.id
|
attr.zoomInId = protyle.block.id
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue