killing of the buffers now works
This commit is contained in:
@@ -64,20 +64,27 @@ impl BufferState {
|
|||||||
self.history.get(self.active_index)
|
self.history.get(self.active_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the currently active buffer from the history.
|
/// Removes the currently active buffer from the history, unless it's the Intro buffer.
|
||||||
/// Sets the new active buffer to the one preceding the closed one.
|
/// Sets the new active buffer to the one preceding the closed one.
|
||||||
/// Returns `true` if a buffer was closed, `false` otherwise (e.g., only one buffer left).
|
/// # Returns
|
||||||
|
/// * `true` if a non-Intro buffer was closed.
|
||||||
|
/// * `false` if the active buffer was Intro or only Intro remained.
|
||||||
pub fn close_active_buffer(&mut self) -> bool {
|
pub fn close_active_buffer(&mut self) -> bool {
|
||||||
if self.history.len() <= 1 {
|
let current_index = self.active_index;
|
||||||
return false; // Cannot close the last buffer
|
|
||||||
|
// Rule 1: Cannot close Intro buffer.
|
||||||
|
if matches!(self.history.get(current_index), Some(AppView::Intro)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let current_index = self.active_index;
|
// Rule 2: Cannot close if only Intro would remain (or already remains).
|
||||||
self.history.remove(current_index); // Remove the active buffer
|
// This check implicitly covers the case where len <= 1.
|
||||||
|
if self.history.len() <= 1 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the new active index to the one *before* the closed one,
|
self.history.remove(current_index);
|
||||||
// ensuring it doesn't go below 0. This mimics closing a tab.
|
self.active_index = current_index.saturating_sub(1).min(self.history.len() - 1);
|
||||||
self.active_index = current_index.saturating_sub(1);
|
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user