More accurate node selection expansion

Open
#219 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
frontend

Research direction

Trace the editor's onkeydown handling for Shift+Up/Down and the render_selection behavior described in the issue. Preserve the original selection anchor while moving focus by one node in either direction, including reverse selections, and verify that repeated movement restores the expected text selection.

Written by the indexing model from the issue text.

Description

Given an active node selection pressing shift+down you'd expect to select the next node. However you have to press several times because the selection just follows the native behavior, e.g. set the selection focus to the next line.

In order to improve that I can't just handle shift+down and update our model selection by one offset, because this way you will loose our original selection anchor (it will just end up somewhere else).

E.g. think of this:

  • start the selection drag inside a 2-line text property
  • drag to the second line (still a text selection)
  • now press shift+down (now we have a node selection of that element)
  • now press shift+down again (another node gets selected because of our special handling)
  • now press shift+up and again shift+up (now you'd expect the original 2 line text selection) but that is destroyed now because after special-handling the shift+down a selection rerender happens which selects the entire node (as per implementation of render_selection)

However, what I can do is handle an onkeydown if shift+up/down but instead of updating the model selection, i can find a suitable new DOM selection that matches what the user expects. Basically we will leave the selection anchor untouched and just move the selection focus somewhere into the next node

Of course this needs to work accurately for reverse selections, where shift+up will move the focus up and shift+down will move the focus down by one node. There are likely some edge cases, but I think this can be managed and it will improve the user experience for heavy keyboard users.

Dominant language
TypeScript
Stars
691
Forks
20
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from michael/svedit

All issues in michael/svedit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.