Skip to content

Commit

Permalink
feat: display long status messages as popups
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaRevenco committed Dec 12, 2024
1 parent db1d842 commit b34549f
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use crate::{
commands::{self, OnKeyCallback},
compositor::{Component, Context, Event, EventResult},
compositor::{Component, Compositor, Context, Event, EventResult},
events::{OnModeSwitch, PostCommand},
handlers::completion::CompletionItem,
job::{self, Callback},
key,
keymap::{KeymapResult, Keymaps},
ui::{
document::{render_document, LinePos, TextRenderer},
statusline,
text_decorations::{self, Decoration, DecorationManager, InlineDiagnostics},
Completion, ProgressSpinners,
Completion, Markdown, Popup, ProgressSpinners,
},
};

Expand All @@ -33,7 +34,7 @@ use helix_view::{
};
use std::{mem::take, num::NonZeroUsize, path::PathBuf, rc::Rc, sync::Arc};

use tui::{buffer::Buffer as Surface, text::Span};
use tui::{buffer::Buffer as Surface, text::Span, widgets::Paragraph, Viewport};

pub struct EditorView {
pub keymaps: Keymaps,
Expand Down Expand Up @@ -1525,12 +1526,30 @@ impl Component for EditorView {
cx.editor.theme.get("ui.text")
};

surface.set_string(
area.x,
area.y + area.height.saturating_sub(1),
status_msg,
style,
);
if status_msg.len() <= area.width.into() {
surface.set_string(
area.x,
area.y + area.height.saturating_sub(1),
status_msg,
style,
);
} else {
let status_msg_box = async move {
let call: job::Callback = Callback::EditorCompositor(Box::new(
move |editor: &mut Editor, compositor: &mut Compositor| {
if let Some((contents, _)) = &editor.status_msg {
let contents =
Markdown::new(contents.to_string(), editor.syn_loader.clone());
let popup = Popup::new("hover", contents).auto_close(true);
compositor.replace_or_push("hover", popup);
}
},
));
Ok(call)
};

cx.jobs.callback(status_msg_box)
}
}

if area.width.saturating_sub(status_msg_width as u16) > key_width {
Expand Down

0 comments on commit b34549f

Please sign in to comment.