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

Add pseudo_pending for t/T/f/F #4062

Merged
merged 2 commits into from
Oct 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,18 +1086,27 @@ fn extend_next_long_word_end(cx: &mut Context) {
extend_word_impl(cx, movement::move_next_long_word_end)
}

fn will_find_char<F>(cx: &mut Context, search_fn: F, inclusive: bool, extend: bool)
where
fn will_find_char<F>(
cx: &mut Context,
search_fn: F,
inclusive: bool,
extend: bool,
pseudo_pending: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

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

This can be a &'static str and then in the line below you can say cx.editor.pseudo_pending = Some(key.to_string()).

Copy link
Contributor Author

@mbStavola mbStavola Oct 2, 2022

Choose a reason for hiding this comment

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

Might be better to avoid specifying 'static here as there isn't a hard requirement for it, right? I imagine in the future, to @ath3 's point, we might want to support displaying the remapped keys (which wouldn't be 'static).

) where
F: Fn(RopeSlice, char, usize, usize, bool) -> Option<usize> + 'static,
{
// TODO: count is reset to 1 before next key so we move it into the closure here.
// Would be nice to carry over.
let count = cx.count();

cx.editor.pseudo_pending = pseudo_pending;

// need to wait for next key
// TODO: should this be done by grapheme rather than char? For example,
// we can't properly handle the line-ending CRLF case here in terms of char.
cx.on_next_key(move |cx, event| {
cx.editor.pseudo_pending = None;

let ch = match event {
KeyEvent {
code: KeyCode::Enter,
Expand Down Expand Up @@ -1200,35 +1209,35 @@ fn find_prev_char_impl(
}

fn find_till_char(cx: &mut Context) {
will_find_char(cx, find_next_char_impl, false, false)
will_find_char(cx, find_next_char_impl, false, false, Some("t".to_string()))
}

fn find_next_char(cx: &mut Context) {
will_find_char(cx, find_next_char_impl, true, false)
will_find_char(cx, find_next_char_impl, true, false, Some("f".to_string()))
}

fn extend_till_char(cx: &mut Context) {
will_find_char(cx, find_next_char_impl, false, true)
will_find_char(cx, find_next_char_impl, false, true, Some("vt".to_string()))
mbStavola marked this conversation as resolved.
Show resolved Hide resolved
}

fn extend_next_char(cx: &mut Context) {
will_find_char(cx, find_next_char_impl, true, true)
will_find_char(cx, find_next_char_impl, true, true, Some("vf".to_string()))
}

fn till_prev_char(cx: &mut Context) {
will_find_char(cx, find_prev_char_impl, false, false)
will_find_char(cx, find_prev_char_impl, false, false, Some("T".to_string()))
}

fn find_prev_char(cx: &mut Context) {
will_find_char(cx, find_prev_char_impl, true, false)
will_find_char(cx, find_prev_char_impl, true, false, Some("F".to_string()))
}

fn extend_till_prev_char(cx: &mut Context) {
will_find_char(cx, find_prev_char_impl, false, true)
will_find_char(cx, find_prev_char_impl, false, true, Some("vT".to_string()))
}

fn extend_prev_char(cx: &mut Context) {
will_find_char(cx, find_prev_char_impl, true, true)
will_find_char(cx, find_prev_char_impl, true, true, Some("vF".to_string()))
}

fn repeat_last_motion(cx: &mut Context) {
Expand Down