-
Notifications
You must be signed in to change notification settings - Fork 140
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
Floem editor #296
Floem editor #296
Conversation
a284c65
to
bd5ac75
Compare
Hi, I have packaged this view up into a standalone repo here: https://github.com/dparnell/floem-editor-view/ |
e3d666b
to
c4722c0
Compare
|
||
impl MoveCommand { | ||
pub fn to_movement(&self, count: Option<usize>) -> Movement { | ||
use MoveCommand::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just reading through the code and noticed this. Not necessarily super important.
Using use enum::*
can be a pretty bad idea.
If we were to ever remove one of the variants from MoveCommand it wouldn't cause a compiler error and that variant would then act as a catch all that matches all other patterns. So then if another command was added it would be matched under that variant.
It's generally better to do use MoveCommand as MC
or some other short name. This adds the convenience of the short name and doesn't cause the same issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be caught by Rust warnings because it would be unused.
(Minor, but this is how it is done in Lapce)
Also I don't think clippy is actually running on most/all of the added code because it is under a non-default feature. Probably the CI / Rust isn't building with the features either. |
Maybe add editor to default features? |
I think there's some benefit to having it non-default, as it makes so widget-crates won't accidentally leave it enabled, but also text inputs are pretty common, so I'll just add it to default features. |
This PR breaks the core editor portion of Lapce out into a separate module.
The editor being a separate module allows it to be used by other programs that utilize Floem, allowing us to share the improvements (and testing, which this makes simpler) between the two.
The basic idea is that it should be extensible (or, replaceable, like copying & pasting with modifications the view creation functions) enough to use in Lapce without too much work, while also not being very noisy with extension points that are painful to maintain stability.
This was initially developed as a crate in the Lapce repo, but discussion with dzhou ended up with deciding on putting it in floem (under a feature flag). See lapce/lapce#2909 for the Lapce PR which has most of the git history as well.
The primary trait is
Document
. It provides text (the xi-ropeRope
), cache revision, IME preedit, screen lines, running commands, and some more.Lapce's
Document
(now namedDoc
to avoid name collisions) would impl this trait, and be pretty close to what it once was.Of note is that unlike the original Lapce
Document
the doc does not handle text layout creation directly, merely specifying how the text layout should be styled.The movement logic supports modal mode movement, as I don't see a good way to cleanly separate them, but the default keymap does not support modal mode.
An
Editor
is in a way the data for the view into a document. Each distinct input box is a differentEditor
(data) +EditorView
(view). Multiple editors can use the same document, automatically mirroring changes across them while allowing different styling or altered behavior in the other editor.Room for improvement:
Styling
.strum
under a feature since we only really have that for Lapce's benefit?Rc<Doc>
which the constructor then turns into anRwSignal<Rc<Doc>>
, does that actually provide any benefit now? Can we just swap that out with having every editor into a doc sharing theRwSignal
rather than just theRc
?Document
because we want it shared between different editors. However it would be nice to make it automatically handled somehow?text.len()
RopeText
would work, but be very noisy.Rc<dyn RopeText>
(after modifyingRopeText
to be object-safe) would work, though I think we should worry about how much some logic directly benefits from inlining multiple operations done to the same text!RwSignal<dyn Document>
which is then downcasted toRwSignal<Doc>
, because the caller wants to use their specific type?SimpleStyleBuilder
?Styling
trait. However we could just say 'whatever' and have name collisions like that since ~most users aren't going to have theStyling
trait in the same scope.TextDocument
has editor-specific command listeners