on master help sign in
Show infobox to hint textobjects with `mi` and `ma` (#1686)

* Show infobox to hint textobjects with `mi` and `ma` * Add note to infobox than any pair of characters will work too The wording could probably be a little more clear, but I wanted to keep it short but still accurate. * Don't allocate a vec for the static help text * Fix bug where `mi<esc>` would swallow next input and persist infobox * Better help text for arbitrary pair matching in textobject selection * Add way to add fake pending key data below status, use with `mi`/`ma` 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. * Return early on anything other than `mi` and `ma` for autoinfo * Remove "ascii" from help text with `mi` and `ma` * Update helix-term/src/ui/editor.rs Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>

commitb13d44156c0f2ebe700c4169e87839c976c4fedc authorDaniel S Poulin <dan.poulin@digitalsurgeons.com> dateMon 28 Feb 2022, 20:29 (5 years ago) parentbdbf423
3 files changed+34−1
helix-term/src/commands.rs+29−1 helix-term/src/ui/editor.rs+3 helix-view/src/editor.rs+2
helix-term/src/commands.rs+29−1
@@ -5353,7 +5353,10 @@ fn select_textobject_inner(cx: &mut Context) {
53535353
53545354fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
53555355 let count = cx.count();
5356+
53565357 cx.on_next_key(move |cx, event| {
5358+ cx.editor.autoinfo = None;
5359+ cx.editor.pseudo_pending = None;
53575360 if let Some(ch) = event.char() {
53585361 let textobject = move |editor: &mut Editor| {
53595362 let (view, doc) = current!(editor);
@@ -5402,7 +5405,32 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
54025405 textobject(cx.editor);
54035406 cx.editor.last_motion = Some(Motion(Box::new(textobject)));
54045407 }
5405− })
5408+ });
5409+
5410+ if let Some((title, abbrev)) = match objtype {
5411+ textobject::TextObject::Inside => Some(("Match inside", "mi")),
5412+ textobject::TextObject::Around => Some(("Match around", "ma")),
5413+ _ => return,
5414+ } {
5415+ let help_text = [
5416+ ("w", "Word"),
5417+ ("W", "WORD"),
5418+ ("c", "Class (tree-sitter)"),
5419+ ("f", "Function (tree-sitter)"),
5420+ ("p", "Parameter (tree-sitter)"),
5421+ ("m", "Matching delimiter under cursor"),
5422+ (" ", "... or any character acting as a pair"),
5423+ ];
5424+
5425+ cx.editor.autoinfo = Some(Info::new(
5426+ title,
5427+ help_text
5428+ .into_iter()
5429+ .map(|(col1, col2)| (col1.to_string(), col2.to_string()))
5430+ .collect(),
5431+ ));
5432+ cx.editor.pseudo_pending = Some(abbrev.to_string());
5433+ };
54065434}
54075435
54085436fn surround_add(cx: &mut Context) {
helix-term/src/ui/editor.rs+3
@@ -1211,6 +1211,9 @@ impl Component for EditorView {
12111211 disp.push_str(&s);
12121212 }
12131213 }
1214+ if let Some(pseudo_pending) = &cx.editor.pseudo_pending {
1215+ disp.push_str(pseudo_pending.as_str())
1216+ }
12141217 let style = cx.editor.theme.get("ui.text");
12151218 let macro_width = if cx.editor.macro_recording.is_some() {
12161219 3
helix-view/src/editor.rs+2
@@ -299,6 +299,7 @@ pub struct Editor {
299299
300300 pub idle_timer: Pin<Box<Sleep>>,
301301 pub last_motion: Option<Motion>,
302+ pub pseudo_pending: Option<String>,
302303
303304 pub exit_code: i32,
304305}
@@ -346,6 +347,7 @@ impl Editor {
346347 autoinfo: None,
347348 idle_timer: Box::pin(sleep(config.idle_timeout)),
348349 last_motion: None,
350+ pseudo_pending: None,
349351 config,
350352 auto_pairs,
351353 exit_code: 0,