This commit is contained in:
Vanessa 2023-05-29 11:20:08 +08:00
parent 6c4753d290
commit e4b14a12c6
8 changed files with 32 additions and 29 deletions

View file

@ -45,9 +45,6 @@ export const openFileById = async (options: {
showMessage(data.msg); showMessage(data.msg);
return; return;
} }
if (typeof options.removeCurrentTab === "undefined") {
options.removeCurrentTab = true;
}
openFile({ openFile({
app: options.app, app: options.app,
fileName: data.data.rootTitle, fileName: data.data.rootTitle,
@ -80,6 +77,9 @@ export const openAsset = (app: App, assetPath: string, page: number | string, po
}; };
export const openFile = (options: IOpenFileOptions) => { export const openFile = (options: IOpenFileOptions) => {
if (typeof options.removeCurrentTab === "undefined") {
options.removeCurrentTab = true;
}
const allModels = getAllModels(); const allModels = getAllModels();
// 文档已打开 // 文档已打开
if (options.assetPath) { if (options.assetPath) {

View file

@ -221,7 +221,7 @@ export class Outline extends Model {
if (getSelection().rangeCount > 0) { if (getSelection().rangeCount > 0) {
const blockElement = hasClosestBlock(getSelection().getRangeAt(0).startContainer); const blockElement = hasClosestBlock(getSelection().getRangeAt(0).startContainer);
if (blockElement && blockElement.getAttribute("data-type") === "NodeHeading") { if (blockElement && blockElement.getAttribute("data-type") === "NodeHeading") {
this.setCurrent(blockElement) this.setCurrent(blockElement);
} }
} }
}); });

View file

@ -584,43 +584,43 @@ export const resizeTopbar = () => {
const dragElement = toolbarElement.querySelector("#drag") as HTMLElement; const dragElement = toolbarElement.querySelector("#drag") as HTMLElement;
dragElement.style.padding = ""; dragElement.style.padding = "";
const barMoreElement = toolbarElement.querySelector("#barMore") const barMoreElement = toolbarElement.querySelector("#barMore");
barMoreElement.classList.remove("fn__none") barMoreElement.classList.remove("fn__none");
barMoreElement.removeAttribute("data-hideids") barMoreElement.removeAttribute("data-hideids");
Array.from(toolbarElement.querySelectorAll('[data-hide="true"]')).forEach((item) => { Array.from(toolbarElement.querySelectorAll('[data-hide="true"]')).forEach((item) => {
item.classList.remove("fn__none") item.classList.remove("fn__none");
item.removeAttribute("data-hide"); item.removeAttribute("data-hide");
}) });
let afterDragElement = dragElement.nextElementSibling let afterDragElement = dragElement.nextElementSibling;
const hideIds: string[] = [] const hideIds: string[] = [];
while (toolbarElement.scrollWidth > toolbarElement.clientWidth + 2) { while (toolbarElement.scrollWidth > toolbarElement.clientWidth + 2) {
hideIds.push(afterDragElement.id) hideIds.push(afterDragElement.id);
afterDragElement.classList.add("fn__none") afterDragElement.classList.add("fn__none");
afterDragElement.setAttribute("data-hide", "true") afterDragElement.setAttribute("data-hide", "true");
afterDragElement = afterDragElement.nextElementSibling afterDragElement = afterDragElement.nextElementSibling;
if (afterDragElement.id === "barMore") { if (afterDragElement.id === "barMore") {
break; break;
} }
} }
let beforeDragElement = dragElement.previousElementSibling let beforeDragElement = dragElement.previousElementSibling;
while (toolbarElement.scrollWidth > toolbarElement.clientWidth + 2) { while (toolbarElement.scrollWidth > toolbarElement.clientWidth + 2) {
hideIds.push(beforeDragElement.id) hideIds.push(beforeDragElement.id);
beforeDragElement.classList.add("fn__none") beforeDragElement.classList.add("fn__none");
beforeDragElement.setAttribute("data-hide", "true") beforeDragElement.setAttribute("data-hide", "true");
beforeDragElement = beforeDragElement.previousElementSibling beforeDragElement = beforeDragElement.previousElementSibling;
if (beforeDragElement.id === "barWorkspace") { if (beforeDragElement.id === "barWorkspace") {
break; break;
} }
} }
if (hideIds.length > 0) { if (hideIds.length > 0) {
barMoreElement.classList.remove("fn__none") barMoreElement.classList.remove("fn__none");
} else { } else {
barMoreElement.classList.add("fn__none") barMoreElement.classList.add("fn__none");
} }
barMoreElement.setAttribute("data-hideids", hideIds.join(",")) barMoreElement.setAttribute("data-hideids", hideIds.join(","));
const width = dragElement.clientWidth; const width = dragElement.clientWidth;
const dragRect = dragElement.getBoundingClientRect(); const dragRect = dragElement.getBoundingClientRect();

View file

@ -1190,16 +1190,16 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
} }
}); });
} }
const isPinHead = nodeElement.getAttribute("custom-pinthead") const isPinHead = nodeElement.getAttribute("custom-pinthead");
menus.push({ menus.push({
icon: "iconPin", icon: "iconPin",
label: isPinHead ? window.siyuan.languages.unpinTableHead : window.siyuan.languages.pinTableHead, label: isPinHead ? window.siyuan.languages.unpinTableHead : window.siyuan.languages.pinTableHead,
click: () => { click: () => {
const html = nodeElement.outerHTML; const html = nodeElement.outerHTML;
if (isPinHead) { if (isPinHead) {
nodeElement.removeAttribute("custom-pinthead") nodeElement.removeAttribute("custom-pinthead");
} else { } else {
nodeElement.setAttribute("custom-pinthead", "true") nodeElement.setAttribute("custom-pinthead", "true");
} }
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html); updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);
} }

View file

@ -194,7 +194,7 @@ openTab = (options: {
return; return;
} }
} };
/// #endif /// #endif
export const API = { export const API = {

View file

@ -34,7 +34,7 @@ export const processPasteCode = (html: string, text: string) => {
return `<div data-type="NodeCodeBlock" class="code-block" data-node-id="${Lute.NewNodeID()}"><div class="protyle-action"><span class="protyle-action--first protyle-action__language" contenteditable="false">${window.siyuan.storage[Constants.LOCAL_CODELANG]}</span><span class="fn__flex-1"></span><span class="protyle-icon protyle-icon--first protyle-action__copy"><svg><use xlink:href="#iconCopy"></use></svg></span><span class="protyle-icon protyle-icon--last protyle-action__menu"><svg><use xlink:href="#iconMore"></use></svg></span></div><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}">${code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}<wbr></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`; return `<div data-type="NodeCodeBlock" class="code-block" data-node-id="${Lute.NewNodeID()}"><div class="protyle-action"><span class="protyle-action--first protyle-action__language" contenteditable="false">${window.siyuan.storage[Constants.LOCAL_CODELANG]}</span><span class="fn__flex-1"></span><span class="protyle-icon protyle-icon--first protyle-action__copy"><svg><use xlink:href="#iconCopy"></use></svg></span><span class="protyle-icon protyle-icon--last protyle-action__menu"><svg><use xlink:href="#iconMore"></use></svg></span></div><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}">${code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}<wbr></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
} else { } else {
// Paste code from IDE no longer escape `<` and `>` https://github.com/siyuan-note/siyuan/issues/8340 // Paste code from IDE no longer escape `<` and `>` https://github.com/siyuan-note/siyuan/issues/8340
code = code.replace("<", "&lt;").replace('>', "&gt;"); code = code.replace("<", "&lt;").replace(">", "&gt;");
return "`" + code + "`"; return "`" + code + "`";
} }
} }

View file

@ -15,6 +15,9 @@ export class Search extends Model {
app: options.app, app: options.app,
id: options.tab.id, id: options.tab.id,
}); });
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
options.tab.headElement?.classList.add("item--unupdate");
}
this.element = options.tab.panelElement as HTMLElement; this.element = options.tab.panelElement as HTMLElement;
this.config = options.config; this.config = options.config;
this.edit = genSearch(options.app, this.config, this.element); this.edit = genSearch(options.app, this.config, this.element);

View file

@ -66,4 +66,4 @@ const afterLayout = (app:App) => {
const tab = getInstanceById(item.getAttribute("data-id")) as Tab; const tab = getInstanceById(item.getAttribute("data-id")) as Tab;
tab.parent.switchTab(item, false, false); tab.parent.switchTab(item, false, false);
}); });
} };