|
|
@ -40,6 +40,7 @@ use crate::{
|
|
|
|
|
|
|
|
|
|
|
|
use crate::job::{self, Job, Jobs};
|
|
|
|
use crate::job::{self, Job, Jobs};
|
|
|
|
use futures_util::{FutureExt, TryFutureExt};
|
|
|
|
use futures_util::{FutureExt, TryFutureExt};
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::{fmt, future::Future};
|
|
|
|
use std::{fmt, future::Future};
|
|
|
|
|
|
|
|
|
|
|
|
use std::{
|
|
|
|
use std::{
|
|
|
@ -76,6 +77,16 @@ impl<'a> Context<'a> {
|
|
|
|
self.on_next_key_callback = Some(Box::new(on_next_key_callback));
|
|
|
|
self.on_next_key_callback = Some(Box::new(on_next_key_callback));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
|
|
|
pub fn on_next_key_mode(&mut self, map: HashMap<KeyEvent, fn(&mut Context)>) {
|
|
|
|
|
|
|
|
self.on_next_key(move |cx, event| {
|
|
|
|
|
|
|
|
cx.editor.autoinfo = None;
|
|
|
|
|
|
|
|
if let Some(func) = map.get(&event) {
|
|
|
|
|
|
|
|
func(cx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[inline]
|
|
|
|
pub fn callback<T, F>(
|
|
|
|
pub fn callback<T, F>(
|
|
|
|
&mut self,
|
|
|
|
&mut self,
|
|
|
@ -3406,84 +3417,95 @@ macro_rules! mode_info {
|
|
|
|
// TODO: how to use one expr for both pat and expr?
|
|
|
|
// TODO: how to use one expr for both pat and expr?
|
|
|
|
// TODO: how to use replaced function name as str at compile time?
|
|
|
|
// TODO: how to use replaced function name as str at compile time?
|
|
|
|
// TODO: extend to support multiple keys, but first solve the other two
|
|
|
|
// TODO: extend to support multiple keys, but first solve the other two
|
|
|
|
{$name:literal, $cx:expr, $($key:expr => $func:expr; $desc:literal),+,} => {
|
|
|
|
(@join $first:expr $(,$rest:expr)*) => {
|
|
|
|
mode_info! {
|
|
|
|
concat!($first, $(", ", $rest),*)
|
|
|
|
$name, $cx,
|
|
|
|
|
|
|
|
$($key; $key => $func; $desc,)+
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
{$name:literal, $cx:expr, $($key:expr; $keyp:pat => $func:expr; $desc:literal),+,} => {
|
|
|
|
{$mode:ident, $name:literal, $(#[doc = $desc:literal] $($key:expr),+ => $func:expr),+,} => {
|
|
|
|
$cx.editor.autoinfo = Some(Info::key(
|
|
|
|
#[doc = $name]
|
|
|
|
$name,
|
|
|
|
#[doc = ""]
|
|
|
|
vec![
|
|
|
|
#[doc = "<table><tr><th>key</th><th>desc</th></tr><tbody>"]
|
|
|
|
$(
|
|
|
|
$(
|
|
|
|
(vec![$key], $desc),
|
|
|
|
#[doc = "<tr><td>"]
|
|
|
|
|
|
|
|
#[doc = mode_info!(@join $($key),+)]
|
|
|
|
|
|
|
|
#[doc = "</td><td>"]
|
|
|
|
|
|
|
|
#[doc = $desc]
|
|
|
|
|
|
|
|
#[doc = "</td></tr>"]
|
|
|
|
)+
|
|
|
|
)+
|
|
|
|
],
|
|
|
|
#[doc = "</tbody></table>"]
|
|
|
|
|
|
|
|
pub fn $mode(cx: &mut Context) {
|
|
|
|
|
|
|
|
cx.editor.autoinfo = Some(Info::key(
|
|
|
|
|
|
|
|
$name,
|
|
|
|
|
|
|
|
vec![$((vec![$($key.parse().unwrap()),+], $desc)),+],
|
|
|
|
));
|
|
|
|
));
|
|
|
|
$cx.on_next_key(move |cx, event| {
|
|
|
|
use helix_core::hashmap;
|
|
|
|
cx.editor.autoinfo = None;
|
|
|
|
let mut map = hashmap! {
|
|
|
|
match event {
|
|
|
|
$($($key.parse::<KeyEvent>().unwrap() => $func as for<'r, 's> fn(&'r mut Context<'s>)),+),*
|
|
|
|
$(
|
|
|
|
};
|
|
|
|
$keyp => $func(cx),
|
|
|
|
cx.on_next_key_mode(map);
|
|
|
|
)+
|
|
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn space_mode(cx: &mut Context) {
|
|
|
|
mode_info! {
|
|
|
|
mode_info! {
|
|
|
|
space_mode, "space mode",
|
|
|
|
"space mode", cx,
|
|
|
|
/// file picker
|
|
|
|
key!('f'); key!('f') => file_picker; "file picker",
|
|
|
|
"f" => file_picker,
|
|
|
|
key!('b'); key!('b') => buffer_picker; "buffer picker",
|
|
|
|
/// buffer picker
|
|
|
|
key!('s'); key!('s') => symbol_picker; "symbol picker",
|
|
|
|
"b" => buffer_picker,
|
|
|
|
key!('w'); key!('w') => window_mode; "window mode",
|
|
|
|
/// symbol picker
|
|
|
|
key!('y'); key!('y') => yank_joined_to_clipboard; "yank joined to clipboard",
|
|
|
|
"s" => symbol_picker,
|
|
|
|
key!('Y'); key!('Y') => yank_main_selection_to_clipboard; "yank main selection to clipboard",
|
|
|
|
/// window mode
|
|
|
|
key!('p'); key!('p') => paste_clipboard_after; "paste system clipboard after selections",
|
|
|
|
"w" => window_mode,
|
|
|
|
key!('P'); key!('P') => paste_clipboard_before; "paste system clipboard before selections",
|
|
|
|
/// yank joined to clipboard
|
|
|
|
key!('R'); key!('R') => replace_selections_with_clipboard; "replace selections with clipboard",
|
|
|
|
"y" => yank_joined_to_clipboard,
|
|
|
|
key!(' '); key!(' ') => keep_primary_selection; "keep primary selection",
|
|
|
|
/// yank main selection to clipboard
|
|
|
|
}
|
|
|
|
"Y" => yank_main_selection_to_clipboard,
|
|
|
|
|
|
|
|
/// paste system clipboard after selections
|
|
|
|
|
|
|
|
"p" => paste_clipboard_after,
|
|
|
|
|
|
|
|
/// paste system clipboard before selections
|
|
|
|
|
|
|
|
"P" => paste_clipboard_before,
|
|
|
|
|
|
|
|
/// replace selections with clipboard
|
|
|
|
|
|
|
|
"R" => replace_selections_with_clipboard,
|
|
|
|
|
|
|
|
/// keep primary selection
|
|
|
|
|
|
|
|
"space" => keep_primary_selection,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: generated, delete it later
|
|
|
|
// TODO: generated, delete it later
|
|
|
|
// fn space_mode(cx: &mut Context) {
|
|
|
|
// /// space mode
|
|
|
|
|
|
|
|
// ///
|
|
|
|
|
|
|
|
// /// | key | desc |
|
|
|
|
|
|
|
|
// /// |-----|------|
|
|
|
|
|
|
|
|
// /// | f | file picker |
|
|
|
|
|
|
|
|
// /// | b | buffer picker |
|
|
|
|
|
|
|
|
// /// ...
|
|
|
|
|
|
|
|
// pub fn space_mode(cx: &mut Context) {
|
|
|
|
// cx.editor.autoinfo = Some(Info::key(
|
|
|
|
// cx.editor.autoinfo = Some(Info::key(
|
|
|
|
// "space",
|
|
|
|
// "space mode",
|
|
|
|
// vec![
|
|
|
|
// vec![
|
|
|
|
// (vec![key!('f')], "file picker"),
|
|
|
|
// (vec!["f".parse().unwrap()], "file picker"),
|
|
|
|
// (vec![key!('b')], "buffer picker"),
|
|
|
|
// (vec!["b".parse().unwrap()], "buffer picker"),
|
|
|
|
// (vec![key!('s')], "symbol picker"),
|
|
|
|
// (vec!["s".parse().unwrap()], "symbol picker"),
|
|
|
|
// (vec![key!('w')], "window mode"),
|
|
|
|
// (vec!["w".parse().unwrap()], "window mode"),
|
|
|
|
// (vec![key!('y')], "yank joined to clipboard"),
|
|
|
|
// (vec!["y".parse().unwrap()], "yank joined to clipboard"),
|
|
|
|
// (vec![key!('Y')], "yank main selection to clipboard"),
|
|
|
|
// (vec!["Y".parse().unwrap()], "yank main selection to clipboard"),
|
|
|
|
// (vec![key!('p')], "paste clipboard after"),
|
|
|
|
// (vec!["p".parse().unwrap()], "paste system clipboard after selections"),
|
|
|
|
// (vec![key!('P')], "paste clipboard before"),
|
|
|
|
// (vec!["P".parse().unwrap()], "paste system clipboard before selections"),
|
|
|
|
// (vec![key!('R')], "replace selections with clipboard"),
|
|
|
|
// (vec!["R".parse().unwrap()], "replace selections with clipboard"),
|
|
|
|
// (vec![key!(' ')], "keep primary selection"),
|
|
|
|
// (vec![" ".parse().unwrap()], "keep primary selection"),
|
|
|
|
// ],
|
|
|
|
// ],
|
|
|
|
// ));
|
|
|
|
// ));
|
|
|
|
// cx.on_next_key(move |cx, event| {
|
|
|
|
// let mut map: HashMap<KeyEvent, fn(&mut Context)> = HashMap::with_capacity(10);
|
|
|
|
// cx.editor.autoinfo = None;
|
|
|
|
// map.insert("f".parse().unwrap(), file_picker);
|
|
|
|
// match event {
|
|
|
|
// map.insert("b".parse().unwrap(), buffer_picker);
|
|
|
|
// key!('f') => file_picker(cx),
|
|
|
|
// map.insert("s".parse().unwrap(), symbol_picker);
|
|
|
|
// key!('b') => buffer_picker(cx),
|
|
|
|
// map.insert("w".parse().unwrap(), window_mode);
|
|
|
|
// key!('s') => symbol_picker(cx),
|
|
|
|
// map.insert("y".parse().unwrap(), yank_joined_to_clipboard);
|
|
|
|
// key!('w') => window_mode(cx),
|
|
|
|
// map.insert("Y".parse().unwrap(), yank_main_selection_to_clipboard);
|
|
|
|
// key!('y') => yank_joined_to_clipboard(cx),
|
|
|
|
// map.insert("p".parse().unwrap(), paste_clipboard_after);
|
|
|
|
// key!('Y') => yank_main_selection_to_clipboard(cx),
|
|
|
|
// map.insert("P".parse().unwrap(), paste_clipboard_before);
|
|
|
|
// key!('p') => paste_clipboard_after(cx),
|
|
|
|
// map.insert("R".parse().unwrap(), replace_selections_with_clipboard);
|
|
|
|
// key!('P') => paste_clipboard_before(cx),
|
|
|
|
// map.insert(" ".parse().unwrap(), keep_primary_selection);
|
|
|
|
// key!('R') => replace_selections_with_clipboard(cx),
|
|
|
|
// cx.on_next_key_mode(map);
|
|
|
|
// // key!(' ') => toggle_alternate_buffer(cx),
|
|
|
|
|
|
|
|
// // TODO: temporary since space mode took its old key
|
|
|
|
|
|
|
|
// key!(' ') => keep_primary_selection(cx),
|
|
|
|
|
|
|
|
// _ => {}
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
fn view_mode(cx: &mut Context) {
|
|
|
|
fn view_mode(cx: &mut Context) {
|
|
|
|