Skip to content

Commit

Permalink
handle keybind in hover component
Browse files Browse the repository at this point in the history
  • Loading branch information
kyfanc committed Apr 4, 2024
1 parent 31f872c commit 8310f64
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions helix-term/src/ui/lsp/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use arc_swap::ArcSwap;
use helix_core::syntax;
use helix_lsp::lsp;
use helix_view::graphics::{Margin, Rect, Style};
use helix_view::input::Event;
use tui::buffer::Buffer;
use tui::widgets::{BorderType, Paragraph, Widget, Wrap};

use crate::compositor::{Component, Compositor, Context};
use crate::compositor::{Component, Compositor, Context, EventResult};

use crate::ui::Markdown;
use crate::{ctrl, key, shift};

use crate::ui::Popup;

Expand Down Expand Up @@ -78,7 +80,7 @@ impl Hover {
}

pub fn previous_hover(&mut self) {
let index = if self.active_index > 1 {
let index = if self.active_index > 0 {
self.active_index - 1
} else {
self.hovers.len() - 1
Expand Down Expand Up @@ -156,6 +158,24 @@ impl Component for Hover {

Some((width + PADDING, height + PADDING))
}

fn handle_event(&mut self, event: &Event, _ctx: &mut Context) -> EventResult {
let Event::Key(event) = event else {
return EventResult::Ignored(None);
};

match event {
shift!(Tab) | key!(Up) | ctrl!('p') => {
self.previous_hover();
EventResult::Consumed(None)
}
key!(Tab) | key!(Down) | ctrl!('n') => {
self.next_hover();
EventResult::Consumed(None)
}
_ => EventResult::Ignored(None),
}
}
}

fn hover_contents_to_string(contents: &lsp::HoverContents) -> String {
Expand Down

0 comments on commit 8310f64

Please sign in to comment.