@douyinfe/semi-ui
Version:
A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.
39 lines (38 loc) • 3.02 kB
TypeScript
import { EditorState, Plugin, Transaction, Selection } from 'prosemirror-state';
import { EditorView } from '@tiptap/pm/view';
/**
* @param newState
* @returns
* handleZeroWidthCharLogic 用于插入零宽字符或者删除多余的零宽字符
* 为什么需要插入零宽字符?
* 1. 保证自定义节点前后的光标高度正常,光标高度和内容相关,解决自定义节点是最后一个节点,
* 光标高度会和自定义节点占据高度一致,和文本中光标高度不一致的问题
* 2. 保证对于可编辑的 inline 节点(比如 input-slot),为最后一个节点时候,光标可以聚焦到该节点后
* Why do we need to insert zero-width characters?
* 1. Ensure that the cursor height before and after the custom node is normal.
* The cursor height is related to the content. Solve the problem that when the custom node is the last node,
* the cursor height will be consistent with the height occupied by the custom node, and inconsistent with the cursor height in the text.
* 2. Ensure that for an editable inline node (such as input-slot), when it is the last node, the cursor can focus after the node.
*/
export declare function handleZeroWidthCharLogic(newState: EditorState): Transaction;
export declare function ensureTrailingText(schema: any): Plugin<any>;
export declare function keyDownHandlePlugin(schema: any): Plugin<any>;
export declare function handlePasteLogic(view: EditorView, event: ClipboardEvent): boolean;
/**
* specialPasteLogicForInputSlot 处理两种情况
* 1. 如果是 parentNode 是 input-slot,当里面内容仅为零宽字符时候
* 直接去掉零宽字符会导致 input-slot 消失,
* 因此将此行为处理成获取文字部分,将零宽字符替换为文字内容
* 2. 如果 parentNode 是 input-slot,选中 input-slot 中的所有文字并粘贴
* 会导致 input-slot 被删除,因此需要处理成使用复制内容替换原有内容的
* The `specialPasteLogicForInputSlot` function handles two cases.
* 1. If the parentNode is input-slot, and its content consists of only zero-width characters...
* Removing zero-width characters directly will cause the input slot to disappear.
* Therefore, this behavior is processed by retrieving the text portion and replacing the zero-width characters with the text content.
* 2. If the parentNode is input-slot, select all the text in the input-slot and paste it.
* This will cause the input slot to be deleted, so it needs to be handled by replacing the original content with copied content.
*/
export declare function specialPasteLogicForInputSlot(event: ClipboardEvent, $from: any, tr: Transaction, dispatch: (tr: Transaction) => void, selection: Selection): boolean;
export declare function removeZeroWidthChar($from: any, tr: Transaction): boolean;
export declare function handleCompositionEndLogic(view: EditorView): void;
export declare function handleTextInputLogic(view: EditorView, from: number, to: number, text: string): boolean;