Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add infrastructure to Parley to facilitate text selection/editing #52

Open
PoignardAzur opened this issue May 11, 2024 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@PoignardAzur
Copy link
Contributor

PoignardAzur commented May 11, 2024

We want Parley to implement types and methods that Masonry and other editors will be able to use to create a text-editing widget, or to handle selection in non-editable text.

After some discussion we've settled on the following:

  • A TextMovement enum representing different possible changes to a text edit's selection and content. Possible variants might be eg MoveLeft, MoveToNextWord, SelectToNextParagraph, RemovePreviousWord, etc.
  • A function that maps a String, a cursor position(/span) and a TextMovement to a StringDiff and position(/span). That function essentially tells you "if you do that, here's how the text will change and where your cursor will be next".
  • Later down the road, once we want to implement spans, a function that maps a span and a StringDiff to an optional span.

Possible signatures:

enum TextMovement {
  MoveLeft,
  MoveRight,
  // ...
}

struct StringDiff {
  removed_span: usize..usize,
  new_position: usize,
  added_text: String,
}

fn apply_movement(string: &str, movement: TextMovement, byte_offset: usize) -> StringDiff;

fn map_span(span: usize..usize, diff: StringDiff) -> Option<usize..usize>;

We night use Parley's Cursor type instead of byte offsets in these interfaces.

@xorgy xorgy self-assigned this May 14, 2024
@nicoburns nicoburns added the enhancement New feature or request label May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants