linebender / linebender/piet

cursor position, leading/trailing and affinity

Open
#323 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question text
Dominant language
Rust
Stars
1.4k
Forks
98
PR merge metrics
No merged PRs in 30d

Description

I ran into an issue in piet-coregraphics where `hit_test_position` wasn't respecting trailing newlines, and this has led me down a bit of a rabbit hole. In particular, I'm curious that there doesn't seem to be any concept of leading/trailing or upstream/downstream here? Is this an oversight, or am I missing something?

As an illustration, imagine the text "AAA BBB" with a soft break, so lines are "AAA " and "BBB". If I hit-test position 4, both "AAA |" and "|BBB" are valid. Is there some trick I'm missing? This doesn't seem to be as much of an issue on piet-d2d, although I haven't been able to play around there quite as much.

I'm pretty sure I could implement this in piet as some kind of `cursor_pos_for_point` method, because then I could ensure I take the line of the point into account when choosing my position instead of resolving to a string index and resolving from that back to a point, which is lossy?

Contributor guide

Open the contributing guide

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.

Research direction

Start by examining hit_test_position in piet-coregraphics and comparing its behavior with piet-d2d, especially for trailing newlines and soft breaks. Review the proposed cursor_pos_for_point direction and the issue's leading/trailing or upstream/downstream questions. Done means the desired cursor-position and affinity behavior is defined clearly enough to assess across the backends.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.