intro buffer can be killed now also

This commit is contained in:
filipriec
2025-05-25 22:37:27 +02:00
parent 32210a5f7c
commit 116db3566f

View File

@@ -8,7 +8,7 @@ pub enum AppView {
Admin, Admin,
AddTable, AddTable,
AddLogic, AddLogic,
Form, // Remove the String parameter Form,
Scratch, Scratch,
} }
@@ -23,7 +23,7 @@ impl AppView {
AppView::Admin => "Admin_Panel", AppView::Admin => "Admin_Panel",
AppView::AddTable => "Add_Table", AppView::AddTable => "Add_Table",
AppView::AddLogic => "Add_Logic", AppView::AddLogic => "Add_Logic",
AppView::Form => "Form", // Default fallback AppView::Form => "Form",
AppView::Scratch => "*scratch*", AppView::Scratch => "*scratch*",
} }
} }
@@ -41,7 +41,6 @@ impl AppView {
} }
} }
// Rest of BufferState implementation remains the same
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct BufferState { pub struct BufferState {
pub history: Vec<AppView>, pub history: Vec<AppView>,
@@ -81,11 +80,8 @@ impl BufferState {
} }
let current_index = self.active_index; let current_index = self.active_index;
if matches!(self.history.get(current_index), Some(AppView::Intro)) {
return false;
}
self.history.remove(current_index); self.history.remove(current_index);
if self.history.is_empty() { if self.history.is_empty() {
self.history.push(AppView::Intro); self.history.push(AppView::Intro);
self.active_index = 0; self.active_index = 0;
@@ -97,8 +93,12 @@ impl BufferState {
pub fn close_buffer_with_intro_fallback(&mut self, current_table_name: Option<&str>) -> String { pub fn close_buffer_with_intro_fallback(&mut self, current_table_name: Option<&str>) -> String {
let current_view_cloned = self.get_active_view().cloned(); let current_view_cloned = self.get_active_view().cloned();
if let Some(AppView::Intro) = current_view_cloned { if let Some(AppView::Intro) = current_view_cloned {
return "Cannot close intro buffer".to_string(); if self.history.len() == 1 {
self.close_active_buffer();
return "Intro buffer reset".to_string();
}
} }
let closed_name = current_view_cloned let closed_name = current_view_cloned
@@ -108,12 +108,12 @@ impl BufferState {
if self.close_active_buffer() { if self.close_active_buffer() {
if self.history.len() == 1 && matches!(self.history.get(0), Some(AppView::Intro)) { if self.history.len() == 1 && matches!(self.history.get(0), Some(AppView::Intro)) {
format!("Closed '{}' - returned to intro", closed_name) format!("Closed '{}' - returned to Intro", closed_name)
} else { } else {
format!("Closed '{}'", closed_name) format!("Closed '{}'", closed_name)
} }
} else { } else {
format!("Cannot close buffer: {}", closed_name) format!("Buffer '{}' could not be closed", closed_name)
} }
} }
} }