mirror of
https://github.com/alexpasmantier/television.git
synced 2025-07-29 06:11:37 +00:00
fix(preview): move preview config logic out of the channel
This commit is contained in:
parent
e5303a3052
commit
acba4b5f11
@ -256,20 +256,10 @@ impl Channel {
|
||||
let item = self.matcher.get_result(index);
|
||||
|
||||
if let Some(item) = item {
|
||||
let mut entry = Entry::new(item.inner.clone())
|
||||
let entry = Entry::new(item.inner.clone())
|
||||
.with_display(item.matched_string)
|
||||
.with_match_indices(&item.match_indices);
|
||||
if let Some(p) = &self.prototype.preview {
|
||||
// FIXME: this should be done by the previewer instead
|
||||
if let Some(offset_expr) = &p.offset {
|
||||
let offset_str =
|
||||
offset_expr.format(&item.inner).unwrap_or_default();
|
||||
|
||||
entry = entry.with_line_number(
|
||||
offset_str.parse::<usize>().unwrap_or(0),
|
||||
);
|
||||
}
|
||||
}
|
||||
.with_match_indices(&item.match_indices)
|
||||
.ansi(self.prototype.source.ansi);
|
||||
Some(entry)
|
||||
} else {
|
||||
None
|
||||
|
@ -364,12 +364,45 @@ impl Television {
|
||||
}
|
||||
|
||||
pub fn get_selected_entry(&mut self) -> Option<Entry> {
|
||||
if self.channel.result_count() == 0 {
|
||||
match self.mode {
|
||||
Mode::Channel => {
|
||||
let entry = self
|
||||
.results_picker
|
||||
.selected()
|
||||
.and_then(|idx| self.results_picker.entries.get(idx))
|
||||
.cloned()?;
|
||||
Some(self.apply_preview_offset(entry))
|
||||
}
|
||||
Mode::RemoteControl => {
|
||||
if self
|
||||
.remote_control
|
||||
.as_ref()
|
||||
.map_or(0, RemoteControl::result_count)
|
||||
== 0
|
||||
{
|
||||
return None;
|
||||
}
|
||||
self.selected_index()
|
||||
let entry = self
|
||||
.selected_index()
|
||||
.map(|idx| self.channel.get_result(idx))
|
||||
.and_then(|entry| entry)
|
||||
.and_then(|entry| entry)?;
|
||||
Some(self.apply_preview_offset(entry))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply preview offset logic to an entry
|
||||
fn apply_preview_offset(&self, mut entry: Entry) -> Entry {
|
||||
if let Some(p) = &self.channel.prototype.preview {
|
||||
if let Some(offset_expr) = &p.offset {
|
||||
let offset_str =
|
||||
offset_expr.format(&entry.raw).unwrap_or_default();
|
||||
entry = entry.with_line_number(
|
||||
offset_str.parse::<usize>().unwrap_or(0),
|
||||
);
|
||||
}
|
||||
}
|
||||
entry
|
||||
}
|
||||
|
||||
pub fn get_selected_cable_entry(&mut self) -> Option<CableEntry> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user