mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 09:00:12 +01:00
🚨
This commit is contained in:
parent
b1ee790ee2
commit
a8072882fc
5 changed files with 24 additions and 16 deletions
|
|
@ -23,8 +23,6 @@ import {showMessage} from "../dialog/message";
|
||||||
import {openFileById, updatePanelByEditor} from "../editor/util";
|
import {openFileById, updatePanelByEditor} from "../editor/util";
|
||||||
import {scrollCenter} from "../util/highlightById";
|
import {scrollCenter} from "../util/highlightById";
|
||||||
import {getAllModels} from "./getAll";
|
import {getAllModels} from "./getAll";
|
||||||
import {fetchPost} from "../util/fetch";
|
|
||||||
import {onGet} from "../protyle/util/onGet";
|
|
||||||
import {countBlockWord} from "./status";
|
import {countBlockWord} from "./status";
|
||||||
import {saveScroll} from "../protyle/scroll/saveScroll";
|
import {saveScroll} from "../protyle/scroll/saveScroll";
|
||||||
|
|
||||||
|
|
@ -312,7 +310,7 @@ export class Wnd {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const initData = currentTab.headElement.getAttribute("data-initdata")
|
const initData = currentTab.headElement.getAttribute("data-initdata");
|
||||||
if (initData) {
|
if (initData) {
|
||||||
const json = JSON.parse(initData);
|
const json = JSON.parse(initData);
|
||||||
currentTab.addModel(new Editor({
|
currentTab.addModel(new Editor({
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import {hideElements} from "../protyle/ui/hideElements";
|
||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost} from "../util/fetch";
|
||||||
import {hasClosestBlock} from "../protyle/util/hasClosest";
|
import {hasClosestBlock} from "../protyle/util/hasClosest";
|
||||||
import {getContenteditableElement} from "../protyle/wysiwyg/getBlock";
|
import {getContenteditableElement} from "../protyle/wysiwyg/getBlock";
|
||||||
import {updatePanelByEditor} from "../editor/util";
|
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {openSearch} from "../search/spread";
|
import {openSearch} from "../search/spread";
|
||||||
import {saveScroll} from "../protyle/scroll/saveScroll";
|
import {saveScroll} from "../protyle/scroll/saveScroll";
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import {fetchPost} from "../../util/fetch";
|
||||||
import {openMobileFileById} from "../editor";
|
import {openMobileFileById} from "../editor";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
import {getEventName} from "../../protyle/util/compatibility";
|
import {getEventName} from "../../protyle/util/compatibility";
|
||||||
import {focusBlock} from "../../protyle/util/selection";
|
|
||||||
|
|
||||||
export class MobileOutline {
|
export class MobileOutline {
|
||||||
private tree: Tree;
|
private tree: Tree;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ import {getNoContainerElement} from "../wysiwyg/getBlock";
|
||||||
import {commonHotkey} from "../wysiwyg/commonHotkey";
|
import {commonHotkey} from "../wysiwyg/commonHotkey";
|
||||||
import {code160to32} from "../util/code160to32";
|
import {code160to32} from "../util/code160to32";
|
||||||
import {deleteFile} from "../../editor/deleteFile";
|
import {deleteFile} from "../../editor/deleteFile";
|
||||||
import {restoreScroll} from "../scroll/saveScroll";
|
|
||||||
|
|
||||||
export class Title {
|
export class Title {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
|
||||||
|
|
@ -4,32 +4,36 @@ import {fetchPost} from "../../util/fetch";
|
||||||
import {zoomOut} from "../../menus/protyle";
|
import {zoomOut} from "../../menus/protyle";
|
||||||
import {preventScroll} from "./preventScroll";
|
import {preventScroll} from "./preventScroll";
|
||||||
import {pushBack} from "../../util/backForward";
|
import {pushBack} from "../../util/backForward";
|
||||||
|
import {processRender} from "../util/processCode";
|
||||||
|
import {highlightRender} from "../markdown/highlightRender";
|
||||||
|
import {blockRender} from "../markdown/blockRender";
|
||||||
|
import {disabledProtyle, enableProtyle} from "../util/onGet";
|
||||||
|
|
||||||
export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
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 || parseInt(protyle.contentElement.getAttribute("data-scrolltop")) || 0,
|
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)) {
|
if (!range || !protyle.wysiwyg.element.contains(range.startContainer)) {
|
||||||
range = protyle.toolbar.range
|
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) {
|
||||||
const position = getSelectionOffset(blockElement, undefined, range);
|
const position = getSelectionOffset(blockElement, undefined, range);
|
||||||
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;
|
||||||
}
|
}
|
||||||
if (getObject) {
|
if (getObject) {
|
||||||
return attr;
|
return attr;
|
||||||
|
|
@ -38,7 +42,7 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
||||||
fetchPost("/api/attr/setBlockAttrs", {id: protyle.block.rootID, attrs: {scroll: jsonAttr}}, () => {
|
fetchPost("/api/attr/setBlockAttrs", {id: protyle.block.rootID, attrs: {scroll: jsonAttr}}, () => {
|
||||||
protyle.wysiwyg.element.setAttribute("scroll", jsonAttr);
|
protyle.wysiwyg.element.setAttribute("scroll", jsonAttr);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export const restoreScroll = (protyle: IProtyle, scrollAttr: IScrollAttr) => {
|
export const restoreScroll = (protyle: IProtyle, scrollAttr: IScrollAttr) => {
|
||||||
preventScroll(protyle);
|
preventScroll(protyle);
|
||||||
|
|
@ -67,7 +71,16 @@ export const restoreScroll = (protyle: IProtyle, scrollAttr: IScrollAttr) => {
|
||||||
startID: scrollAttr.startId,
|
startID: scrollAttr.startId,
|
||||||
endID: scrollAttr.endId,
|
endID: scrollAttr.endId,
|
||||||
}, getResponse => {
|
}, getResponse => {
|
||||||
|
protyle.block.showAll = false;
|
||||||
protyle.wysiwyg.element.innerHTML = getResponse.data.content;
|
protyle.wysiwyg.element.innerHTML = getResponse.data.content;
|
||||||
|
processRender(protyle.wysiwyg.element);
|
||||||
|
highlightRender(protyle.wysiwyg.element);
|
||||||
|
blockRender(protyle, protyle.wysiwyg.element);
|
||||||
|
if (protyle.disabled) {
|
||||||
|
disabledProtyle(protyle);
|
||||||
|
} else {
|
||||||
|
enableProtyle(protyle);
|
||||||
|
}
|
||||||
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
||||||
if (scrollAttr.focusId) {
|
if (scrollAttr.focusId) {
|
||||||
const range = focusByOffset(protyle.wysiwyg.element.querySelector(`[data-node-id="${scrollAttr.focusId}"]`), scrollAttr.focusStart, scrollAttr.focusEnd);
|
const range = focusByOffset(protyle.wysiwyg.element.querySelector(`[data-node-id="${scrollAttr.focusId}"]`), scrollAttr.focusStart, scrollAttr.focusEnd);
|
||||||
|
|
@ -75,6 +88,6 @@ export const restoreScroll = (protyle: IProtyle, scrollAttr: IScrollAttr) => {
|
||||||
pushBack(protyle, range || undefined);
|
pushBack(protyle, range || undefined);
|
||||||
/// #endif
|
/// #endif
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue