@@ -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 = () => {
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
|
import { Protocol } from '@toeverything/datasource/db-service';
|
||||||
import {
|
import {
|
||||||
BaseView,
|
|
||||||
AsyncBlock,
|
AsyncBlock,
|
||||||
|
BaseView,
|
||||||
BlockEditor,
|
BlockEditor,
|
||||||
HTML2BlockResult,
|
HTML2BlockResult,
|
||||||
} from '@toeverything/framework/virgo';
|
} from '@toeverything/framework/virgo';
|
||||||
import { Protocol } from '@toeverything/datasource/db-service';
|
|
||||||
import { CodeView } from './CodeView';
|
|
||||||
import {
|
import {
|
||||||
Block2HtmlProps,
|
Block2HtmlProps,
|
||||||
commonBlock2HtmlContent,
|
commonBlock2HtmlContent,
|
||||||
commonHTML2block,
|
commonHTML2block,
|
||||||
} from '../../utils/commonBlockClip';
|
} from '../../utils/commonBlockClip';
|
||||||
|
import { CodeView } from './CodeView';
|
||||||
|
|
||||||
export class CodeBlock extends BaseView {
|
export class CodeBlock extends BaseView {
|
||||||
type = Protocol.Block.Type.code;
|
type = Protocol.Block.Type.code;
|
||||||
public override selectable = true;
|
public override selectable = true;
|
||||||
public override editable = false;
|
public override editable = true;
|
||||||
// View = CodeView;
|
// View = CodeView;
|
||||||
View = CodeView;
|
View = CodeView;
|
||||||
override async onCreate(block: AsyncBlock): Promise<AsyncBlock> {
|
override async onCreate(block: AsyncBlock): Promise<AsyncBlock> {
|
||||||
|
|||||||
@@ -97,6 +97,23 @@ export const TextView = ({
|
|||||||
const onBackspace: TextProps['handleBackSpace'] = editor.withBatch(
|
const onBackspace: TextProps['handleBackSpace'] = editor.withBatch(
|
||||||
async props => {
|
async props => {
|
||||||
const { isCollAndStart } = props;
|
const { isCollAndStart } = props;
|
||||||
|
const activeBlockIds =
|
||||||
|
editor.selectionManager.getSelectedNodesIds();
|
||||||
|
|
||||||
|
// when only one group selected , remove this group block
|
||||||
|
if (activeBlockIds && activeBlockIds.length === 1) {
|
||||||
|
const activeBlock = await editor.getBlockById(
|
||||||
|
activeBlockIds[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
activeBlock &&
|
||||||
|
activeBlock.type === Protocol.Block.Type.group
|
||||||
|
) {
|
||||||
|
await activeBlock.remove();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!isCollAndStart) {
|
if (!isCollAndStart) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -406,6 +406,7 @@ export const TextManage = forwardRef<ExtendedTextUtils, CreateTextView>(
|
|||||||
textRef.current.isEmpty() || textRef.current.isSelectAll();
|
textRef.current.isEmpty() || textRef.current.isSelectAll();
|
||||||
|
|
||||||
const ifSelectGroup = await selectGroupBlocks(isSelectAll);
|
const ifSelectGroup = await selectGroupBlocks(isSelectAll);
|
||||||
|
|
||||||
if (ifSelectGroup) {
|
if (ifSelectGroup) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
|
setTimeout(() => {
|
||||||
|
editor.selectionManager.activeNodeByNodeId(nextBlock.id);
|
||||||
|
});
|
||||||
if (block.blockProvider.isEmpty()) {
|
if (block.blockProvider.isEmpty()) {
|
||||||
block.remove();
|
block.remove();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user