nhn / tui.editor

🍞📝 Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.
http://ui.toast.com/tui-editor
MIT License
17.13k stars 1.74k forks source link

select the table in WYSIWYG, switch back to Markdown, and click WYSIWYG, an error bug will appear #3145

Open yy2012 opened 1 year ago

yy2012 commented 1 year ago

Describe the bug

select the table in WYSIWYG, switch back to Markdown, and click WYSIWYG, an error bug will appear

To Reproduce

  1. Select any table in WYSIWYG
  2. switch back to Markdown
  3. click WYSIWYG
  4. See error

You can reproduce this problem on this page https://ui.toast.com/tui-editor

Uncaught TypeError: Cannot read properties of null (reading 'totalColumnCount') at t.map (index.js:19100:47) at n.selection.get (index.es.js:701:45) at w.apply (index.es.js:907:15) at UxO+.S.applyInner (index.es.js:1095:37) at UxO+.S.applyTransaction (index.es.js:1028:23) at $t.dispatchTransaction (index.js:23602:38) at V2qZ.$t.dispatch (index.es.js:7400:25) at t.setModel (index.js:23724:15) at e.changeMode (index.js:27534:21) at index.js:23939:30

ygzhang-cn commented 1 year ago
import { TextSelection } from "prosemirror-state";
youEditorInstance.on("changeMode", function (mode) {
            console.log(mode)
            let view, state;
            if (mode == "markdown") {
                view = that.editor.wwEditor.view
                state = view.state
            } else {
                view = that.editor.mdEditor.view
                state = view.state
            }
            if (state.selection.empty) {
                console.log("state.selection is empty")
                return
            }
            if (state.selection.constructor.name != "CellSelection") {
                console.log("state.selection is not CellSelection")
                return
            }
            view.dispatch(
                state.tr.setSelection(
                    TextSelection.create(
                        state.apply(state.tr).doc,
                        state.selection.to
                    )
                ));
        })