mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 05:48:59 +08:00
chore: merge blocksuite source code (#9213)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import type { EditorHost } from '@blocksuite/block-std';
|
||||
import type { InlineEditor } from '@blocksuite/inline';
|
||||
|
||||
function getDocTitleByEditorHost(editorHost: EditorHost): HTMLElement | null {
|
||||
const docViewport = editorHost.closest('.affine-page-viewport');
|
||||
if (!docViewport) return null;
|
||||
return docViewport.querySelector('doc-title');
|
||||
}
|
||||
|
||||
export function getDocTitleInlineEditor(
|
||||
editorHost: EditorHost
|
||||
): InlineEditor | null {
|
||||
const docTitle = getDocTitleByEditorHost(editorHost);
|
||||
if (!docTitle) return null;
|
||||
const titleRichText = docTitle.querySelector<
|
||||
HTMLElement & { inlineEditor: InlineEditor }
|
||||
>('rich-text');
|
||||
if (!titleRichText || !titleRichText.inlineEditor) return null;
|
||||
return titleRichText.inlineEditor;
|
||||
}
|
||||
|
||||
export function focusTitle(editorHost: EditorHost, index = Infinity, len = 0) {
|
||||
const titleInlineEditor = getDocTitleInlineEditor(editorHost);
|
||||
if (!titleInlineEditor) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (index > titleInlineEditor.yText.length) {
|
||||
index = titleInlineEditor.yText.length;
|
||||
}
|
||||
titleInlineEditor.setInlineRange({ index, length: len });
|
||||
}
|
||||
Reference in New Issue
Block a user