aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorGokul Soumya2022-12-25 05:54:09 +0000
committerBlaž Hrastnik2023-01-18 05:19:32 +0000
commit5c7db7aed54f52b3af6102517f81c9d70bb6d1fb (patch)
treea49faaa0ceb633c09b908bfe249d2f9b4a935680 /helix-term/src/ui
parentb2837ff3bea286ce7ccfba9b6fbcd861977caf83 (diff)
Replace menu::Item::{row, label} with format()
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/completion.rs7
-rw-r--r--helix-term/src/ui/menu.rs22
-rw-r--r--helix-term/src/ui/picker.rs6
3 files changed, 14 insertions, 21 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index 11d7886a..824bafd8 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -1,7 +1,6 @@
use crate::compositor::{Component, Context, Event, EventResult};
use helix_view::{apply_transaction, editor::CompleteAction, ViewId};
use tui::buffer::Buffer as Surface;
-use tui::text::Spans;
use std::borrow::Cow;
@@ -33,11 +32,7 @@ impl menu::Item for CompletionItem {
.into()
}
- fn label(&self, _data: &Self::Data) -> Spans {
- self.label.as_str().into()
- }
-
- fn row(&self, _data: &Self::Data) -> menu::Row {
+ fn format(&self, _data: &Self::Data) -> menu::Row {
menu::Row::new(vec![
menu::Cell::from(self.label.as_str()),
menu::Cell::from(match self.kind {
diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs
index b9c1f9de..e92578c5 100644
--- a/helix-term/src/ui/menu.rs
+++ b/helix-term/src/ui/menu.rs
@@ -4,7 +4,7 @@ use crate::{
compositor::{Callback, Component, Compositor, Context, Event, EventResult},
ctrl, key, shift,
};
-use tui::{buffer::Buffer as Surface, text::Spans, widgets::Table};
+use tui::{buffer::Buffer as Surface, widgets::Table};
pub use tui::widgets::{Cell, Row};
@@ -18,28 +18,24 @@ pub trait Item {
/// Additional editor state that is used for label calculation.
type Data;
- fn label(&self, data: &Self::Data) -> Spans;
+ fn format(&self, data: &Self::Data) -> Row;
fn sort_text(&self, data: &Self::Data) -> Cow<str> {
- let label: String = self.label(data).into();
+ let label: String = self.format(data).cell_text().collect();
label.into()
}
fn filter_text(&self, data: &Self::Data) -> Cow<str> {
- let label: String = self.label(data).into();
+ let label: String = self.format(data).cell_text().collect();
label.into()
}
-
- fn row(&self, data: &Self::Data) -> Row {
- Row::new(vec![Cell::from(self.label(data))])
- }
}
impl Item for PathBuf {
/// Root prefix to strip.
type Data = PathBuf;
- fn label(&self, root_path: &Self::Data) -> Spans {
+ fn format(&self, root_path: &Self::Data) -> Row {
self.strip_prefix(root_path)
.unwrap_or(self)
.to_string_lossy()
@@ -144,10 +140,10 @@ impl<T: Item> Menu<T> {
let n = self
.options
.first()
- .map(|option| option.row(&self.editor_data).cells.len())
+ .map(|option| option.format(&self.editor_data).cells.len())
.unwrap_or_default();
let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| {
- let row = option.row(&self.editor_data);
+ let row = option.format(&self.editor_data);
// maintain max for each column
for (acc, cell) in acc.iter_mut().zip(row.cells.iter()) {
let width = cell.content.width();
@@ -331,7 +327,9 @@ impl<T: Item + 'static> Component for Menu<T> {
(a + b - 1) / b
}
- let rows = options.iter().map(|option| option.row(&self.editor_data));
+ let rows = options
+ .iter()
+ .map(|option| option.format(&self.editor_data));
let table = Table::new(rows)
.style(style)
.highlight_style(selected)
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs
index 05738ccf..ccf37eb2 100644
--- a/helix-term/src/ui/picker.rs
+++ b/helix-term/src/ui/picker.rs
@@ -410,10 +410,10 @@ impl<T: Item> Picker<T> {
let n = options
.first()
- .map(|option| option.row(&editor_data).cells.len())
+ .map(|option| option.format(&editor_data).cells.len())
.unwrap_or_default();
let max_lens = options.iter().fold(vec![0; n], |mut acc, option| {
- let row = option.row(&editor_data);
+ let row = option.format(&editor_data);
// maintain max for each column
for (acc, cell) in acc.iter_mut().zip(row.cells.iter()) {
let width = cell.content.width();
@@ -729,7 +729,7 @@ impl<T: Item + 'static> Component for Picker<T> {
.skip(offset)
.take(rows as usize)
.map(|pmatch| &self.options[pmatch.index])
- .map(|option| option.row(&self.editor_data))
+ .map(|option| option.format(&self.editor_data))
.map(|mut row| {
const TEMP_CELL_SEP: &str = " ";