Skip to content

How can i focus a richtext / block? #6883

Answered by golok727
TBenTiCon asked this question in Q&A
Discussion options

You must be logged in to vote

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

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
  })
]);

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@raintoway
Comment options

@TBenTiCon
Comment options

Comment options

You must be logged in to vote
2 replies
@TBenTiCon
Comment options

@TBenTiCon
Comment options

Answer selected by TBenTiCon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants