Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Stabilize grouped database item navigation https://github.com/siyuan-note/siyuan/issues/12022

Daniel1fcce985b7ad
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index c81bd25098..265a755350 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -197,7 +197,8 @@
}
&--select,
- &--hl {
+ &--hl,
+ &--locate {
&:not(.av__row--header) .av__cell,
&:not(.av__row--header) .av__firstcol {
background-color: var(--b3-theme-primary-lightest);
@@ -208,6 +209,16 @@
}
}
+ &--locate::before {
+ border: 2px solid var(--b3-theme-primary-lighter);
+ border-radius: var(--b3-border-radius-s);
+ content: '';
+ inset: 1px;
+ pointer-events: none;
+ position: absolute;
+ z-index: 4;
+ }
+
&--header {
z-index: 3;
@@ -327,7 +338,7 @@
}
&:hover {
- &:not(.av__gallery-item--select)::before {
+ &:not(.av__gallery-item--select):not(.av__gallery-item--locate)::before {
background-color: var(--b3-theme-surface-light);
}
@@ -336,7 +347,8 @@
}
}
- &--select::before {
+ &--select::before,
+ &--locate::before {
background-color: var(--b3-theme-primary-lightest) !important;
opacity: 1 !important;
}
@@ -1415,7 +1427,7 @@
opacity: 0.26;
}
- &:hover:not(.av__gallery-item--select)::before {
+ &:hover:not(.av__gallery-item--select):not(.av__gallery-item--locate)::before {
background-color: var(--b3-av-kanban-background);
opacity: 0.38;
}
diff --git a/app/src/protyle/render/av/locate.ts b/app/src/protyle/render/av/locate.ts
index 922f55127f..b0ca47180c 100644
--- a/app/src/protyle/render/av/locate.ts
+++ b/app/src/protyle/render/av/locate.ts
@@ -3,6 +3,7 @@ import {showMessage} from "../../../dialog/message";
import {transaction} from "../../wysiwyg/transaction";
import {clearSelect} from "../../util/clear";
import {addDragFill} from "./cell";
+import {scrollCenter} from "../../../util/highlightById";
export interface IAVLocateRequest {
itemID: string;
@@ -17,18 +18,67 @@ export interface IAVLocateRequest {
const locateRequests = new WeakMap<HTMLElement, IAVLocateRequest>();
const queuedLocateRequests = new Map<string, IAVLocateRequest>();
const renderTokens = new WeakMap<HTMLElement, symbol>();
-const highlightTimers = new WeakMap<HTMLElement, number>();
+const highlightTokens = new WeakMap<HTMLElement, symbol>();
-const highlightTemporarily = (blockElement: HTMLElement, targetElement: HTMLElement, className: string) => {
- window.clearTimeout(highlightTimers.get(blockElement));
- targetElement.classList.add(className);
- const timer = window.setTimeout(() => {
- targetElement.classList.remove(className);
- if (highlightTimers.get(blockElement) === timer) {
- highlightTimers.delete(blockElement);
+const highlightLocatedItem = (blockElement: HTMLElement, protyle: IProtyle, viewType: TAVView,
+ groupQuery: string, itemID: string) => {
+ const token = Symbol();
+ highlightTokens.set(blockElement, token);
+ const waitStartedAt = performance.now();
+ let highlightStartedAt: number;
+ let previousRect: DOMRect;
+ let stableFrames = 0;
+ const className = viewType === "table" ? "av__row--locate" : "av__gallery-item--locate";
+ const targetQuery = viewType === "table" ? `.av__row[data-id="${itemID}"]` : `.av__gallery-item[data-id="${itemID}"]`;
+ const clearHighlight = () => {
+ blockElement.querySelectorAll(`.${className}`).forEach(item => item.classList.remove(className));
+ };
+ const frame = () => {
+ if (highlightTokens.get(blockElement) !== token || !blockElement.isConnected) {
+ return;
+ }
+ const now = performance.now();
+ const targetElement = blockElement.querySelector(groupQuery)?.querySelector(targetQuery) as HTMLElement;
+ if (targetElement) {
+ const rect = targetElement.getBoundingClientRect();
+ const contentRect = protyle.contentElement.getBoundingClientRect();
+ const visible = rect.height > 0 && rect.bottom > contentRect.top && rect.top < contentRect.bottom;
+ if (visible && previousRect && Math.abs(previousRect.top - rect.top) < 0.5 &&
+ Math.abs(previousRect.left - rect.left) < 0.5 && Math.abs(previousRect.width - rect.width) < 0.5 &&
+ Math.abs(previousRect.height - rect.height) < 0.5) {
+ stableFrames++;
+ } else {
+ stableFrames = 0;
+ }
+ previousRect = rect;
+ if (stableFrames >= 2) {
+ if (highlightStartedAt === undefined) {
+ highlightStartedAt = now;
+ clearHighlight();
+ if (viewType === "table") {
+ protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl, .av__row--hl").forEach(item => {
+ item.classList.remove("protyle-wysiwyg--hl", "av__row--hl");
+ });
+ }
+ }
+ targetElement.classList.add(className);
+ }
+ } else {
+ previousRect = undefined;
+ stableFrames = 0;
+ }
+ if (highlightStartedAt !== undefined && now - highlightStartedAt >= 1024) {
+ clearHighlight();
+ highlightTokens.delete(blockElement);
+ return;
}
- }, 1024);
- highlightTimers.set(blockElement, timer);
+ if (highlightStartedAt === undefined && now - waitStartedAt >= 10000) {
+ highlightTokens.delete(blockElement);
+ return;
+ }
+ requestAnimationFrame(frame);
+ };
+ requestAnimationFrame(frame);
};
export const beginAVRender = (blockElement: HTMLElement) => {
@@ -180,12 +230,6 @@ export const finishAVLocate = (blockElement: HTMLElement, protyle: IProtyle, dat
if (data.viewType === "table") {
const rowElement = bodyElement?.querySelector(`.av__row[data-id="${request.itemID}"]`) as HTMLElement;
targetElement = rowElement?.querySelector(".av__cell[data-dtype=\"block\"]") as HTMLElement;
- if (rowElement && request.highlight) {
- protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl, .av__row--hl").forEach(item => {
- item.classList.remove("protyle-wysiwyg--hl", "av__row--hl");
- });
- highlightTemporarily(blockElement, rowElement, "av__row--hl");
- }
if (targetElement && request.select !== false) {
clearSelect(["cell"], blockElement);
targetElement.classList.add("av__cell--select");
@@ -193,13 +237,9 @@ export const finishAVLocate = (blockElement: HTMLElement, protyle: IProtyle, dat
}
} else {
targetElement = bodyElement?.querySelector(`.av__gallery-item[data-id="${request.itemID}"]`) as HTMLElement;
- if (targetElement && (request.select !== false || request.highlight)) {
+ if (targetElement && request.select !== false && !request.highlight) {
blockElement.querySelectorAll(".av__gallery-item--select").forEach(item => item.classList.remove("av__gallery-item--select"));
- if (request.highlight) {
- highlightTemporarily(blockElement, targetElement, "av__gallery-item--select");
- } else {
- targetElement.classList.add("av__gallery-item--select");
- }
+ targetElement.classList.add("av__gallery-item--select");
}
}
if (!targetElement) {
@@ -209,7 +249,10 @@ export const finishAVLocate = (blockElement: HTMLElement, protyle: IProtyle, dat
const contentRect = protyle.contentElement.getBoundingClientRect();
protyle.contentElement.scrollTop += blockElement.getBoundingClientRect().top - contentRect.top;
} else {
- targetElement.scrollIntoView({block: "center", inline: "nearest"});
+ scrollCenter(protyle, targetElement, "center");
+ }
+ if (request.highlight) {
+ highlightLocatedItem(blockElement, protyle, data.viewType, groupQuery, request.itemID);
}
clearAVLocateRequest(blockElement, request);
};
diff --git a/kernel/model/attribute_view_render.go b/kernel/model/attribute_view_render.go
index fd83c3e6a0..8c2b9dcbe5 100644
--- a/kernel/model/attribute_view_render.go
+++ b/kernel/model/attribute_view_render.go
@@ -285,16 +285,21 @@ func renderAttributeViewGroups(viewable av.Viewable, attrView *av.AttributeView,
}
groupTargetItemID := ""
- if nil != target && target.Status != "viewNotFound" && (target.Status != "visible" || groupView.ID == targetGroupID) {
- groupTargetItemID = target.ItemID
+ if nil != target && target.Status != "viewNotFound" {
+ if (targetGroupID != "" && groupView.ID == targetGroupID) || (targetGroupID == "" && target.Status != "visible") {
+ groupTargetItemID = target.ItemID
+ }
}
targetIndex, renderErr := renderViewableInstance(groupViewable, view, attrView, groupPage, groupPageSize, ignoreRows, groupTargetItemID)
err = renderErr
if nil != err {
return
}
+ if !ignoreRows {
+ hideEmptyGroupViews(view, groupViewable)
+ }
if nil != target && target.Status != "viewNotFound" && targetIndex >= 0 {
- if groupView.GroupHidden == 0 {
+ if groupViewable.GetGroupHidden() == 0 {
if target.Status != "visible" || groupView.ID == targetGroupID {
setAttributeViewRenderTarget(target, groupView.ID, targetIndex, groupPageSize, view.PageSize)
}
@@ -304,9 +309,6 @@ func renderAttributeViewGroups(viewable av.Viewable, attrView *av.AttributeView,
}
}
- if !ignoreRows {
- hideEmptyGroupViews(view, groupViewable)
- }
groups = append(groups, groupViewable)
// 将分组视图的分组字段清空,减少冗余(字段信息可以在总的视图 view 对象上获取到)