form pages robust finish chnages

This commit is contained in:
filipriec
2025-08-29 19:49:27 +02:00
parent 16dd460469
commit 2373ae4b8c
3 changed files with 14 additions and 3 deletions

View File

@@ -113,6 +113,13 @@ impl AppState {
false false
} }
pub fn is_canvas_edit_mode_at(&self, path: &str) -> bool {
self.form_editor
.get(path)
.map(|e| matches!(e.mode(), canvas::AppMode::Edit))
.unwrap_or(false)
}
// Mutable editor accessor // Mutable editor accessor
pub fn editor_for_path(&mut self, path: &str) -> Option<&mut FormEditor<FormState>> { pub fn editor_for_path(&mut self, path: &str) -> Option<&mut FormEditor<FormState>> {
self.form_editor.get_mut(path) self.form_editor.get_mut(path)

View File

@@ -151,12 +151,13 @@ pub fn render_ui(
} else { } else {
(0, 1) (0, 1)
}; };
let table_name = path.split('/').nth(1).unwrap_or("");
render_form_page( render_form_page(
f, f,
form_render_area, form_render_area,
editor, editor,
app_state.current_view_table_name.as_deref().unwrap_or(""), table_name,
theme, theme,
total_count, total_count,
current_position, current_position,

View File

@@ -446,6 +446,9 @@ pub async fn run_ui() -> Result<()> {
AppView::AddLogic => router.navigate(Page::AddLogic(admin_state.add_logic_state.clone())), AppView::AddLogic => router.navigate(Page::AddLogic(admin_state.add_logic_state.clone())),
AppView::Form(path) => { AppView::Form(path) => {
// Router now carries the path; just navigate with it // Router now carries the path; just navigate with it
if let Some((profile, table)) = path.split_once('/') {
app_state.set_current_view_table(profile.to_string(), table.to_string());
}
router.navigate(Page::Form(path.clone())); router.navigate(Page::Form(path.clone()));
} }
AppView::Scratch => {} AppView::Scratch => {}
@@ -610,7 +613,7 @@ pub async fn run_ui() -> Result<()> {
if let Page::Form(path) = &router.current { if let Page::Form(path) = &router.current {
if !table_just_switched { if !table_just_switched {
if position_changed && !app_state.is_canvas_edit_mode() { if position_changed && !app_state.is_canvas_edit_mode_at(path) {
position_logic_needs_redraw = true; position_logic_needs_redraw = true;
if let Some(form_state) = app_state.form_state_for_path(path) { if let Some(form_state) = app_state.form_state_for_path(path) {
@@ -648,7 +651,7 @@ pub async fn run_ui() -> Result<()> {
form_state.current_cursor_pos = form_state.current_cursor_pos =
event_handler.ideal_cursor_column.min(max_cursor_pos); event_handler.ideal_cursor_column.min(max_cursor_pos);
} }
} else if !position_changed && !app_state.is_canvas_edit_mode() { } else if !position_changed && !app_state.is_canvas_edit_mode_at(path) {
if let Some(form_state) = app_state.form_state_for_path(path) { if let Some(form_state) = app_state.form_state_for_path(path) {
let current_input_str = form_state.get_current_input(); let current_input_str = form_state.get_current_input();
let current_input_len = current_input_str.chars().count(); let current_input_len = current_input_str.chars().count();