Skip to content

Commit

Permalink
Add way to add fake pending key data below status, use with mi/ma
Browse files Browse the repository at this point in the history
This is a bit hacky as it makes use of global state which will end
up managed in multiple places, but has precedent in the way autoinfo
works. There should probably be a bigger refactor to handle this
kind of state better.
  • Loading branch information
EpocSquadron committed Feb 21, 2022
1 parent d4d19b1 commit b97d9bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5346,6 +5346,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {

cx.on_next_key(move |cx, event| {
cx.editor.autoinfo = None;
cx.editor.pseudo_pending = None;
if let Some(ch) = event.char() {
let textobject = move |editor: &mut Editor| {
let (view, doc) = current!(editor);
Expand Down Expand Up @@ -5396,9 +5397,9 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
}
});

if let Some(title) = match objtype {
textobject::TextObject::Inside => Some("Match inside"),
textobject::TextObject::Around => Some("Match around"),
if let Some((title, abbrev)) = match objtype {
textobject::TextObject::Inside => Some(("Match inside", "mi")),
textobject::TextObject::Around => Some(("Match around", "ma")),
textobject::TextObject::Movement => None,
} {
let help_text = [
Expand All @@ -5418,6 +5419,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
.map(|(col1, col2)| (col1.to_string(), col2.to_string()))
.collect(),
));
cx.editor.pseudo_pending = Some(abbrev.to_string());
};
}

Expand Down
3 changes: 3 additions & 0 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,9 @@ impl Component for EditorView {
disp.push_str(&s);
}
}
if let Some(pseudo_pending) = &cx.editor.pseudo_pending {
disp.push_str(&*pseudo_pending)
}
let style = cx.editor.theme.get("ui.text");
let macro_width = if cx.editor.macro_recording.is_some() {
3
Expand Down
2 changes: 2 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ pub struct Editor {

pub idle_timer: Pin<Box<Sleep>>,
pub last_motion: Option<Motion>,
pub pseudo_pending: Option<String>,

pub exit_code: i32,
}
Expand Down Expand Up @@ -336,6 +337,7 @@ impl Editor {
autoinfo: None,
idle_timer: Box::pin(sleep(config.idle_timeout)),
last_motion: None,
pseudo_pending: None,
config,
exit_code: 0,
}
Expand Down

0 comments on commit b97d9bf

Please sign in to comment.