Skip to content

Commit efa0a34

Browse files
authored
fix caret loosing after caret (#2697)
1 parent c48fca1 commit efa0a34

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- `Fix` - Block removing while Enter press on Block Tunes
1313
`Fix` – Unwanted scroll on first typing on iOS devices
1414
- `Fix` - Unwanted soft line break on Enter press after period and space (". |") on iOS devices
15+
- `Fix` - Caret lost after block conversion on mobile devices.
1516

1617
### 2.29.1
1718

src/components/modules/blockManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,10 @@ export default class BlockManager extends Module {
370370
* @param newTool - new Tool name
371371
* @param data - new Tool data
372372
*/
373-
public replace(block: Block, newTool: string, data: BlockToolData): void {
373+
public replace(block: Block, newTool: string, data: BlockToolData): Block {
374374
const blockIndex = this.getBlockIndex(block);
375375

376-
this.insert({
376+
return this.insert({
377377
tool: newTool,
378378
data,
379379
index: blockIndex,
@@ -821,7 +821,7 @@ export default class BlockManager extends Module {
821821
* @param targetToolName - name of the Tool to convert to
822822
* @param blockDataOverrides - optional new Block data overrides
823823
*/
824-
public async convert(blockToConvert: Block, targetToolName: string, blockDataOverrides?: BlockToolData): Promise<void> {
824+
public async convert(blockToConvert: Block, targetToolName: string, blockDataOverrides?: BlockToolData): Promise<Block> {
825825
/**
826826
* At first, we get current Block data
827827
*/
@@ -866,7 +866,7 @@ export default class BlockManager extends Module {
866866
newBlockData = Object.assign(newBlockData, blockDataOverrides);
867867
}
868868

869-
this.replace(blockToConvert, replacingTool.name, newBlockData);
869+
return this.replace(blockToConvert, replacingTool.name, newBlockData);
870870
}
871871

872872
/**

src/components/modules/toolbar/blockSettings.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,18 +289,16 @@ export default class BlockSettings extends Module<BlockSettingsNodes> {
289289
icon: toolboxItem.icon,
290290
title: toolboxItem.title,
291291
name: toolName,
292-
onActivate: () => {
292+
onActivate: async () => {
293293
const { BlockManager, BlockSelection, Caret } = this.Editor;
294294

295-
BlockManager.convert(this.Editor.BlockManager.currentBlock, toolName, toolboxItem.data);
295+
const newBlock = await BlockManager.convert(this.Editor.BlockManager.currentBlock, toolName, toolboxItem.data);
296296

297297
BlockSelection.clearSelection();
298298

299299
this.close();
300300

301-
window.requestAnimationFrame(() => {
302-
Caret.setToBlock(this.Editor.BlockManager.currentBlock, Caret.positions.END);
303-
});
301+
Caret.setToBlock(newBlock, Caret.positions.END);
304302
},
305303
});
306304
});

0 commit comments

Comments
 (0)