admin管理员组文章数量:1295902
I’m using Blocknote in a Next.js project and trying to programmatically set the text cursor position on the first block. However, setTextCursorPosition
doesn’t seem to work.
Here’s what I’ve tried:
Using setTextCursorPosition
directly
const toText = useCallback(() => {
if (!editor || !editorRef.current) {
console.log('Editor atau editorRef belum siap');
return;
}
// Ambil blok pertama
const firstBlock = editor.document[0];
// Coba set cursor ke blok pertama
editor.setTextCursorPosition(firstBlock);
}, [editor]);
Editor Option
const editor = useCreateBlockNote({
schema: schema,
dropCursor: multiColumnDropCursor,
trailingBlock: true,
dictionary: {
...locales.en,
multi_column: multiColumnLocales.en,
},
initialContent: initialValue
? initialValue
: [
{
type: 'heading',
content: '', // Blok pertama selalu menjadi H1,
},
{
type: 'paragraph',
content: '', // Area kosong untuk menulis
},
],
});
Issue: Cursor doesn’t appear in the editor.
Expected Behavior:
- The text cursor should move to the first block.
- The editor should be ready for input after running toText().
Actual Behavior
- The cursor doesn’t appear.
- Clicking manually works, but not programmatically.
Any ideas on how to make setTextCursorPosition
work properly in Blocknote?
I’m using Blocknote in a Next.js project and trying to programmatically set the text cursor position on the first block. However, setTextCursorPosition
doesn’t seem to work.
Here’s what I’ve tried:
Using setTextCursorPosition
directly
const toText = useCallback(() => {
if (!editor || !editorRef.current) {
console.log('Editor atau editorRef belum siap');
return;
}
// Ambil blok pertama
const firstBlock = editor.document[0];
// Coba set cursor ke blok pertama
editor.setTextCursorPosition(firstBlock);
}, [editor]);
Editor Option
const editor = useCreateBlockNote({
schema: schema,
dropCursor: multiColumnDropCursor,
trailingBlock: true,
dictionary: {
...locales.en,
multi_column: multiColumnLocales.en,
},
initialContent: initialValue
? initialValue
: [
{
type: 'heading',
content: '', // Blok pertama selalu menjadi H1,
},
{
type: 'paragraph',
content: '', // Area kosong untuk menulis
},
],
});
Issue: Cursor doesn’t appear in the editor.
Expected Behavior:
- The text cursor should move to the first block.
- The editor should be ready for input after running toText().
Actual Behavior
- The cursor doesn’t appear.
- Clicking manually works, but not programmatically.
Any ideas on how to make setTextCursorPosition
work properly in Blocknote?
1 Answer
Reset to default 0Finally i have solution with this code
editor.setTextCursorPosition(initialCursor?.targetBlock, initialCursor?.placement);
editor.focus();
本文标签: reactjsHow to programmatically set cursor position in BlocknoteStack Overflow
版权声明:本文标题:reactjs - How to programmatically set cursor position in Blocknote? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741617917a2388637.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论