Rethink code navigation with CodeMirror token selection #44698
Rethink code navigation with CodeMirror token selection #44698
Conversation
Bundle size report 📦
Look at the Statoscope report for a full comparison between the commits a443d8d and 63ba073 or learn more. Open explanation
|
8e4738a to
46373c7
Compare
46373c7 to
eeea627
Compare
45de7a2 to
96a8d2a
Compare
|
I prematurely marked this PR as ready for review. I'm very happy with the functionality, but I'm planning to self-review the diff on Monday and clean up the code before tagging people for review. |
There was a problem hiding this comment.
@limitedmage Can you advice on the most appropriate role for the blob view? The "region" role did not work well with hjlk navigation.
There was a problem hiding this comment.
I don't think main would be valid here, because we are using a <main> element in AppRouterContainer, which wraps the blob view. According to the MDN docs:
There should only be one
mainlandmark role per document.The
<main>element has a role of main. Developers should use semantic HTML — in this case<main>— over using ARIA.
Can you elaborate more on what didn't work well when it was still region?
There was a problem hiding this comment.
You're totally right that main is inappropriate. I've reverted this change so that it's region again. Selection driven navigation will need more iterations to get accessibility right. When I tried hjkl navigation with the region role then VoiceOver didn't speak out the selection.
There was a problem hiding this comment.
I think region is fine. Does it show up in the Landmarks menu? (VoiceOver+U, use left/right arrows to go between menus).
Previously, the token cursor feature flag used HTML href links for go to definition. This commit changes the behavior of the feature flag to use CodeMirror selections instead along with several other big changes: * Cmd+Click for Go to definition * Enter for Go to definition * Space for Show popover * Right-click menu for Go to definition and Find references * Up/Down/Right/Left arrow to move the selection to the next token Demo https://www.loom.com/share/a0fa53badd4d419081dcfd1a2fbc7e4e Please give it a try and let us know what you think.
6a4fb1e to
9878e6a
Compare
|
Not notifying subscribers because the number of notifying subscribers (20) has exceeded the threshold (10). |
|
Codenotify: Notifying subscribers in OWNERS files for diff 50fe3e7...a443d8d. No notifications. |
bda0b57 to
0cfe883
Compare
|
OK, we have a green CI and this PR is ready for review. I've cleaned up the implementation and I'm very(!) happy with the functionality. A few highlights of the changes since I recorded the Loom:
I'm eager to get this PR merged so that we can collect more feedback before deciding what to do with this feature flag. |
|
This is awesome - I will make time to take a look at it tomorrow! (cc @sourcegraph/code-exploration for visibility) @olafurpg Would you be able to compare the work you've done against the items listed in this tracking issue and note which issues you think it should close in the PR? |
|
@felixfbecker Have you tried with |
|
@lrhacker This PR enables keyboard navigation but I don't think the solution is fully accessible as is. When using VoiceOver, the currently selected token is read out but you have to use hjkl navigation instead of up/down/right/left. To achieve this, I made a small change to use the |
|
Great work, @olafurpg! Here are some comments and random thoughts I had while testing it.
I haven't tested these changes from the accessibility standpoint, will do it shortly. |
|
A few different chunks of feedback and comments so far. I like @taras-yemets's table but this might be a little verbose for columns (sorry 😅). From that tracking issue I linked, I do think this satisfies #43175, in that its goal is to include up/down/left/right keyboard navigation. The primary difference from the acceptance criteria I see is that up/down navigation now focuses on a single token, whereas what @umpox had prototyped originally was selecting just line to start with (and left/right navigation would start token selection). One question: in your Loom it appears that the current line is highlighted along with the token, but I'm not seeing that locally - is that an expected change? (I personally prefer to see the line highlight so it's easier to see where I am.) For #42421 from the tracking issue, while I wouldn't expect this PR itself to include tab-driven navigation, that is something I find myself wanting. Or, maybe more specifically, I want to make sure that pressing Currently, if At this point, the goal would just be to make sure we aren't intentionally doing anything in this PR that would make supporting tab-driven navigation prohibitively challenging in the future. The RFC that @taras-yemets linked above will also be something to consider and be a good place to discuss what specific keyboard interactions we want to settle on. Not that we can't differ from what's in the RFC today, but it will be good to make sure we're all in agreement with what is expected (e.g. should Side note: one specific interaction specified in the RFC that I found myself missing here, though, is using In terms of accessibility, I still need to do more testing, but I think we'll need to keep iterating on interactions with VoiceOver (or, more generally, all screen readers) over time. At the very least, it's not always the simplest problem to solve on the first pass. When I did a very quick test, using the actual VoiceOver controls for navigation (e.g., Ctrl + Opt + Right arrow) does not selecting things as expected (the entire row of text is selected/read). I still need to do more research on standards around supporting specific screen reader controls, versus having other keyboard-based navigation available (e.g. h/j/k/l) that works in tandem with the reader to announce something meaningful. @limitedmage do you happen to have any resources on this? That being said, there are almost certainly some things we can do using ARIA roles to better describe the tokens. The first thing that comes to mind would be to use something like the Lastly, like @taras-yemets mentioned, the intel popover does not close when you begin navigating again. I think the preferred interaction for now would actually be to close it when you start navigating again, because it easily has the potential to cover/hide where the selection has moved to, like so: |
client/web/src/repo/blob/codemirror/token-selection/modifier-click.ts
Outdated
Show resolved
Hide resolved
client/web/src/repo/blob/codemirror/tooltips/CodeIntelTooltip.tsx
Outdated
Show resolved
Hide resolved
822e389 to
e80d425
Compare
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff 50fe3e7...a443d8d. No notifications. |
|
@taras-yemets Thank you for the detailed review. Thanks to your suggestions, I was able to remove Can you please repost your accessibility comment in https://github.com/sourcegraph/sourcegraph/issues/45006 ? It's outside the scope of this PR to fix accessibility. |
The new selection-driven code nav UI (https://github.com/sourcegraph/sourcegraph/pull/44698) does not use this.
The new selection-driven code nav UI (https://github.com/sourcegraph/sourcegraph/pull/44698) does not use this.
The new selection-driven code nav UI (https://github.com/sourcegraph/sourcegraph/pull/44698) does not use this.
The new selection-driven code nav UI (https://github.com/sourcegraph/sourcegraph/pull/44698) does not use this.
The new selection-driven code nav UI (https://github.com/sourcegraph/sourcegraph/pull/44698) does not use this.
The new selection-driven code nav UI (https://github.com/sourcegraph/sourcegraph/pull/44698) does not use this.
In the web app, the new selection-driven code nav UI (https://github.com/sourcegraph/sourcegraph/pull/44698) does not use this. The browser extension's implementation is separate from the web app's in implementation and backstory, but it is also removed because it presents the same future UX problems and is inconsistent with the direction we're taking for the web app.
In the web app, the new selection-driven code nav UI (https://github.com/sourcegraph/sourcegraph/pull/44698 https://github.com/sourcegraph/sourcegraph/pull/48066) does not use this. The browser extension's implementation is separate from the web app's in implementation and backstory, but it is also removed because it presents the same future UX problems and is inconsistent with the direction we're taking for the web app. ## Test plan Ensure code navigation in the remaining selection-driven mode still works.









Previously, the token cursor feature flag used HTML href links for go to definition. This commit changes the behavior of the feature flag to use CodeMirror selections instead along with several other big changes:
Demo https://www.loom.com/share/a0fa53badd4d419081dcfd1a2fbc7e4e
Changes since the demo was recorded
Please give it a try and let us know what you think.
TODOs before this PR is ready for review:
Improvements for the future: see https://github.com/sourcegraph/sourcegraph/issues/45006
Test plan
To test it manually with a local build. First start the server. Note that it's not possible to use
web-standalone.Next, update setting
"experimentalFeatures": {"codeNavigation": "selection-driven"}}.App preview:
Check out the client app preview documentation to learn more.