Gutter markers and "diffing"

I’ve been investigating a couple of usability issues in FF devtools (based on CM6). They both show a slightly different version of the same underlying issue: that gutter markers lack identity. See:

  1. Activating code block toggle button with keyboard make them lose their focus state
  2. Debugger editor gutter with cm6 traps keyboard navigation

In #1, the folding gutter marks are clickable buttons that can be activated by keyboard. When one does so, its DOM gets trashed since the only relevant state for them is the open flag. This causes the user to lose focus on the marker.

In #2, navigating the markers with Tab sometimes triggers a whole recalculation of gutter elements that trashes all markers, again losing the focused element.

For #1, I kind of see how one could vendor foldGutter() and cache markers so that toggling the open state only mutates the DOM. I’ve hacked something along this lines and it works.

However, for #2 I don’t really see a solution unless one vendors gutter() entirely, which (superficially) seems more burdensome that just foldGutter().

Is there a better approach that I’m missing? Is this a use case that CM could support out of the box?

Firstly, I’m very skeptical about this approach to making these buttons accessible. As issue 1915123 shows, this can make moving past the editor an absolute chore, because it will, on a big file, expose hundreds of focusable buttons. Also, I don’t really see a way for screen reader users to associate these buttons with actual editor content.

Since there are already key bindings for folding and unfolding code, aren’t those a much preferable mechanism for keyboard users to interact with this feature?

With issue 1901756, one approach might be to add support for something similar to WidgetType.updateDOM, to have markers that update themselves without re-rendering. But because the gutter currently, as you found, will reuse widgets across different positions when it can, we’d probably also need some option to turn that off.