mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-23 08:12:25 +03:00
feat(code): focus
This commit is contained in:
parent
b90ce50c0f
commit
04065bd6bd
@ -39,7 +39,7 @@ import { yaml } from '@codemirror/legacy-modes/mode/yaml';
|
|||||||
import { Extension } from '@codemirror/state';
|
import { Extension } from '@codemirror/state';
|
||||||
import {
|
import {
|
||||||
BlockPendantProvider,
|
BlockPendantProvider,
|
||||||
useOnSelect,
|
useOnSelectActive,
|
||||||
} from '@toeverything/components/editor-core';
|
} from '@toeverything/components/editor-core';
|
||||||
import { DuplicateIcon } from '@toeverything/components/icons';
|
import { DuplicateIcon } from '@toeverything/components/icons';
|
||||||
import { Option, Select, styled } from '@toeverything/components/ui';
|
import { Option, Select, styled } from '@toeverything/components/ui';
|
||||||
@ -147,7 +147,8 @@ export const CodeView = ({ block, editor }: CreateCodeView) => {
|
|||||||
codeMirror?.current?.view?.focus();
|
codeMirror?.current?.view?.focus();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
useOnSelect(block.id, (_is_select: boolean) => {
|
//TODO listen codeMirror.up down event , active
|
||||||
|
useOnSelectActive(block.id, () => {
|
||||||
focusCode();
|
focusCode();
|
||||||
});
|
});
|
||||||
const onChange = (value: string) => {
|
const onChange = (value: string) => {
|
||||||
@ -161,9 +162,9 @@ export const CodeView = ({ block, editor }: CreateCodeView) => {
|
|||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleLangChange(langType ? langType : DEFAULT_LANG);
|
handleLangChange(langType ? langType : DEFAULT_LANG);
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
focusCode();
|
// focusCode();
|
||||||
}, 100);
|
// }, 100);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const copyCode = () => {
|
const copyCode = () => {
|
||||||
|
@ -118,7 +118,7 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => {
|
|||||||
?.getRangeAt(0)
|
?.getRangeAt(0)
|
||||||
?.getBoundingClientRect();
|
?.getBoundingClientRect();
|
||||||
if (rect) {
|
if (rect) {
|
||||||
let rectTop = rect.top;
|
const rectTop = rect.top;
|
||||||
const clientHeight =
|
const clientHeight =
|
||||||
document.documentElement.clientHeight;
|
document.documentElement.clientHeight;
|
||||||
|
|
||||||
@ -224,8 +224,10 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => {
|
|||||||
await commonCommandMenuHandler(blockId, type, editor);
|
await commonCommandMenuHandler(blockId, type, editor);
|
||||||
}
|
}
|
||||||
const block = await editor.getBlockById(blockId);
|
const block = await editor.getBlockById(blockId);
|
||||||
let nextBlock = await block.nextSibling();
|
const nextBlock = await block.nextSibling();
|
||||||
|
setTimeout(() => {
|
||||||
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
|
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
|
||||||
|
});
|
||||||
if (block.blockProvider.isEmpty()) {
|
if (block.blockProvider.isEmpty()) {
|
||||||
block.remove();
|
block.remove();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user