Text editing: multi-part compatible TextIndex, PartList, algorithms#696
Conversation
dhardy
left a comment
There was a problem hiding this comment.
Several things are left incomplete in this PR; nevertheless I'm happy with the general shape and would like to get this merged.
| pub struct Part { | ||
| part: u32, // part index |
There was a problem hiding this comment.
PartList impls need to set/update the part index
| // TODO(opt): should we use dyn PartList to reduce code size? | ||
| pub fn handle_event( | ||
| &mut self, | ||
| parts: &mut impl PartList, |
There was a problem hiding this comment.
There will probably be two PartList impls eventually. This function and cmd_action are large, therefore using dyn PartList may save code size, though it may not be worthwhile. Currently this is blocked by usage of impl Trait within PartList methods.
| anchor.byte = r.anchor.cast(); | ||
| cursor.byte = r.cursor.cast(); | ||
| } else { | ||
| // TODO |
There was a problem hiding this comment.
Multi-line drag-selection in double-click (word) and triple-click (line) modes is currently unimplemented (see also TODO above).
| } | ||
| } | ||
| Action::Move(p, None) | ||
| // TODO: prev |
There was a problem hiding this comment.
Word-mode left/right navigation across parts is not yet implemented
| _ => 0, | ||
| }; | ||
| part.display | ||
| // TODO: prev/next |
There was a problem hiding this comment.
Up/down navigation across parts is not yet implemented
| } | ||
| Command::Home if cursor > 0 => { | ||
| let index = part | ||
| // TODO: we don't need to use find_line if each part represents a line |
There was a problem hiding this comment.
We should be able to simplify the code once we have a 1 part = 1 line relationship.
Further work towards scalable text editors:
TextIndextype (part, byte)PartList, with an impl for a singlePartTextIndexto represent the cursor index / selectionSome sub-systems like undo support and click-to-text-index translation have been updated to support multi-part editors (untested); some other sub-systems have not been (TODO comments present).