fix: the cursor cannot be restored after paintformat is executed

This commit is contained in:
yanmao 2021-12-24 10:47:29 +08:00
parent 17cb84afa0
commit 1280f2a2ed
1 changed files with 6 additions and 1 deletions

View File

@ -6,6 +6,8 @@ import {
Plugin, Plugin,
RangeInterface, RangeInterface,
PluginOptions, PluginOptions,
DATA_ELEMENT,
UI,
} from '@aomao/engine'; } from '@aomao/engine';
import './index.css'; import './index.css';
@ -99,7 +101,9 @@ export default class<T extends PaintformatOptions> extends Plugin<T> {
const removeCommand = this.options.removeCommand || 'removeformat'; const removeCommand = this.options.removeCommand || 'removeformat';
// 选择范围为折叠状态,应用在整个段落,包括段落自己的样式 // 选择范围为折叠状态,应用在整个段落,包括段落自己的样式
if (range.collapsed) { if (range.collapsed) {
const dummy = $('<img style="display: none;" />'); let dummy = $(
`<img ${DATA_ELEMENT}="${UI}" role="format-dummy" style="display: none;" />`,
);
range.insertNode(dummy[0]); range.insertNode(dummy[0]);
const currentBlock = block.closest(range.startNode); const currentBlock = block.closest(range.startNode);
range.select(currentBlock, true); range.select(currentBlock, true);
@ -114,6 +118,7 @@ export default class<T extends PaintformatOptions> extends Plugin<T> {
this.paintBlocks(block, activeBlocks); this.paintBlocks(block, activeBlocks);
}); });
} }
dummy = currentBlock.find(`img[role="format-dummy"]`);
range.select(dummy); range.select(dummy);
range.collapse(true); range.collapse(true);
dummy.remove(); dummy.remove();