Skip to content

Unify druid & druid-shell selection types, rm src/text/selection.rs#1653

Merged
cmyr merged 1 commit intomasterfrom
unify-selection
Mar 19, 2021
Merged

Unify druid & druid-shell selection types, rm src/text/selection.rs#1653
cmyr merged 1 commit intomasterfrom
unify-selection

Conversation

@cmyr
Copy link
Member

@cmyr cmyr commented Mar 16, 2021

This removes the druid selection type, and adds any API on that type that was missing to druid-shell::Selection

@lord
Copy link
Contributor

lord commented Mar 18, 2021

A few thoughts/questions:

  • When I've implemented text editing before, I've modeled selections as having two h_poss, one for the active end and one for the anchor. But I'm struggling to actually find a case where this makes a difference, so it could be that these two representations are equivalent? If they are in fact equivalent, this way with just one seems maybe better? Not sure if you've thought too much about this or not.
  • How would a user create a selection with an h_pos of None?
  • I think the way this interacts with InputHandler::set_selection is worth documenting? (Should the input method be able to update the h_pos directly? I feel like not, right?) Similarly, maybe worth writing down if the input method can observe the h_pos, and the h_pos changes, does that result in Event::SelectionChanged, or (my vote) Event:: LayoutChanged
  • If these types are unified, you'll eventually want to add affinity as well, right? If Selection continues to grow, may want to do something to limit what the input method can access, or at least what it can implicitly set through set_selection

@cmyr
Copy link
Member Author

cmyr commented Mar 18, 2021

A few thoughts/questions:

  • When I've implemented text editing before, I've modeled selections as having two h_poss, one for the active end and one for the anchor. But I'm struggling to actually find a case where this makes a difference, so it could be that these two representations are equivalent? If they are in fact equivalent, this way with just one seems maybe better? Not sure if you've thought too much about this or not.

This is interesting, it would not have occurred to me to track the h-pos of the anchor edge, but now that you mention it you probably want to track the hpos of the secondary cursor, if you're doing BiDi.

  • How would a user create a selection with an h_pos of None?

h_pos is none by default; it is only set when there is a vertical movement.

edit: to clarify: I have added a constructor for Selection, and I'll mark it non_exhaustive to be clear.

  • I think the way this interacts with InputHandler::set_selection is worth documenting? (Should the input method be able to update the h_pos directly? I feel like not, right?) Similarly, maybe worth writing down if the input method can observe the h_pos, and the h_pos changes, does that result in Event::SelectionChanged, or (my vote) Event:: LayoutChanged

All explicit setting of the selection (that are not the product of vertical motion) clears h_pos, and h_pos is not part of visible selection state. Also it should not be possible to change h_pos without also changing some other aspect of the selection? In any case I don't think h_pos interacts with IME.

  • If these types are unified, you'll eventually want to add affinity as well, right? If Selection continues to grow, may want to do something to limit what the input method can access, or at least what it can implicitly set through set_selection

Yes, I was thinking of making this be our single selection type. I can't really think of a very good way to limit what is available to IME, but I do think it would be worth documenting the expectations a bit better.

Thanks for the notes, very happy to have another pair of eyes on some of this stuff!

@cmyr cmyr force-pushed the unify-selection branch from 3646a76 to cc20d1c Compare March 19, 2021 00:27
This lets us delete druid/src/text/selection.rs
@cmyr cmyr force-pushed the unify-selection branch from cc20d1c to 0f910f0 Compare March 19, 2021 00:31
@cmyr
Copy link
Member Author

cmyr commented Mar 19, 2021

@lord i added a bunch more docs based on your suggestions, thanks! I'm going to go ahead and merge this so I can start cleaning up some of the follow-up PRs. :)

@cmyr cmyr merged commit a281a81 into master Mar 19, 2021
@cmyr cmyr deleted the unify-selection branch March 19, 2021 01:30
@lord
Copy link
Contributor

lord commented Mar 19, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants