-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add live preview to theme picker #1798
Add live preview to theme picker #1798
Conversation
A better way to approach this would be to implement live preview on |
Agreed, that seems like a good choice. I was going to fiddle with setting a smaller height to the picker, but the :theme command has that going for it naturally. I'll try poking around with that too! |
Removed the picker variant and kept the :command variant |
TIL flatmap on Option is called and_then
helix-editor/website#10 (comment) @the-mikedavis sorry for the wait! This is ready to be re-reviewed. (I had initially been distracted by Elden Ring if that's fair) |
helix-term/src/ui/prompt.rs
Outdated
#[repr(u8)] | ||
#[derive(Clone, Copy, PartialEq)] | ||
pub enum PromptEvent { | ||
/// The prompt input has been updated. | ||
Update, | ||
Update = 1 << 0, | ||
/// Validate and finalize the change. | ||
Validate, | ||
Validate = 1 << 1, | ||
/// Abort the change, reverting to the initial state. | ||
Abort, | ||
Abort = 1 << 2, | ||
} |
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.
Oh, I thought you are going to use bitflags
crate. That one is more ergonomic.
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.
I gave it a shot and it's a tad more complicated: If we make PromptEvent
itself bitflags, The match arms would only exhaust after all possible combinations of the flags. The TypeableCommand functions technically only can receive one type of event at once, thus causing this code:
match event {
PromptEvent::Abort => {},
PromptEvent::Update => {},
PromptEvent::Validate => {},
}
to error with:
|
607 | match event {
| ^^^^^ patterns `PromptEvent { bits: 0_u8 }`, `PromptEvent { bits: 3_u8 }` and `PromptEvent { bits: 5_u8..=u8::MAX }` not covered
|
I think at least for now, it seems more correct to not allow those other possibilities, so I went with a more traditional solution
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.
Looks good, awesome work @jharrilim !
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.
Is there any other typable commands we could live preview?
helix-term/src/commands/typed.rs
Outdated
/// Use `prompt_events` to declare which events this command will respond to. | ||
pub prompt_events: u8, |
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.
Is this really worth it? It adds extra complexity. I'd just always call the prompt
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.
And then return early inside the function. That way it behaves exactly like regex_prompt and other command prompts.
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.
I had that initially, but swapped to this approach to avoid touching the existing functions: #1798 (comment)
I don't think it's going to be a clean revert at this point unfortunately
8dfd840
I don't have strong opinions on either approach. If you confirm that you'd prefer what was done originally I'll change it back, but I'll only do it one more time or else I might get tendonitis 😳
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.
Yeah I'd prefer to handle these inside existing functions, it's a bit more flexible. Sorry for the trouble!
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.
Yeah I'd prefer to handle these inside existing functions, it's a bit more flexible. Sorry for the trouble!
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.
Switched it back, should be good to go!
For not-so-live-previews, I could imagine it might be nice a nice option for showing the contents of the clipboard if the size of the yank isn't too large. |
…ithub.com:jharrilim/helix into feat/add-theme-picker-with-live-preview-jharrilim
|
That's a good point! Feel free to exclude that from this initial PR though.
We do show a register preview window you can use when selecting registers before pasting ( |
Agreed, let's keep that separate, it'll be easier to review that way |
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.
Looks good to me.
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.
Thanks for working on this!
Tagging this here for posterity. PR for |
I'm probably annoying at this point, as I'm spamming this repo with my experiments. This one was fun though. It even reverts back to the original theme if you didn't select any. Perhaps it's a good start?
misc stuff:
Also added theme caching to reduce FS reads (although tbh it might be better to load them at the start)Added more callbacks to the pickerlast_theme
property is used now, this is useful for when a user cancels the theme preview so we can reset back to that theme