aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/ui/picker.rs33
-rw-r--r--helix-term/src/ui/prompt.rs3
2 files changed, 26 insertions, 10 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs
index bf072877..a715ebb5 100644
--- a/helix-term/src/ui/picker.rs
+++ b/helix-term/src/ui/picker.rs
@@ -118,6 +118,20 @@ impl<T> Picker<T> {
// - on input change:
// - score all the names in relation to input
+fn inner_rect(area: Rect) -> Rect {
+ let padding_vertical = area.height * 20 / 100;
+ let padding_horizontal = area.width * 20 / 100;
+
+ let area = Rect::new(
+ area.x + padding_horizontal,
+ area.y + padding_vertical,
+ area.width - padding_horizontal * 2,
+ area.height - padding_vertical * 2,
+ );
+
+ area
+}
+
impl<T: 'static> Component for Picker<T> {
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
let key_event = match event {
@@ -191,15 +205,7 @@ impl<T: 'static> Component for Picker<T> {
}
fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
- let padding_vertical = area.height * 20 / 100;
- let padding_horizontal = area.width * 20 / 100;
-
- let area = Rect::new(
- area.x + padding_horizontal,
- area.y + padding_vertical,
- area.width - padding_horizontal * 2,
- area.height - padding_vertical * 2,
- );
+ let area = inner_rect(area);
// -- Render the frame:
@@ -260,6 +266,15 @@ impl<T: 'static> Component for Picker<T> {
}
fn cursor_position(&self, area: Rect, editor: &Editor) -> Option<Position> {
+ // TODO: this is mostly duplicate code
+ let area = inner_rect(area);
+ let block = Block::default().borders(Borders::ALL);
+ // calculate the inner area inside the box
+ let inner = block.inner(area);
+
+ // prompt area
+ let area = Rect::new(inner.x + 1, inner.y, inner.width - 1, 1);
+
self.prompt.cursor_position(area, editor)
}
}
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs
index dbbef72c..e6c383b6 100644
--- a/helix-term/src/ui/prompt.rs
+++ b/helix-term/src/ui/prompt.rs
@@ -271,8 +271,9 @@ impl Component for Prompt {
}
fn cursor_position(&self, area: Rect, editor: &Editor) -> Option<Position> {
+ let line = area.height as usize - 1;
Some(Position::new(
- area.y as usize,
+ area.y as usize + line,
area.x as usize + self.prompt.len() + self.cursor,
))
}