killing of the buffer working
This commit is contained in:
@@ -63,5 +63,23 @@ impl BufferState {
|
||||
pub fn get_active_view(&self) -> Option<&AppView> {
|
||||
self.history.get(self.active_index)
|
||||
}
|
||||
|
||||
/// Removes the currently active buffer from the history.
|
||||
/// 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).
|
||||
pub fn close_active_buffer(&mut self) -> bool {
|
||||
if self.history.len() <= 1 {
|
||||
return false; // Cannot close the last buffer
|
||||
}
|
||||
|
||||
let current_index = self.active_index;
|
||||
self.history.remove(current_index); // Remove the active buffer
|
||||
|
||||
// Set the new active index to the one *before* the closed one,
|
||||
// ensuring it doesn't go below 0. This mimics closing a tab.
|
||||
self.active_index = current_index.saturating_sub(1);
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user