Skip to content
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

Actually split mi and ma into several subcommands #1723

Closed
wants to merge 10 commits into from

Conversation

The0x539
Copy link
Contributor

@The0x539 The0x539 commented Mar 1, 2022

Well, this was poorly timed.

Adds a fallback field to KeyTrieNode, used for surround pairs as discussed. For that command to actually work, I added a last_key field to Context.

Outstanding concerns:

  • Should last_key be on Editor instead?
  • Does a better approach come to mind?
  • How can select_*_pair be used from the command palette?
  • How should fallbacks be represented in config.toml?

helix-term/src/commands.rs Outdated Show resolved Hide resolved
@archseer
Copy link
Member

Note: I have some simplifications of the Keymap/Keymaps structs here #1803, I'd like to merge that first then rebase this PR

@archseer
Copy link
Member

Ended up pushing the changes to master: 7909d6f a7ee9f7

@The0x539
Copy link
Contributor Author

Ended up rewriting the changes. The general design is pretty much the same, except some of the command palette reverse_map stuff is a bit cleaner and I added an abstraction to Compositor that I noticed ought to exist. The old version is still available on my mi-ma-rework-v1 branch.

Comment on lines +677 to +694
"a" => { "Select around"
"w" => select_around_word,
"W" => select_around_long_word,
"c" => select_around_class,
"f" => select_around_function,
"a" => select_around_parameter,
"m" => select_around_cursor_pair,
_ => select_around_pair,
},
"i" => { "Select inside"
"w" => select_inside_word,
"W" => select_inside_long_word,
"c" => select_inside_class,
"f" => select_inside_function,
"a" => select_inside_parameter,
"m" => select_inside_cursor_pair,
_ => select_inside_pair,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I was looking into doing something like this.

pub struct FallbackCommand {
pub name: &'static str,
pub fun: fn(cx: &mut Context, event: KeyEvent),
pub with_prompt: MappableCommand,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need with_prompt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For use in reverse_map, so that the binding for the fallback command shows up for its prompting version in the command palette. I suppose it could be left out, but I think the binding should really show up in the palette. It could also be just the name instead, since that's what ultimately ends up getting used.

At one point, I tried to come up with a way to have just a prompt message that'd allow for the "generation" of an appropriately structured function, but I couldn't figure that out. Doing that might require a third MappableCommand variant, and I'm not sure that's super worth looking into.

Copy link
Contributor

@pickfire pickfire Mar 22, 2022

Choose a reason for hiding this comment

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

Is it possible not have it behaves like a command without needing any prompt? I don't see why we need to prompt here given that it can be used like any other key already. At least in my own opinion, the prompt could be a separate thing.

Copy link
Member

@sudormrfbin sudormrfbin left a comment

Choose a reason for hiding this comment

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

It would've been easier to review if some of the changes like getting the editor view from the compositor were split off into separate PRs, but looks okay otherwise.

Comment on lines +586 to +603
impl std::str::FromStr for FallbackCommand {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
FallbackCommand::FALLBACK_COMMAND_LIST
.iter()
.find(|cmd| cmd.name() == s)
.cloned()
.ok_or_else(|| anyhow!("No command named '{}'", s))
}
}

impl<'de> Deserialize<'de> for FallbackCommand {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let s: &'de str = Deserialize::deserialize(deserializer)?;
s.parse().map_err(de::Error::custom)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we can pass on deserializing fallback commands from the config for now since that's better supported via scripting in the future.

Comment on lines +4026 to 4030
enum TextObjectSelector {
Word(bool),
Treesitter(&'static str),
Matching(Option<char>),
}
Copy link
Member

Choose a reason for hiding this comment

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

A separate LongWord variant would be clearer instead of a bool.

Comment on lines +4118 to +4120
fn select_around_pair(cx: &mut Context, event: KeyEvent) {
select_pair(cx, textobject::TextObject::Around, event);
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather this be called select_around_pair_fallback and prompt_and_select_around_pair be called select_around_pair.

.find(|component| component.id() == Some(id))
.and_then(|component| component.as_any_mut().downcast_mut())
.filter(|component| component.id() == Some(id))
.find_map(|component| component.as_any_mut().downcast_mut::<T>())
Copy link
Member

Choose a reason for hiding this comment

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

This change seems unnecessary ?

Comment on lines +605 to +609
impl PartialEq for FallbackCommand {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Seems more accurate to compare both name and function pointers?

@the-mikedavis the-mikedavis added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 18, 2022
@kirawi kirawi added A-helix-term Area: Helix term improvements S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 13, 2022
@pascalkuthe
Copy link
Member

would like to still see this altough I would prefer a different approach (that will require much less invasive changes). That said this PR has gone stale with lots of conflicts and still has undressed comments so I am going to close this out. Thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants