Skip to content

Text editing: multi-part compatible TextIndex, PartList, algorithms#696

Merged
dhardy merged 17 commits into
masterfrom
push-oyrqnlrmquns
May 24, 2026
Merged

Text editing: multi-part compatible TextIndex, PartList, algorithms#696
dhardy merged 17 commits into
masterfrom
push-oyrqnlrmquns

Conversation

@dhardy
Copy link
Copy Markdown
Collaborator

@dhardy dhardy commented May 23, 2026

Further work towards scalable text editors:

  • Add TextIndex type (part, byte)
  • Add trait PartList, with an impl for a single Part
  • Use TextIndex to represent the cursor index / selection

Some 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).

@dhardy dhardy force-pushed the push-oyrqnlrmquns branch from ad7e287 to 103947b Compare May 24, 2026 08:21
Copy link
Copy Markdown
Collaborator Author

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several things are left incomplete in this PR; nevertheless I'm happy with the general shape and would like to get this merged.

Comment on lines 182 to +183
pub struct Part {
part: u32, // part index
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PartList impls need to set/update the part index

Comment on lines +1216 to +1219
// TODO(opt): should we use dyn PartList to reduce code size?
pub fn handle_event(
&mut self,
parts: &mut impl PartList,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Word-mode left/right navigation across parts is not yet implemented

_ => 0,
};
part.display
// TODO: prev/next
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to simplify the code once we have a 1 part = 1 line relationship.

@dhardy dhardy merged commit 3d1452c into master May 24, 2026
5 checks passed
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.

1 participant