This commit is contained in:
Vanessa 2023-05-10 20:18:40 +08:00
parent 78cba22910
commit e0e803d743
21 changed files with 135 additions and 71 deletions

View file

@ -434,48 +434,56 @@ const newTab = (options: IOpenFileOptions) => {
return tab;
};
export const updatePanelByEditor = (protyle?: IProtyle, focus = true, pushBackStack = false, reload = false) => {
export const updatePanelByEditor = (options: {
protyle?: IProtyle,
focus: boolean,
pushBackStack: boolean,
reload: boolean,
resize: boolean
}) => {
let title = window.siyuan.languages.siyuanNote;
if (protyle && protyle.path) {
if (options.protyle && options.protyle.path) {
// https://ld246.com/article/1637636106054/comment/1641485541929#comments
if (protyle.element.classList.contains("fn__none") ||
(!hasClosestByClassName(protyle.element, "layout__wnd--active") &&
if (options.protyle.element.classList.contains("fn__none") ||
(!hasClosestByClassName(options.protyle.element, "layout__wnd--active") &&
document.querySelector(".layout__wnd--active") // https://github.com/siyuan-note/siyuan/issues/4414
)
) {
return;
}
title = protyle.title.editElement.textContent;
resize(protyle);
title = options.protyle.title.editElement.textContent;
if (options.resize) {
resize(options.protyle);
}
if (focus) {
if (protyle.toolbar.range) {
focusByRange(protyle.toolbar.range);
countSelectWord(protyle.toolbar.range, protyle.block.rootID);
if (pushBackStack && protyle.preview.element.classList.contains("fn__none")) {
pushBack(protyle, protyle.toolbar.range);
if (options.protyle.toolbar.range) {
focusByRange(options.protyle.toolbar.range);
countSelectWord(options.protyle.toolbar.range, options.protyle.block.rootID);
if (options.pushBackStack && options.protyle.preview.element.classList.contains("fn__none")) {
pushBack(options.protyle, options.protyle.toolbar.range);
}
} else {
focusBlock(protyle.wysiwyg.element.firstElementChild);
if (pushBackStack && protyle.preview.element.classList.contains("fn__none")) {
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
focusBlock(options.protyle.wysiwyg.element.firstElementChild);
if (options.pushBackStack && options.protyle.preview.element.classList.contains("fn__none")) {
pushBack(options.protyle, undefined, options.protyle.wysiwyg.element.firstElementChild);
}
countBlockWord([], protyle.block.rootID);
countBlockWord([], options.protyle.block.rootID);
}
}
if (window.siyuan.config.fileTree.alwaysSelectOpenedFile && protyle) {
if (window.siyuan.config.fileTree.alwaysSelectOpenedFile && options.protyle) {
const fileModel = getDockByType("file")?.data.file;
if (fileModel instanceof Files) {
const target = fileModel.element.querySelector(`li[data-path="${protyle.path}"]`);
const target = fileModel.element.querySelector(`li[data-path="${options.protyle.path}"]`);
if (!target || (target && !target.classList.contains("b3-list-item--focus"))) {
fileModel.selectItem(protyle.notebookId, protyle.path);
fileModel.selectItem(options.protyle.notebookId, options.protyle.path);
}
}
}
}
// 切换页签或关闭所有页签时,需更新对应的面板
const models = getAllModels();
updateOutline(models, protyle, reload);
updateBacklinkGraph(models, protyle);
updateOutline(models, options.protyle, options.reload);
updateBacklinkGraph(models, options.protyle);
setTitle(title);
};