linebender / parley

Rich text layout library
Apache License 2.0
158 stars 18 forks source link

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

Open PoignardAzur opened 1 month ago

PoignardAzur commented 1 month ago

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:

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.