chore(core): cancel block not found alert (#8310)
This commit is contained in:
@@ -13,7 +13,6 @@ import { paramsParseOptions, preprocessParams } from '../../navigation/utils';
|
|||||||
import type { WorkbenchView } from '../../workbench';
|
import type { WorkbenchView } from '../../workbench';
|
||||||
import { EditorScope } from '../scopes/editor';
|
import { EditorScope } from '../scopes/editor';
|
||||||
import type { EditorSelector } from '../types';
|
import type { EditorSelector } from '../types';
|
||||||
import { scrollAnchoring } from '../utils/scroll-anchoring';
|
|
||||||
|
|
||||||
export class Editor extends Entity {
|
export class Editor extends Entity {
|
||||||
readonly scope = this.framework.createScope(EditorScope, {
|
readonly scope = this.framework.createScope(EditorScope, {
|
||||||
@@ -159,14 +158,21 @@ export class Editor extends Entity {
|
|||||||
|
|
||||||
const focusAt$ = LiveData.computed(get => {
|
const focusAt$ = LiveData.computed(get => {
|
||||||
const selector = get(this.selector$);
|
const selector = get(this.selector$);
|
||||||
const id =
|
const mode = get(this.mode$);
|
||||||
get(this.mode$) === 'edgeless' && selector?.elementIds?.length
|
let id = selector?.blockIds?.[0];
|
||||||
? selector?.elementIds?.[0]
|
let key = 'blockIds';
|
||||||
: selector?.blockIds?.[0];
|
|
||||||
|
if (mode === 'edgeless') {
|
||||||
|
const elementId = selector?.elementIds?.[0];
|
||||||
|
if (elementId) {
|
||||||
|
id = elementId;
|
||||||
|
key = 'elementIds';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!id) return null;
|
if (!id) return null;
|
||||||
|
|
||||||
return { id, refreshKey: selector?.refreshKey };
|
return { id, key, mode, refreshKey: selector?.refreshKey };
|
||||||
});
|
});
|
||||||
if (focusAt$.value === null && docTitle) {
|
if (focusAt$.value === null && docTitle) {
|
||||||
const title = docTitle.querySelector<
|
const title = docTitle.querySelector<
|
||||||
@@ -177,15 +183,25 @@ export class Editor extends Entity {
|
|||||||
|
|
||||||
const subscription = focusAt$
|
const subscription = focusAt$
|
||||||
.distinctUntilChanged(
|
.distinctUntilChanged(
|
||||||
(a, b) => a?.id === b?.id && a?.refreshKey === b?.refreshKey
|
(a, b) =>
|
||||||
|
a?.id === b?.id &&
|
||||||
|
a?.key === b?.key &&
|
||||||
|
a?.refreshKey === b?.refreshKey
|
||||||
)
|
)
|
||||||
.subscribe(params => {
|
.subscribe(anchor => {
|
||||||
if (!params?.id) return;
|
if (!anchor) return;
|
||||||
|
|
||||||
const std = editorContainer.host?.std;
|
const selection = editorContainer.host?.std.selection;
|
||||||
if (!std) return;
|
if (!selection) return;
|
||||||
|
|
||||||
scrollAnchoring(std, this.mode$.value, params.id);
|
const { id, key, mode } = anchor;
|
||||||
|
|
||||||
|
selection.setGroup('scene', [
|
||||||
|
selection.create('highlight', {
|
||||||
|
mode,
|
||||||
|
[key]: [id],
|
||||||
|
}),
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
unsubs.push(subscription.unsubscribe.bind(subscription));
|
unsubs.push(subscription.unsubscribe.bind(subscription));
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
import { notify } from '@affine/component';
|
|
||||||
import { I18n } from '@affine/i18n';
|
|
||||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
|
||||||
import {
|
|
||||||
GfxControllerIdentifier,
|
|
||||||
type GfxModel,
|
|
||||||
} from '@blocksuite/block-std/gfx';
|
|
||||||
import type { DocMode } from '@blocksuite/blocks';
|
|
||||||
|
|
||||||
// TODO(@fundon): it should be a command
|
|
||||||
export function scrollAnchoring(std: BlockStdScope, mode: DocMode, id: string) {
|
|
||||||
let key = 'blockIds';
|
|
||||||
let exists = false;
|
|
||||||
|
|
||||||
if (mode === 'page') {
|
|
||||||
exists = std.doc.hasBlock(id);
|
|
||||||
} else {
|
|
||||||
const controller = std.getOptional(GfxControllerIdentifier);
|
|
||||||
if (!controller) return;
|
|
||||||
|
|
||||||
exists = !!controller.getElementById<GfxModel>(id)?.xywh;
|
|
||||||
if (controller.surface?.hasElementById(id)) {
|
|
||||||
key = 'elementIds';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!exists) {
|
|
||||||
notify.error({
|
|
||||||
title: I18n['Block not found'](),
|
|
||||||
message: I18n['Block not found description'](),
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const selection = std.selection;
|
|
||||||
|
|
||||||
selection.setGroup('scene', [
|
|
||||||
selection.create('highlight', {
|
|
||||||
mode,
|
|
||||||
[key]: [id],
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
@@ -26,8 +26,6 @@
|
|||||||
"Back Home": "Back home",
|
"Back Home": "Back home",
|
||||||
"Back to Quick Search": "Back to quick search",
|
"Back to Quick Search": "Back to quick search",
|
||||||
"Back to all": "Back to all",
|
"Back to all": "Back to all",
|
||||||
"Block not found": "Block not found",
|
|
||||||
"Block not found description": "The block you are trying to access does not exist or has been removed.",
|
|
||||||
"Body text": "Body text",
|
"Body text": "Body text",
|
||||||
"Bold": "Bold",
|
"Bold": "Bold",
|
||||||
"Cancel": "Cancel",
|
"Cancel": "Cancel",
|
||||||
|
|||||||
Reference in New Issue
Block a user