Add saved split view rows
This commit is contained in:
@@ -125,6 +125,7 @@ impl BrowserCore {
|
||||
self.split_active_tab_right()?;
|
||||
Ok(true)
|
||||
}
|
||||
"save-split-view" | "save split view" => Ok(self.save_active_split_view()?.is_some()),
|
||||
"downloads" | "open-downloads" | "open downloads" => {
|
||||
self.open_tab(downloads_url()?);
|
||||
Ok(true)
|
||||
|
||||
@@ -5,6 +5,21 @@ use crate::CoreError;
|
||||
use super::BrowserCore;
|
||||
|
||||
impl BrowserCore {
|
||||
pub fn save_active_split_view(&mut self) -> Result<Option<SplitId>, CoreError> {
|
||||
let Some(split_id) = self.active_tab()?.split_id().cloned() else {
|
||||
return Ok(None);
|
||||
};
|
||||
let title = self.active_split_title(&split_id)?;
|
||||
let layout = self
|
||||
.split_layouts
|
||||
.iter_mut()
|
||||
.find(|layout| layout.id() == &split_id)
|
||||
.ok_or_else(|| CoreError::SplitNotFound { id: split_id.clone() })?;
|
||||
|
||||
layout.save(title);
|
||||
Ok(Some(split_id))
|
||||
}
|
||||
|
||||
pub fn split_active_tab_right(&mut self) -> Result<SplitId, CoreError> {
|
||||
let active_index = self.active_tab_index()?;
|
||||
let active_tab_id = self.tabs[active_index].id().clone();
|
||||
@@ -98,4 +113,28 @@ impl BrowserCore {
|
||||
.find(|tab| tab.id() == active_tab_id)
|
||||
.and_then(|tab| tab.split_id().cloned())
|
||||
}
|
||||
|
||||
fn active_split_title(&self, split_id: &SplitId) -> Result<String, CoreError> {
|
||||
let layout = self
|
||||
.split_layouts
|
||||
.iter()
|
||||
.find(|layout| layout.id() == split_id)
|
||||
.ok_or_else(|| CoreError::SplitNotFound { id: split_id.clone() })?;
|
||||
let pane_titles = layout
|
||||
.panes()
|
||||
.iter()
|
||||
.filter_map(|pane| {
|
||||
self.tabs
|
||||
.iter()
|
||||
.find(|tab| tab.id() == pane.tab_id())
|
||||
.map(|tab| tab.title().to_string())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(match pane_titles.as_slice() {
|
||||
[] => "Split View".to_string(),
|
||||
[title] => format!("Split View: {title}"),
|
||||
[first, second, ..] => format!("Split View: {first} + {second}"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,39 @@ fn split_right_command_focuses_new_pane() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_split_view_command_marks_active_layout() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
core.split_active_tab_right()?;
|
||||
|
||||
core.set_command_query(">save-split-view");
|
||||
let intent = core.submit_command()?;
|
||||
let snapshot = core.snapshot()?;
|
||||
let layout = snapshot.split_layouts.first().ok_or("missing split layout")?;
|
||||
|
||||
assert_eq!(intent, Some(CommandIntent::Command("save-split-view".to_string())));
|
||||
assert!(layout.saved());
|
||||
assert_eq!(layout.title(), "Split View: New Tab + New Tab");
|
||||
assert_eq!(snapshot.command_query, "");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_split_view_command_preserves_query_without_active_split() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let active_tab_id = core.active_tab()?.id().clone();
|
||||
|
||||
core.set_command_query(">save-split-view");
|
||||
let intent = core.submit_command()?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert_eq!(intent, Some(CommandIntent::Command("save-split-view".to_string())));
|
||||
assert!(snapshot.split_layouts.is_empty());
|
||||
assert_eq!(snapshot.active_tab_id, active_tab_id);
|
||||
assert_eq!(snapshot.command_query, ">save-split-view");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_split_pane_dissolves_two_pane_layout() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
Reference in New Issue
Block a user