intro empty buffer fixed
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// src/tui/functions/intro.rs
|
// src/pages/intro/logic.rs
|
||||||
use crate::state::app::state::AppState;
|
use crate::state::app::state::AppState;
|
||||||
use crate::buffer::state::{AppView, BufferState};
|
use crate::buffer::state::{AppView, BufferState};
|
||||||
|
|
||||||
@@ -12,19 +12,65 @@ pub fn handle_intro_selection(
|
|||||||
buffer_state: &mut BufferState,
|
buffer_state: &mut BufferState,
|
||||||
index: usize,
|
index: usize,
|
||||||
) {
|
) {
|
||||||
let target_view = match index {
|
match index {
|
||||||
0 => AppView::Form("".to_string()), // or better: pick a real path
|
// Continue: go to the most recent existing Form tab, or open a sensible default
|
||||||
1 => AppView::Admin,
|
0 => {
|
||||||
2 => AppView::Login,
|
// 1) Try to switch to an already open Form buffer (most recent)
|
||||||
3 => AppView::Register,
|
if let Some(existing_path) = buffer_state
|
||||||
_ => return,
|
.history
|
||||||
};
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.find_map(|view| {
|
||||||
|
if let AppView::Form(p) = view {
|
||||||
|
Some(p.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
{
|
||||||
|
buffer_state.update_history(AppView::Form(existing_path));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
buffer_state.update_history(target_view);
|
// 2) Otherwise pick a fallback path
|
||||||
|
let fallback_path = if let (Some(profile), Some(table)) = (
|
||||||
// Register view requires focus reset
|
app_state.current_view_profile_name.clone(),
|
||||||
if index == 3 {
|
app_state.current_view_table_name.clone(),
|
||||||
app_state.ui.focus_outside_canvas = false;
|
) {
|
||||||
app_state.focused_button_index = 0;
|
Some(format!("{}/{}", profile, table))
|
||||||
|
} else if let Some(any_key) = app_state.form_editor.keys().next().cloned() {
|
||||||
|
// Use any existing editor key if available
|
||||||
|
Some(any_key)
|
||||||
|
} else {
|
||||||
|
// Otherwise pick the first available table from the profile tree
|
||||||
|
let mut found: Option<String> = None;
|
||||||
|
for prof in &app_state.profile_tree.profiles {
|
||||||
|
if let Some(tbl) = prof.tables.first() {
|
||||||
|
found = Some(format!("{}/{}", prof.name, tbl.name));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
found
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(path) = fallback_path {
|
||||||
|
buffer_state.update_history(AppView::Form(path));
|
||||||
|
} else {
|
||||||
|
// No sensible default; stay on Intro
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
buffer_state.update_history(AppView::Admin);
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
buffer_state.update_history(AppView::Login);
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
buffer_state.update_history(AppView::Register);
|
||||||
|
// Register view requires focus reset
|
||||||
|
app_state.ui.focus_outside_canvas = false;
|
||||||
|
app_state.focused_button_index = 0;
|
||||||
|
}
|
||||||
|
_ => return,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user