paste command improvement
This commit is contained in:
parent
5316b37919
commit
c3d30177b1
14
src/nvim.rs
14
src/nvim.rs
@ -188,3 +188,17 @@ fn safe_call<F>(cb: F)
|
||||
glib::Continue(false)
|
||||
});
|
||||
}
|
||||
|
||||
pub trait ErrorReport {
|
||||
fn report_err(&self, nvim: &mut NeovimApi, ctx_msg: &str);
|
||||
}
|
||||
|
||||
impl<T> ErrorReport for result::Result<T, String> {
|
||||
fn report_err(&self, _: &mut NeovimApi, ctx_msg: &str) {
|
||||
if let &Err(ref msg) = self {
|
||||
let err_msg = format!("{} {}", ctx_msg, msg);
|
||||
println!("{}", err_msg);
|
||||
//nvim.report_error(&err_msg).expect("Error report error :)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
18
src/ui.rs
18
src/ui.rs
@ -16,7 +16,7 @@ use glib;
|
||||
use neovim_lib::{Neovim, NeovimApi, Value, Integer};
|
||||
|
||||
use ui_model::{UiModel, Attrs, Color, COLOR_BLACK, COLOR_WHITE};
|
||||
use nvim::{RedrawEvents, GuiApi};
|
||||
use nvim::{RedrawEvents, GuiApi, ErrorReport};
|
||||
|
||||
use input::{convert_key, keyval_to_input_string};
|
||||
|
||||
@ -192,9 +192,14 @@ fn edit_paste() {
|
||||
UI.with(|ui_cell| {
|
||||
let mut ui = ui_cell.borrow_mut();
|
||||
|
||||
if let Err(e) = ui.nvim().input("<Esc>\"*p") {
|
||||
println!("Error paste from clipboard {}", e);
|
||||
}
|
||||
let paste_command = if ui.mode == NvimMode::Normal {
|
||||
"\"*p"
|
||||
} else {
|
||||
"<Esc>\"*p"
|
||||
};
|
||||
|
||||
let mut nvim = ui.nvim();
|
||||
nvim.input(paste_command).report_err(nvim, "Error paste from clipboard");
|
||||
});
|
||||
}
|
||||
|
||||
@ -202,9 +207,8 @@ fn edit_save_all() {
|
||||
UI.with(|ui_cell| {
|
||||
let mut ui = ui_cell.borrow_mut();
|
||||
|
||||
if let Err(e) = ui.nvim().command(":wa") {
|
||||
println!("Error save all files {}", e);
|
||||
}
|
||||
let mut nvim = ui.nvim();
|
||||
nvim.command(":wa").report_err(nvim, "Error save all files");
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user