Skip to content

How to access editor DOM in react ? #1151

Closed Answered by Saul-Mirone
ShenQingchuan asked this question in Q&A
Discussion options

You must be logged in to vote

Okay, I got it. Here's how you can get edtior's state and view:

import { editorViewCtx } from '@milkdown/core';

editor().action((ctx) => {
    const view = ctx.get(editorViewCtx);
    const state = view.state;
    const selection = state.selection;
    const { $to } = selection;
    const to = $to.after();
    const $sel = TextSelection.near(state.doc.resolve(to));
    view.dispatch(state.tr.setSelection($sel));
    view.focus();
})

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@ShenQingchuan
Comment options

@s524797336
Comment options

@ShenQingchuan
Comment options

@Saul-Mirone
Comment options

Answer selected by ShenQingchuan
@ShenQingchuan
Comment options

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