diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index c841fcba1..9a7ede24c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2747,6 +2747,53 @@ pub mod cmd { todo!() } + if args[0] == "topics" { + let dir_path = helix_core::runtime_dir().join("help/topics"); + let entries: Vec = std::fs::read_dir(dir_path) + .map(|entries| { + entries + .filter_map(|entry| { + let entry = entry.ok()?; + let path = entry.path(); + Some(path) + }) + .collect() + }) + .unwrap_or_default(); + + let callback = Box::pin(async move { + let call: job::Callback = + Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| { + let picker = FilePicker::new( + entries, + |path| { + path.file_stem() + .and_then(|s| s.to_str()) + .map(From::from) + .unwrap_or_default() + }, + |editor, path, action| { + if let Err(e) = editor.open(path.clone(), action).and_then(|id| { + editor + .document_mut(id) + .unwrap() + .set_path(None) + .map_err(Into::into) + }) { + editor.set_error(e.to_string()); + } + }, + |_editor, path| Some((path.clone(), None)), + ); + compositor.push(Box::new(picker)); + }); + Ok(call) + }); + cx.jobs.callback(callback); + + return Ok(()); + } + let help_dir; let command = { diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index adca5d9b4..8743054c2 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -262,7 +262,7 @@ pub mod completers { pub fn help(input: &str) -> Vec { let static_cmds_path = helix_core::runtime_dir().join("help/static-commands"); let typable_cmds_path = helix_core::runtime_dir().join("help/typable-commands"); - let commands: Vec = std::fs::read_dir(static_cmds_path) + let mut items: Vec = std::fs::read_dir(static_cmds_path) .map(|entries| { entries .filter_map(|entry| { @@ -288,10 +288,11 @@ pub mod completers { .collect() }) .unwrap_or_default(); + items.push("topics".to_owned()); let matcher = Matcher::default(); - let mut matches: Vec<_> = commands + let mut matches: Vec<_> = items .into_iter() .map(Cow::from) .filter_map(|name| matcher.fuzzy_match(&name, input).map(|score| (name, score))) diff --git a/runtime/help/topics/Words vs. WORDS.txt b/runtime/help/topics/Words vs. WORDS.txt new file mode 100644 index 000000000..ab1aa9b61 --- /dev/null +++ b/runtime/help/topics/Words vs. WORDS.txt @@ -0,0 +1,19 @@ +Words vs. WORDS + +Words and WORDS are two very similar types of text objects. A word +is a string of "word" characters, which include letters, numbers, +and underscores. A WORD, on the other hand, is any string of +non-whitespace characters. + +In the example below, the words are underlined by 'w', and the +WORDS are underlined by 'W'. + + This "stuff" is not-so difficult! + --------------------------------- + wwww wwwww ww www ww wwwwwwwww + WWWW WWWWWWW WW WWWWWW WWWWWWWWWW + +As is visible in the example, the words do not include any of the +non-alphanumeric punctuation, while the WORDS do include the +quotes, hyphen, and exclamation point. Also notice that 'not-so' +contains two words, but only one WORD.