nhn / tui.editor

πŸžπŸ“ Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.
http://ui.toast.com/tui-editor
MIT License
16.91k stars 1.72k forks source link

[question, bug] fixed cursor on table when i using toolbar to make table element on tui.editor #3172

Open gloud-mook opened 10 months ago

gloud-mook commented 10 months ago

Summary

Hello, I'm Kwangmook Jung, and I'm trying to apply the @toast-ui/react-editor package to my in-house React project.

The version of the package I'm applying is 3.2.2.

The reason why I'm contacting you this time is that when I add a table through the editor toolbar in the applied editor, the cursor cannot move outside the table.

The mouse cursor can be moved outside the table by clicking the down button on the keyboard, but it may be inconvenient for users who use the service, so I tried several methods.

First, I tried selecting the DOM element directly and defocusing it.

Secondly, I tried to detect the change in the nodeList value below when adding a table element and add a br tag to the end of the table element with useEffect to avoid focusing.

const nodeList = document.querySelectorAll("#toast-editor-editor table")

const tableElements = useMemo(() => {
    return nodeList;
    //eslint-disable-next-line
}, [nodeList.length]);

useEffect(() => {
    const br = document.createElement("br");
    (tableElements || []).forEach((table) => {
        table.parentNode?.appendChild(br);
    });
}, [tableElements]);

The first is something we want to avoid as much as possible, but it hasn't worked well for us. In the second case, after creating a table, the cursor does not move outside the table again when I press the keyboard up key.

I respectfully ask if you could take a look at these issues if you can.

Thank you for taking the time to look into this in your busy schedule.

Screenshots

If applicable, add screenshots to help explain your question.

Version

3.2.2

Additional context

μ•ˆλ…•ν•˜μ„Έμš”. @toast-ui/react-editor νŒ¨ν‚€μ§€λ₯Ό μ‚¬μš©ν•˜μ—¬ 사내 λ¦¬μ•‘νŠΈ ν”„λ‘œμ νŠΈμ— μ μš©μ„ μ‹œλ„ν•˜κ³  μžˆλŠ” 정광묡 이라고 ν•©λ‹ˆλ‹€.

μ μš©μ€‘μΈ νŒ¨ν‚€μ§€μ˜ 버전은 3.2.2 λ²„μ „μž…λ‹ˆλ‹€.

닀름 μ•„λ‹ˆλΌ μ΄λ²ˆμ— 문의λ₯Ό λ“œλ¦¬κ²Œ 된 μ΄μœ λŠ” μ μš©ν•œ μ—λ””ν„°μ—μ„œ 에디터 νˆ΄λ°”λ₯Ό 톡해 ν…Œμ΄λΈ”μ„ λ„£μ—ˆμ„ λ•Œ, μ»€μ„œκ°€ ν…Œμ΄λΈ” λ°”κΉ₯으둜 이동할 수 μ—†λŠ” μ΄μŠˆκ°€ μžˆμ–΄μ„œ μž…λ‹ˆλ‹€.

ν‚€λ³΄λ“œμ—μ„œ λ°©ν–₯ν‚€ (down) λ²„νŠΌμ„ ν΄λ¦­μ‹œ 마우슀 μ»€μ„œκ°€ ν…Œμ΄λΈ” λ°”κΉ₯으둜 이동할 수 μžˆμŠ΅λ‹ˆλ‹€λ§Œ, μ„œλΉ„μŠ€λ₯Ό μ‚¬μš©ν•˜λŠ” μ‚¬μš©μžλ“€λ‘œμ„œλŠ” μ•„λ¬΄λž˜λ„ λΆˆνŽΈν•¨μ΄ μžˆμ„ 수 있기 λ•Œλ¬Έμ— μ—¬λŸ¬ μ‹œλ„λ₯Ό ν•΄λ³΄μ•˜μŠ΅λ‹ˆλ‹€.

첫 λ²ˆμ§Έλ‘œλŠ” dom μš”μ†Œλ₯Ό 직접 μ„ νƒν•΄μ„œ 포컀싱을 ν•΄μ œ ν•˜λŠ” 방식을 μ‹œλ„ν•΄ λ³΄μ•˜κ³ 

두 λ²ˆμ§Έλ‘œλŠ” ν…Œμ΄λΈ” μš”μ†Œλ₯Ό μΆ”κ°€ν•  λ•Œ μ•„λž˜ nodeList κ°’μ˜ λ³€ν™”κ°€ μƒκΈ°λŠ” 것을 κ°μ§€ν•˜κ³  useEffect λ₯Ό 가지고 table 의 μš”μ†Œ λ§ˆμ§€λ§‰μ— br νƒœκ·Έλ₯Ό μΆ”κ°€ν•΄μ„œ 포컀싱을 ν”Όν•˜λŠ” 방식을 μ‹œλ„ν•΄ λ³΄μ•˜μŠ΅λ‹ˆλ‹€.

첫번째 방식은 가급적 ν”Όν•˜κ³  싢은 λ°©μ‹μ΄μ§€λ§Œ, 적용이 잘 λ˜μ§€ μ•Šμ•˜κ³  λ‘λ²ˆμ§Έ 방식은 ν…Œμ΄λΈ” ν•˜λ‚˜λ₯Ό 생성 ν›„ ν‚€λ³΄λ“œ 상ν–₯ λ°©ν–₯ν‚€ λ₯Ό λˆŒλ €μ„ λ•Œ λ‹€μ‹œ μ»€μ„œκ°€ ν…Œμ΄λΈ” λ°”κΉ₯으둜 이동이 λ˜μ§€ μ•ŠλŠ” μ΄μŠˆκ°€ μžˆμŠ΅λ‹ˆλ‹€.

ν˜Ήμ‹œ κ°€λŠ₯ν•˜λ‹€λ©΄ ν•΄λ‹Ή μ΄μŠˆμ— λŒ€ν•΄ 확인해 μ£Όμ‹€ 수 μžˆμ„μ§€ μ •μ€‘νžˆ μ—¬μ­€λ΄…λ‹ˆλ‹€.

λ°”μ˜μ‹  와쀑에 λ‚΄μš©μ„ 확인해 μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€.