Esc does not exit multi-cursor mode due to hidden comment toolbar intercepting keydown

未關閉
#445 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
22/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
javascript
領域
frontend

研究方向

This repository is the issue tracker, so the code is not here; the report points at the bundled asset es2015-B-MiIaIH.js and Radix UI's DismissableLayer. Start by reproducing the Escape behaviour in the editor and checking whether a hidden comment toolbar stays in the layer stack. Done means Escape collapses multiple CodeMirror selections while that toolbar is hidden, and the report is moved to or linked from the right repository.

由索引模型根據 Issue 內容生成。

描述

  • Yes, the bug happens on https://hackmd.io/
  • No. If it's a self-hosted CodiMD instance, please file the issue in the CodiMD repository.
What's the problem
Current behaviour

Pressing Esc does not exit multi-cursor mode in the HackMD editor.

This appears to be caused by a hidden comment floating toolbar intercepting the Escape key through Radix UI's DismissableLayer before CodeMirror can process it.

Steps to reproduce:

  1. Open a note on https://hackmd.io/ in edit mode.
  2. Press Ctrl + Shift + Up/Down to create multiple cursors.
  3. Press Esc.
  4. Observe that the multiple cursors remain active.

The issue also reproduces in Chrome Incognito mode.

Expected behaviour

Pressing Esc should remove the additional cursors, leaving a single cursor, as defined by CodeMirror's Sublime keymap.

Environment

Desktop:

  • OS: macOS
  • Browser: Google Chrome
  • Browser Version: 156

Mobile:

  • Not tested
Additional context

I investigated this issue using Chrome DevTools and identified what appears to be the root cause.

  1. CodeMirror 5 uses the sublime keymap, where Esc is mapped to singleSelectionTop.
  2. Calling cm.execCommand("singleSelectionTop") directly works correctly.
  3. The Escape keydown event reaches CodeMirror, but defaultPrevented is already true.
  4. A document-level capture listener calls preventDefault() before CodeMirror handles the event.
  5. The caller appears to be Radix UI's DismissableLayer in HackMD's es2015-B-MiIaIH.js asset.

Inspecting the handler's closure showed that the associated element is a comment floating toolbar:

  • element.innerText: "コメント" (Comment)
  • element.isConnected: true
  • getComputedStyle(element).display: "none"
  • element.className includes hidden
  • The element remains registered in dismissableLayers.layers.
  • The handler considers itself the topmost layer.

Despite being hidden, the comment toolbar's DismissableLayer still consumes Escape events.

The event trace confirms:

  • window capture: defaultPrevented = false
  • document capture: defaultPrevented = true
  • CodeMirror keydown: defaultPrevented = true
  • CodeMirror keyHandled: not emitted
  • Selection count remains unchanged
Confirmed workaround

Registering a keydown listener on window in the capture phase and calling cm.execCommand("singleSelectionTop") when multiple selections exist restores the expected behaviour.

Suggested fix

Please investigate the lifecycle and Escape handling of the comment floating toolbar's DismissableLayer.

The hidden toolbar should not consume Escape key events intended for CodeMirror. Unmounting or disabling the DismissableLayer while the toolbar is hidden may resolve the issue.

I can provide DevTools screenshots and additional debugging information if needed.

主要語言
沒有語言資料
星號
40
分支
9
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

hackmdio/hackmd-io-issues 的其他 Issue

查看 hackmdio/hackmd-io-issues 的全部 Issue

相似的 Issue

更多 Web Dev Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。