on master help sign in
Show infobox to hint textobjects with `mi` and `ma` (#1686)
b13d441Daniel S Poulin
helix-term/src/commands.rs+29−1
@@ -5353,7 +5353,10 @@ fn select_textobject_inner(cx: &mut Context) {
5353
5353
5354fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
5354fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
5355 let count = cx.count();
5355 let count = cx.count();
5356+
5356 cx.on_next_key(move |cx, event| {
5357 cx.on_next_key(move |cx, event| {
5358+ cx.editor.autoinfo = None;
5359+ cx.editor.pseudo_pending = None;
5357 if let Some(ch) = event.char() {
5360 if let Some(ch) = event.char() {
5358 let textobject = move |editor: &mut Editor| {
5361 let textobject = move |editor: &mut Editor| {
5359 let (view, doc) = current!(editor);
5362 let (view, doc) = current!(editor);
@@ -5402,7 +5405,32 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
5402 textobject(cx.editor);
5405 textobject(cx.editor);
5403 cx.editor.last_motion = Some(Motion(Box::new(textobject)));
5406 cx.editor.last_motion = Some(Motion(Box::new(textobject)));
5404 }
5407 }
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+ };
5406}
5434}
5407
5435
5408fn surround_add(cx: &mut Context) {
5436fn surround_add(cx: &mut Context) {
helix-term/src/ui/editor.rs+3
@@ -1211,6 +1211,9 @@ impl Component for EditorView {
1211 disp.push_str(&s);
1211 disp.push_str(&s);
1212 }
1212 }
1213 }
1213 }
1214+ if let Some(pseudo_pending) = &cx.editor.pseudo_pending {
1215+ disp.push_str(pseudo_pending.as_str())
1216+ }
1214 let style = cx.editor.theme.get("ui.text");
1217 let style = cx.editor.theme.get("ui.text");
1215 let macro_width = if cx.editor.macro_recording.is_some() {
1218 let macro_width = if cx.editor.macro_recording.is_some() {
1216 3
1219 3
helix-view/src/editor.rs+2
@@ -299,6 +299,7 @@ pub struct Editor {
299
299
300 pub idle_timer: Pin<Box<Sleep>>,
300 pub idle_timer: Pin<Box<Sleep>>,
301 pub last_motion: Option<Motion>,
301 pub last_motion: Option<Motion>,
302+ pub pseudo_pending: Option<String>,
302
303
303 pub exit_code: i32,
304 pub exit_code: i32,
304}
305}
@@ -346,6 +347,7 @@ impl Editor {
346 autoinfo: None,
347 autoinfo: None,
347 idle_timer: Box::pin(sleep(config.idle_timeout)),
348 idle_timer: Box::pin(sleep(config.idle_timeout)),
348 last_motion: None,
349 last_motion: None,
350+ pseudo_pending: None,
349 config,
351 config,
350 auto_pairs,
352 auto_pairs,
351 exit_code: 0,
353 exit_code: 0,