Soft Break
Insert line breaks within a block of text without starting a new block.
components/demo.tsx
'use client';
import React from 'react';
import { Plate } from '@udecode/plate-common/react';
import { editorPlugins } from '@/components/editor/plugins/editor-plugins';
import { useCreateEditor } from '@/components/editor/use-create-editor';
import { Editor, EditorContainer } from '@/components/plate-ui/editor';
import { DEMO_VALUES } from './values/demo-values';
export default function Demo({ id }: { id: string }) {
const editor = useCreateEditor({
plugins: [...editorPlugins],
value: DEMO_VALUES[id],
});
return (
<Plate editor={editor}>
<EditorContainer variant="demo">
<Editor />
</EditorContainer>
</Plate>
);
}
安装
npm install @udecode/plate-break
用法
import { SoftBreakPlugin } from '@udecode/plate-break/react';
import { CodeBlockPlugin } from '@udecode/plate-code-block/react';
import { BlockquotePlugin } from '@udecode/plate-block-quote/react';
import { TablePlugin } from '@udecode/plate-table/react';
const plugins = [
// ...otherPlugins,
SoftBreakPlugin.configure({
options: {
rules: [
{ hotkey: 'shift+enter' },
{
hotkey: 'enter',
query: {
allow: [CodeBlockPlugin.key, BlockquotePlugin.key, TablePlugin.key],
},
},
],
},
}),
];
键盘快捷键
Key | Description |
---|---|
Shift + Enter | 在文本块中插入换行符,而无需开始新块。 |
插件
SoftBreakPlugin
Options
Collapse all
一个规则对象数组,用于指定激活软换行的快捷键和可选的过滤查询。