mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 18:10:12 +01:00
This commit is contained in:
parent
4bf4c1228c
commit
c4360840c2
6 changed files with 16 additions and 25 deletions
|
|
@ -394,10 +394,6 @@
|
||||||
&:focus {
|
&:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&--untitled {
|
|
||||||
color: var(--b3-theme-on-surface);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export const validateName = (name: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const replaceFileName = (name: string) => {
|
export const replaceFileName = (name: string) => {
|
||||||
return name.replace(/\r\n|\r|\n|\u2028|\u2029|\t|\//g, "").trim();
|
return name.replace(/\r\n|\r|\n|\u2028|\u2029|\t|\//g, "");
|
||||||
};
|
};
|
||||||
|
|
||||||
export const rename = (options: {
|
export const rename = (options: {
|
||||||
|
|
@ -130,7 +130,7 @@ export const newFileBySelect = (fileName: string, protyle: IProtyle) => {
|
||||||
const id = Lute.NewNodeID();
|
const id = Lute.NewNodeID();
|
||||||
fetchPost("/api/filetree/createDoc", {
|
fetchPost("/api/filetree/createDoc", {
|
||||||
notebook: protyle.notebookId,
|
notebook: protyle.notebookId,
|
||||||
path: pathPosix().join(getDisplayName(protyle.path, false, true), id+ ".sy"),
|
path: pathPosix().join(getDisplayName(protyle.path, false, true), id + ".sy"),
|
||||||
title: fileName,
|
title: fileName,
|
||||||
md: ""
|
md: ""
|
||||||
}, () => {
|
}, () => {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import {setTitle} from "../../dialog/processSystem";
|
||||||
import {getNoContainerElement} from "../wysiwyg/getBlock";
|
import {getNoContainerElement} from "../wysiwyg/getBlock";
|
||||||
import {commonHotkey} from "../wysiwyg/commonHotkey";
|
import {commonHotkey} from "../wysiwyg/commonHotkey";
|
||||||
import {setPosition} from "../../util/setPosition";
|
import {setPosition} from "../../util/setPosition";
|
||||||
|
import {code160to32} from "../util/code160to32";
|
||||||
|
|
||||||
export class Title {
|
export class Title {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -228,22 +229,15 @@ export class Title {
|
||||||
|
|
||||||
private rename(protyle: IProtyle) {
|
private rename(protyle: IProtyle) {
|
||||||
if (!validateName(this.editElement.textContent)) {
|
if (!validateName(this.editElement.textContent)) {
|
||||||
this.editElement.textContent = replaceFileName(this.editElement.textContent);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.editElement.textContent.trim() === "" || this.editElement.textContent.trim() === window.siyuan.languages.untitled) {
|
|
||||||
this.editElement.textContent = window.siyuan.languages.untitled;
|
|
||||||
this.editElement.classList.add("protyle-title__input--untitled");
|
|
||||||
} else {
|
|
||||||
this.editElement.classList.remove("protyle-title__input--untitled");
|
|
||||||
}
|
|
||||||
const fileName = replaceFileName(this.editElement.textContent);
|
const fileName = replaceFileName(this.editElement.textContent);
|
||||||
fetchPost("/api/filetree/renameDoc", {
|
fetchPost("/api/filetree/renameDoc", {
|
||||||
notebook: protyle.notebookId,
|
notebook: protyle.notebookId,
|
||||||
path: protyle.path,
|
path: protyle.path,
|
||||||
title: fileName,
|
title: fileName,
|
||||||
});
|
});
|
||||||
this.editElement.textContent = fileName;
|
this.setTitle(fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private renderMenu(protyle: IProtyle, iconElement: Element, position: { x: number, y: number }) {
|
private renderMenu(protyle: IProtyle, iconElement: Element, position: { x: number, y: number }) {
|
||||||
|
|
@ -333,6 +327,12 @@ ${window.siyuan.languages.createdAt} ${dayjs(response.data.ial.id.substr(0, 14))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setTitle(title: string) {
|
||||||
|
if (code160to32(title) !== code160to32(this.editElement.textContent)) {
|
||||||
|
this.editElement.textContent = title === "Untitled" ? "" : title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public render(protyle: IProtyle, refresh = false) {
|
public render(protyle: IProtyle, refresh = false) {
|
||||||
if (this.editElement.getAttribute("data-render") === "true" && !refresh) {
|
if (this.editElement.getAttribute("data-render") === "true" && !refresh) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -344,12 +344,7 @@ ${window.siyuan.languages.createdAt} ${dayjs(response.data.ial.id.substr(0, 14))
|
||||||
protyle.background.render(response.data.ial, protyle.block.rootID);
|
protyle.background.render(response.data.ial, protyle.block.rootID);
|
||||||
protyle.wysiwyg.renderCustom(response.data.ial);
|
protyle.wysiwyg.renderCustom(response.data.ial);
|
||||||
this.editElement.setAttribute("data-render", "true");
|
this.editElement.setAttribute("data-render", "true");
|
||||||
this.editElement.textContent = response.data.ial.title;
|
this.setTitle(response.data.ial.title);
|
||||||
if (response.data.ial.title === window.siyuan.languages.untitled) {
|
|
||||||
this.editElement.classList.add("protyle-title__input--untitled");
|
|
||||||
} else {
|
|
||||||
this.editElement.classList.remove("protyle-title__input--untitled");
|
|
||||||
}
|
|
||||||
let nodeAttrHTML = "";
|
let nodeAttrHTML = "";
|
||||||
if (response.data.ial.bookmark) {
|
if (response.data.ial.bookmark) {
|
||||||
nodeAttrHTML += `<div class="protyle-attr--bookmark">${Lute.EscapeHTMLStr(response.data.ial.bookmark)}</div>`;
|
nodeAttrHTML += `<div class="protyle-attr--bookmark">${Lute.EscapeHTMLStr(response.data.ial.bookmark)}</div>`;
|
||||||
|
|
@ -367,7 +362,7 @@ ${window.siyuan.languages.createdAt} ${dayjs(response.data.ial.id.substr(0, 14))
|
||||||
if (response.data.refCount !== 0) {
|
if (response.data.refCount !== 0) {
|
||||||
this.element.querySelector(".protyle-attr").insertAdjacentHTML("beforeend", `<div class="protyle-attr--refcount popover__block" data-defids='${JSON.stringify([protyle.block.rootID])}' data-id='${JSON.stringify(response.data.refIDs)}'>${response.data.refCount}</div>`);
|
this.element.querySelector(".protyle-attr").insertAdjacentHTML("beforeend", `<div class="protyle-attr--refcount popover__block" data-defids='${JSON.stringify([protyle.block.rootID])}' data-id='${JSON.stringify(response.data.refIDs)}'>${response.data.refCount}</div>`);
|
||||||
}
|
}
|
||||||
// 存在设置新建文档名模板,不能使用 window.siyuan.languages.untitled 进行判断,https://ld246.com/article/1649301009888
|
// 存在设置新建文档名模板,不能使用 Untitled 进行判断,https://ld246.com/article/1649301009888
|
||||||
if (new Date().getTime() - dayjs(response.data.id.split("-")[0]).toDate().getTime() < 2000) {
|
if (new Date().getTime() - dayjs(response.data.id.split("-")[0]).toDate().getTime() < 2000) {
|
||||||
const range = this.editElement.ownerDocument.createRange();
|
const range = this.editElement.ownerDocument.createRange();
|
||||||
range.selectNodeContents(this.editElement);
|
range.selectNodeContents(this.editElement);
|
||||||
|
|
|
||||||
|
|
@ -493,10 +493,10 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
||||||
fetchPost("/api/filetree/createDoc", {
|
fetchPost("/api/filetree/createDoc", {
|
||||||
notebook: protyle.notebookId,
|
notebook: protyle.notebookId,
|
||||||
path: pathPosix().join(getDisplayName(protyle.path, false, true), newSubDocId + ".sy"),
|
path: pathPosix().join(getDisplayName(protyle.path, false, true), newSubDocId + ".sy"),
|
||||||
title: window.siyuan.languages.untitled,
|
title: "Untitled",
|
||||||
md: ""
|
md: ""
|
||||||
}, () => {
|
}, () => {
|
||||||
insertHTML(genEmptyBlock(false, false, `<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">${escapeHtml(window.siyuan.languages.untitled)}</span>`), protyle);
|
insertHTML(genEmptyBlock(false, false, `<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`), protyle);
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
openMobileFileById(newSubDocId, true);
|
openMobileFileById(newSubDocId, true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ class Protyle {
|
||||||
this.protyle.model.parent.updateTitle(data.data.title);
|
this.protyle.model.parent.updateTitle(data.data.title);
|
||||||
}
|
}
|
||||||
if (this.protyle.options.render.title && this.protyle.block.parentID === data.data.id) {
|
if (this.protyle.options.render.title && this.protyle.block.parentID === data.data.id) {
|
||||||
this.protyle.title.editElement.textContent = data.data.title;
|
this.protyle.title.setTitle(data.data.title);
|
||||||
}
|
}
|
||||||
// update ref
|
// update ref
|
||||||
this.protyle.wysiwyg.element.querySelectorAll(`[data-type="block-ref"][data-id="${data.data.id}"]`).forEach(item => {
|
this.protyle.wysiwyg.element.querySelectorAll(`[data-type="block-ref"][data-id="${data.data.id}"]`).forEach(item => {
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ export const newFile = (notebookId?: string, currentPath?: string, open?: boolea
|
||||||
fetchPost("/api/filetree/createDoc", {
|
fetchPost("/api/filetree/createDoc", {
|
||||||
notebook: notebookId,
|
notebook: notebookId,
|
||||||
path: pathPosix().join(getDisplayName(currentPath, false, true), id + ".sy"),
|
path: pathPosix().join(getDisplayName(currentPath, false, true), id + ".sy"),
|
||||||
title: data.data.name || window.siyuan.languages.untitled,
|
title: data.data.name || "Untitled",
|
||||||
md: "",
|
md: "",
|
||||||
}, () => {
|
}, () => {
|
||||||
if (open && !isMobile()) {
|
if (open && !isMobile()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue