aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorLinden Krouse2024-05-01 21:22:02 +0000
committerJJ2024-05-01 23:54:41 +0000
commitbbc1a3cc99644e5be1030b5ed8d51928c821b866 (patch)
tree2c15ffd41c6af83844a3c56b59e3ba14e10154e7 /helix-term
parentcd2202fd54e5458371f8f15c149686f6c0933a9e (diff)
Add support for Unicode input
ref: https://github.com/helix-editor/helix/issues/1438 ref: https://github.com/helix-editor/helix/pull/2852
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs48
-rw-r--r--helix-term/src/keymap/default.rs2
2 files changed, 50 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 2094aafe..c9874e8c 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -511,6 +511,7 @@ impl MappableCommand {
extend_to_word, "Extend to a two-character label",
open_or_focus_explorer, "Open or focus explorer",
reveal_current_file, "Reveal current file in explorer",
+ insert_digraph, "Insert Unicode characters with prompt",
);
}
@@ -6268,3 +6269,50 @@ fn jump_to_word(cx: &mut Context, behaviour: Movement) {
}
jump_to_label(cx, words, behaviour)
}
+
+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 5b165613..3cd4c0e3 100644
--- a/helix-term/src/keymap/default.rs
+++ b/helix-term/src/keymap/default.rs
@@ -138,6 +138,8 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
"N" => search_prev,
"*" => search_selection,
+ "\\" => insert_digraph,
+
"u" => undo,
"U" => redo,
"A-u" => earlier,