cbrewster / brewcode

Brew(ster) code editor
MIT License
19 stars 3 forks source link

Support proper text selection and editing #7

Open cbrewster opened 4 years ago

cbrewster commented 4 years ago

Right now text insertion does not take into account text selection. I am not entirely sure what I want the text editing API to look like yet, but here is my idea for a first cut:

There should be a API which allows for a "span" of text to be replaced with a new span of text. Something like:

fn apply_edit(&mut self, span: Span, edit: &str) -> Location;

A span is two (row, col) pairs where the first pair precedes the second pair (in terms of location in the text buffer). The span can be empty, but represents a location. This is represented by the start and end pairs having the same value. The edit is a new string which replaces the text in the span. The function would return a the location of the start of the edit so that the cursor location can be updated.

One thing I want to do with this editor is experiment with different text editing approaches. I really like vim's modal approach but I think there is some room to create a more streamlined modal editor.