From efa0a34f8e66a71704bded4fae4cc84ec6149919 Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Sat, 27 Apr 2024 21:19:12 +0300 Subject: [PATCH] fix caret loosing after caret (#2697) --- docs/CHANGELOG.md | 1 + src/components/modules/blockManager.ts | 8 ++++---- src/components/modules/toolbar/blockSettings.ts | 8 +++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 222ddad0..dcbd704f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -12,6 +12,7 @@ - `Fix` - Block removing while Enter press on Block Tunes – `Fix` – Unwanted scroll on first typing on iOS devices - `Fix` - Unwanted soft line break on Enter press after period and space (". |") on iOS devices +- `Fix` - Caret lost after block conversion on mobile devices. ### 2.29.1 diff --git a/src/components/modules/blockManager.ts b/src/components/modules/blockManager.ts index bfc9236b..2ab4a5f8 100644 --- a/src/components/modules/blockManager.ts +++ b/src/components/modules/blockManager.ts @@ -370,10 +370,10 @@ export default class BlockManager extends Module { * @param newTool - new Tool name * @param data - new Tool data */ - public replace(block: Block, newTool: string, data: BlockToolData): void { + public replace(block: Block, newTool: string, data: BlockToolData): Block { const blockIndex = this.getBlockIndex(block); - this.insert({ + return this.insert({ tool: newTool, data, index: blockIndex, @@ -821,7 +821,7 @@ export default class BlockManager extends Module { * @param targetToolName - name of the Tool to convert to * @param blockDataOverrides - optional new Block data overrides */ - public async convert(blockToConvert: Block, targetToolName: string, blockDataOverrides?: BlockToolData): Promise { + public async convert(blockToConvert: Block, targetToolName: string, blockDataOverrides?: BlockToolData): Promise { /** * At first, we get current Block data */ @@ -866,7 +866,7 @@ export default class BlockManager extends Module { newBlockData = Object.assign(newBlockData, blockDataOverrides); } - this.replace(blockToConvert, replacingTool.name, newBlockData); + return this.replace(blockToConvert, replacingTool.name, newBlockData); } /** diff --git a/src/components/modules/toolbar/blockSettings.ts b/src/components/modules/toolbar/blockSettings.ts index 3a2b7aa3..2d8983a9 100644 --- a/src/components/modules/toolbar/blockSettings.ts +++ b/src/components/modules/toolbar/blockSettings.ts @@ -289,18 +289,16 @@ export default class BlockSettings extends Module { icon: toolboxItem.icon, title: toolboxItem.title, name: toolName, - onActivate: () => { + onActivate: async () => { const { BlockManager, BlockSelection, Caret } = this.Editor; - BlockManager.convert(this.Editor.BlockManager.currentBlock, toolName, toolboxItem.data); + const newBlock = await BlockManager.convert(this.Editor.BlockManager.currentBlock, toolName, toolboxItem.data); BlockSelection.clearSelection(); this.close(); - window.requestAnimationFrame(() => { - Caret.setToBlock(this.Editor.BlockManager.currentBlock, Caret.positions.END); - }); + Caret.setToBlock(newBlock, Caret.positions.END); }, }); });