From 8d41beef0beb1d10b268d9ea7190928d42ee49b5 Mon Sep 17 00:00:00 2001 From: filipriec Date: Tue, 15 Apr 2025 18:33:42 +0200 Subject: [PATCH] killing of the buffer working --- client/src/state/app/buffer.rs | 18 ++++++++++++++++++ client/src/tui/functions/common/login.rs | 1 + 2 files changed, 19 insertions(+) diff --git a/client/src/state/app/buffer.rs b/client/src/state/app/buffer.rs index 4ff59c6..054a7ea 100644 --- a/client/src/state/app/buffer.rs +++ b/client/src/state/app/buffer.rs @@ -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 + } } diff --git a/client/src/tui/functions/common/login.rs b/client/src/tui/functions/common/login.rs index 2848d21..98308c6 100644 --- a/client/src/tui/functions/common/login.rs +++ b/client/src/tui/functions/common/login.rs @@ -100,6 +100,7 @@ pub async fn back_to_main( app_state.hide_dialog(); // Uncomment if needed // Navigation logic (currently disabled in original code) + let closed = buffer_state.close_active_buffer(); buffer_state.update_history(AppView::Intro); // Reset focus state