fix caret loosing after caret (#2697)

This commit is contained in:
Peter Savchenko 2024-04-27 21:19:12 +03:00 committed by GitHub
parent c48fca1be3
commit efa0a34f8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 9 deletions

View file

@ -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

View file

@ -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<void> {
public async convert(blockToConvert: Block, targetToolName: string, blockDataOverrides?: BlockToolData): Promise<Block> {
/**
* 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);
}
/**

View file

@ -289,18 +289,16 @@ export default class BlockSettings extends Module<BlockSettingsNodes> {
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);
},
});
});