mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-11-30 00:35:26 +03:00
Allow setting a status message.
This commit is contained in:
parent
742b3a709f
commit
8098e9bdcd
@ -35,6 +35,7 @@ pub struct Context<'a> {
|
||||
pub callback: Option<crate::compositor::Callback>,
|
||||
pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
|
||||
pub callbacks: &'a mut LspCallbacks,
|
||||
pub status_msg: Option<String>,
|
||||
}
|
||||
|
||||
use futures_util::FutureExt;
|
||||
@ -87,6 +88,11 @@ impl<'a> Context<'a> {
|
||||
});
|
||||
self.callbacks.push(callback);
|
||||
}
|
||||
|
||||
// TODO: allow &'static str?
|
||||
pub fn set_status(&mut self, msg: String) {
|
||||
self.status_msg = Some(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/// A command is a function that takes the current state and a count, and does a side-effect on the
|
||||
@ -1378,7 +1384,7 @@ pub fn redo(cx: &mut Context) {
|
||||
pub fn yank(cx: &mut Context) {
|
||||
// TODO: should selections be made end inclusive?
|
||||
let doc = cx.doc();
|
||||
let values = doc
|
||||
let values: Vec<String> = doc
|
||||
.selection()
|
||||
.fragments(doc.text().slice(..))
|
||||
.map(|cow| cow.into_owned())
|
||||
@ -1386,7 +1392,11 @@ pub fn yank(cx: &mut Context) {
|
||||
|
||||
// TODO: allow specifying reg
|
||||
let reg = '"';
|
||||
let msg = format!("yanked {} selection(s) to register {}", values.len(), reg);
|
||||
|
||||
register::set(reg, values);
|
||||
|
||||
cx.set_status(msg)
|
||||
}
|
||||
|
||||
pub fn paste(cx: &mut Context) {
|
||||
|
@ -26,6 +26,7 @@ use tui::{
|
||||
pub struct EditorView {
|
||||
keymap: Keymaps,
|
||||
on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
|
||||
status_msg: Option<String>,
|
||||
}
|
||||
|
||||
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
|
||||
@ -35,6 +36,7 @@ impl EditorView {
|
||||
Self {
|
||||
keymap: keymap::default(),
|
||||
on_next_key: None,
|
||||
status_msg: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,6 +70,12 @@ impl EditorView {
|
||||
1,
|
||||
);
|
||||
self.render_statusline(&doc, area, surface, theme, is_focused);
|
||||
|
||||
// render status
|
||||
if let Some(status_msg) = &self.status_msg {
|
||||
let style = Style::default().fg(Color::Rgb(164, 160, 232)); // lavender
|
||||
surface.set_string(viewport.x, viewport.y + viewport.height, status_msg, style);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_buffer(
|
||||
@ -441,8 +449,12 @@ impl Component for EditorView {
|
||||
callback: None,
|
||||
callbacks: cx.callbacks,
|
||||
on_next_key_callback: None,
|
||||
status_msg: None,
|
||||
};
|
||||
|
||||
// clear status
|
||||
self.status_msg = None;
|
||||
|
||||
if let Some(on_next_key) = self.on_next_key.take() {
|
||||
// if there's a command waiting input, do that first
|
||||
on_next_key(&mut cxt, event);
|
||||
@ -486,6 +498,7 @@ impl Component for EditorView {
|
||||
}
|
||||
|
||||
self.on_next_key = cxt.on_next_key_callback.take();
|
||||
self.status_msg = cxt.status_msg.take();
|
||||
|
||||
// appease borrowck
|
||||
let callback = cxt.callback.take();
|
||||
|
Loading…
Reference in New Issue
Block a user