-
Hey, im currently updating my Editor and just stumbled upon the missing "asyncFocusRichText". Im creating a new Block like this: if (event.key === 'Enter' && event.ctrlKey) {
event.preventDefault();
this._isFocus = false;
const noteBlock = this.doc.getBlockByFlavour('affine:note');
const noteId = noteBlock[0].id;
const addedBlocks = this.doc.addSiblingBlocks(
this.model,
[{ flavour: 'affine:paragraph' }],
'after'
); But i cant figure out, how to focus the newly created block :( |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
u want a function to focus a element/block ? if yes, it is strange bacause |
Beta Was this translation helpful? Give feedback.
-
From the code you provided, it seems that you are trying to add a new paragraph after pressing This should set the cursor to the start of the newly added paragraph. const noteId = // your note-id;
const newParagraphId = this.doc.addBlock(
"affine:paragraph",
{},
noteId
);
const { host } = editor;
host.selection.setGroup('note', [
host.selection.create("text", {
from: {
path: [rootBlockId, noteId, newParagraphId],
index: 0,
length: 0,
},
to: null
})
]); |
Beta Was this translation helpful? Give feedback.
From the code you provided, it seems that you are trying to add a new paragraph after pressing
Ctrl + Enter
from the current range am I right?This should set the cursor to the start of the newly added paragraph.
Please take a took at Selecting Blocks