From 42065d6daaa65b6e2bbbe96a109e688f7684795c Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 7 Feb 2023 11:58:24 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/4350 --- app/src/assets/scss/_protyle.scss | 18 ++++---- app/src/block/Panel.ts | 75 ++++++++++++++++++------------- app/src/history/diff.ts | 2 - app/src/history/history.ts | 1 - app/src/protyle/scroll/event.ts | 5 --- app/src/protyle/scroll/index.ts | 4 +- app/src/protyle/util/Options.ts | 1 - app/src/protyle/util/onGet.ts | 10 ++++- app/src/types/index.d.ts | 2 +- app/src/types/protyle.d.ts | 1 - app/src/window/openNewWindow.ts | 11 +++++ 11 files changed, 77 insertions(+), 53 deletions(-) diff --git a/app/src/assets/scss/_protyle.scss b/app/src/assets/scss/_protyle.scss index 34201b66e..831da373d 100644 --- a/app/src/assets/scss/_protyle.scss +++ b/app/src/assets/scss/_protyle.scss @@ -4,16 +4,18 @@ @import "search"; .protyle-scroll { + --b3-dynamicscroll-width: 200px; position: absolute; right: 0; - height: 100%; - top: 0; + top: 30px; width: 16px; padding: 0 8px; + bottom: 9px; // 下图标 hover 时,需要留出一定的空间 svg { height: 16px; width: 16px; + display: block; } &__down, @@ -23,7 +25,6 @@ opacity: 0; cursor: pointer; color: var(--b3-border-color); - margin-left: -0.5px; &:hover { color: var(--b3-theme-on-surface); @@ -31,11 +32,11 @@ } &__up { - top: calc(50% - 114px); + top: calc(50% - var(--b3-dynamicscroll-width) / 2 - 20px); } &__down { - bottom: calc(50% - 135px); + bottom: calc(50% - var(--b3-dynamicscroll-width) / 2 - 20px); } &:hover { @@ -47,13 +48,14 @@ &__bar { position: absolute; - right: -89px; - top: 50%; + right: calc(11px - var(--b3-dynamicscroll-width) / 2); + top: calc(50% - 8px); transform: rotate(90deg); z-index: 1; .b3-slider { - width: 200px; + width: var(--b3-dynamicscroll-width); + display: block; } } } diff --git a/app/src/block/Panel.ts b/app/src/block/Panel.ts index 045a8c3f1..fa70bdfd3 100644 --- a/app/src/block/Panel.ts +++ b/app/src/block/Panel.ts @@ -9,6 +9,9 @@ import {Constants} from "../constants"; import {openNewWindowById} from "../window/openNewWindow"; /// #endif import {disabledProtyle} from "../protyle/util/onGet"; +import {fetchPost} from "../util/fetch"; +import {lockFile} from "../dialog/processSystem"; +import {showMessage} from "../dialog/message"; export class BlockPanel { public element: HTMLElement; @@ -241,37 +244,49 @@ export class BlockPanel { private initProtyle(editorElement: HTMLElement) { const index = parseInt(editorElement.getAttribute("data-index")); - const action = [Constants.CB_GET_ALL]; - if (this.targetElement.classList.contains("protyle-attr--refcount") || - this.targetElement.classList.contains("counter")) { - action.push(Constants.CB_GET_BACKLINK); - } - const editor = new Protyle(editorElement, { - blockId: this.nodeIds[index], - defId: this.defIds[index] || this.defIds[0] || "", - action, - render: { - gutter: true, - breadcrumbDocName: true, - breadcrumbContext: true - }, - typewriterMode: false, - after: (editor) => { - if (window.siyuan.config.readonly || window.siyuan.config.editor.readOnly) { - disabledProtyle(editor.protyle); - } - editorElement.addEventListener("mouseleave", () => { - hideElements(["gutter"], editor.protyle); - }); - // 浮窗完整文档面包屑应不显示 退出聚焦 - if (editor.protyle.breadcrumb && editor.protyle.block.id === editor.protyle.block.rootID) { - const exitFocusElement = editor.protyle.breadcrumb.element.parentElement.querySelector('[data-type="exit-focus"]'); - exitFocusElement.classList.add("fn__none"); - exitFocusElement.nextElementSibling.classList.add("fn__none"); - } + fetchPost("api/block/getBlockInfo", {id: this.nodeIds[index]}, (response) => { + if (response.code === 2) { + // 文件被锁定 + lockFile(response.data); + return false; } - }); - this.editors.push(editor); + if (response.code === 3) { + showMessage(response.msg); + return; + } + const action = []; + if (response.data.rootID !== this.nodeIds[index]) { + action.push(Constants.CB_GET_ALL); + } + if (this.targetElement.classList.contains("protyle-attr--refcount") || + this.targetElement.classList.contains("counter")) { + action.push(Constants.CB_GET_BACKLINK); + } + const editor = new Protyle(editorElement, { + blockId: this.nodeIds[index], + defId: this.defIds[index] || this.defIds[0] || "", + action, + render: { + scroll: true, + gutter: true, + breadcrumbDocName: true, + }, + typewriterMode: false, + after: (editor) => { + if (window.siyuan.config.readonly || window.siyuan.config.editor.readOnly) { + disabledProtyle(editor.protyle); + } + editorElement.addEventListener("mouseleave", () => { + hideElements(["gutter"], editor.protyle); + }); + if (response.data.rootID !== this.nodeIds[index]) { + editor.protyle.breadcrumb.element.parentElement.insertAdjacentHTML("beforeend", ` +
`) + } + } + }); + this.editors.push(editor); + }) } public destroy() { diff --git a/app/src/history/diff.ts b/app/src/history/diff.ts index 3c582b040..d283f6008 100644 --- a/app/src/history/diff.ts +++ b/app/src/history/diff.ts @@ -43,7 +43,6 @@ const renderCompare = (element: HTMLElement) => { gutter: false, breadcrumb: false, breadcrumbDocName: false, - breadcrumbContext: false, }, typewriterMode: false }); @@ -57,7 +56,6 @@ const renderCompare = (element: HTMLElement) => { gutter: false, breadcrumb: false, breadcrumbDocName: false, - breadcrumbContext: false, }, typewriterMode: false }); diff --git a/app/src/history/history.ts b/app/src/history/history.ts index 2658b07a4..197adb944 100644 --- a/app/src/history/history.ts +++ b/app/src/history/history.ts @@ -342,7 +342,6 @@ export const openHistory = () => { gutter: false, breadcrumb: false, breadcrumbDocName: false, - breadcrumbContext: false, }, typewriterMode: false, }); diff --git a/app/src/protyle/scroll/event.ts b/app/src/protyle/scroll/event.ts index 5b65ef4b6..186099cf5 100644 --- a/app/src/protyle/scroll/event.ts +++ b/app/src/protyle/scroll/event.ts @@ -32,11 +32,6 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => { hideElements(["gutter"], protyle); } - const panelContextElement = protyle.breadcrumb?.element.parentElement.querySelector('[data-type="context"]'); - if (panelContextElement && !panelContextElement.classList.contains("ft__primary")) { - // 悬浮窗需展开上下文后才能进行滚动 https://github.com/siyuan-note/siyuan/issues/2311 - return; - } if (protyle.scroll && !protyle.scroll.element.classList.contains("fn__none")) { clearTimeout(getIndexTimeout); getIndexTimeout = window.setTimeout(() => { diff --git a/app/src/protyle/scroll/index.ts b/app/src/protyle/scroll/index.ts index 88bd2403d..c6b5c1444 100644 --- a/app/src/protyle/scroll/index.ts +++ b/app/src/protyle/scroll/index.ts @@ -19,13 +19,13 @@ export class Scroll { if (!isMobile()) { this.parentElement.style.right = "10px"; } - this.parentElement.innerHTML = `
+ this.parentElement.innerHTML = `
-
+
`; diff --git a/app/src/protyle/util/Options.ts b/app/src/protyle/util/Options.ts index 5c446bd64..83d19da12 100644 --- a/app/src/protyle/util/Options.ts +++ b/app/src/protyle/util/Options.ts @@ -15,7 +15,6 @@ export class Options { scroll: false, breadcrumb: true, breadcrumbDocName: false, - breadcrumbContext: false }, action: [], after: undefined, diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index a009d1b6f..82cfab087 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -16,6 +16,7 @@ import {hasClosestByAttribute, hasClosestByClassName} from "./hasClosest"; import {preventScroll} from "../scroll/preventScroll"; import {restoreScroll} from "../scroll/saveScroll"; import {removeLoading} from "../ui/initUI"; +import {isMobile} from "../../util/functions"; export const onGet = (data: IWebSocketData, protyle: IProtyle, action: string[] = [], scrollAttr?: IScrollAttr, renderTitle = false) => { protyle.wysiwyg.element.removeAttribute("data-top"); @@ -283,8 +284,13 @@ const setHTML = (options: { protyle.options.defId = undefined; } // https://ld246.com/article/1653639418266 - if (protyle.element.classList.contains("block__edit") && (protyle.element.nextElementSibling || protyle.element.previousElementSibling)) { - protyle.element.style.minHeight = Math.min(30 + protyle.wysiwyg.element.clientHeight, window.innerHeight / 3) + "px"; + if (protyle.element.classList.contains("block__edit")) { + if (protyle.element.nextElementSibling || protyle.element.previousElementSibling) { + protyle.element.style.minHeight = Math.min(30 + protyle.wysiwyg.element.clientHeight, window.innerHeight / 3) + "px"; + } + // 49 = 16(上图标)+16(下图标)+8(padding)+9(底部距离) + // @ts-ignore + protyle.scroll.element.parentElement.setAttribute("style", `--b3-dynamicscroll-width:${protyle.contentElement.clientHeight - 49}px;${isMobile() ? "" : "right:10px"}`); } // 屏幕太高的页签 https://github.com/siyuan-note/siyuan/issues/5018 if (!protyle.scroll.element.classList.contains("fn__none") && diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index b933c36c8..56d4b58a9 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -435,7 +435,7 @@ declare interface IConfig { autoLaunch: boolean } localIPs: string[] - readonly: boolean + readonly: boolean // 全局只读 uiLayout: Record langs: { label: string, name: string }[] appearance: IAppearance diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts index 312301b9a..1fc19c451 100644 --- a/app/src/types/protyle.d.ts +++ b/app/src/types/protyle.d.ts @@ -378,7 +378,6 @@ interface IOptions { scroll?: boolean breadcrumb?: boolean breadcrumbDocName?: boolean - breadcrumbContext?: boolean } /** 内部调试时使用 */ _lutePath?: string; diff --git a/app/src/window/openNewWindow.ts b/app/src/window/openNewWindow.ts index 77ddd2dbf..116625a8f 100644 --- a/app/src/window/openNewWindow.ts +++ b/app/src/window/openNewWindow.ts @@ -5,6 +5,8 @@ import {ipcRenderer} from "electron"; import {Constants} from "../constants"; import {Tab} from "../layout/Tab"; import {fetchPost} from "../util/fetch"; +import {lockFile} from "../dialog/processSystem"; +import {showMessage} from "../dialog/message"; export const openNewWindow = (tab: Tab) => { const json = {}; @@ -17,6 +19,15 @@ export const openNewWindow = (tab: Tab) => { export const openNewWindowById = (id: string) => { fetchPost("api/block/getBlockInfo", {id}, (response) => { + if (response.code === 2) { + // 文件被锁定 + lockFile(response.data); + return false; + } + if (response.code === 3) { + showMessage(response.msg); + return; + } const json: any = { title: response.data.rootTitle, docIcon: response.data.rootIcon,