diff options
author | JJ | 2023-11-01 03:55:00 +0000 |
---|---|---|
committer | JJ | 2023-11-01 04:08:59 +0000 |
commit | a4394d502f8ee551660af5c8f04545cca349efb9 (patch) | |
tree | 14c1bbb3e9d9ce56e5168a123bd45dae8fde4810 /helix-term | |
parent | 49b1f2a869be199aaba97e6a4d74995c5161d7b0 (diff) |
Add support for Unicode input
note: a better approach is here https://github.com/quantonganh/snippets-ls
ref: https://github.com/helix-editor/helix/issues/1438
ref: https://github.com/helix-editor/helix/pull/2852
Co-authored-by: Linden Krouse <ztaticnull@gmail.com>
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 48 | ||||
-rw-r--r-- | helix-term/src/keymap/default.rs | 2 |
2 files changed, 50 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index cac86adb..87f1c178 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -494,6 +494,7 @@ impl MappableCommand { command_palette, "Open command palette", open_or_focus_explorer, "Open or focus explorer", reveal_current_file, "Reveal current file in explorer", + insert_digraph, "Insert Unicode characters with prompt", ); } @@ -6020,3 +6021,50 @@ fn replay_macro(cx: &mut Context) { cx.editor.macro_replaying.pop(); })); } + +fn insert_digraph(cx: &mut Context) { + ui::prompt( + cx, + "digraph:".into(), + Some('K'), // todo: decide on register to use + move |editor, input| { + editor + .config() + .digraphs + .search(input) + .take(10) + .map(|entry| { + // todo: Prompt does not currently allow additional text as part + // of it's suggestions. Show the user the symbol and description + // once prompt has been made more robust + #[allow(clippy::useless_format)] + ((0..), Cow::from(format!("{}", entry.sequence))) + }) + .collect() + }, + move |cx, input, event| { + match event { + PromptEvent::Validate => (), + _ => return, + } + let config = cx.editor.config(); + let symbols = if let Some(entry) = config.digraphs.get(input) { + &entry.symbols + } else { + cx.editor.set_error("Digraph not found"); + return; + }; + + let (view, doc) = current!(cx.editor); + let selection = doc.selection(view.id); + let mut changes = Vec::with_capacity(selection.len()); + + for range in selection.ranges() { + changes.push((range.from(), range.from(), Some(symbols.clone().into()))); + } + let trans = Transaction::change(doc.text(), changes.into_iter()); + doc.apply(&trans, view.id); + doc.append_changes_to_history(view); + }, + ) +} diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 9b93c573..0a48f18e 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -137,6 +137,8 @@ pub fn default() -> HashMap<Mode, KeyTrie> { "N" => search_prev, "*" => search_selection, + "\\" => insert_digraph, + "u" => undo, "U" => redo, "A-u" => earlier, |