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

Ouverte
#445 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
22/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
javascript
Domaine
frontend

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

  • 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.

Langage dominant
Aucune donnée de langage
Étoiles
40
Forks
9
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de hackmdio/hackmd-io-issues

Toutes les issues de hackmdio/hackmd-io-issues

Issues similaires

Plus d'issues Web Dev

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.