we compiled but buffer doesnt work
This commit is contained in:
@@ -128,69 +128,84 @@ impl EventHandler {
|
||||
}
|
||||
|
||||
// Helper functions - replace the removed event_helper functions
|
||||
fn get_current_field_for_state(
|
||||
router: &Router,
|
||||
) -> usize {
|
||||
fn get_current_field_for_state(&self, router: &Router, app_state: &AppState) -> usize {
|
||||
match &router.current {
|
||||
Page::Login(state) => state.current_field(),
|
||||
Page::Register(state) => state.current_field(),
|
||||
Page::Form(state) => state.current_field(),
|
||||
Page::Form(path) => app_state
|
||||
.editor_for_path_ref(path)
|
||||
.map(|e| e.data_provider().current_field())
|
||||
.unwrap_or(0),
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_current_cursor_pos_for_state(
|
||||
router: &Router,
|
||||
) -> usize {
|
||||
fn get_current_cursor_pos_for_state(&self, router: &Router, app_state: &AppState) -> usize {
|
||||
match &router.current {
|
||||
Page::Login(state) => state.current_cursor_pos(),
|
||||
Page::Register(state) => state.current_cursor_pos(),
|
||||
Page::Form(state) => state.current_cursor_pos(),
|
||||
Page::Form(path) => app_state
|
||||
.form_state_for_path_ref(path)
|
||||
.map(|fs| fs.current_cursor_pos())
|
||||
.unwrap_or(0),
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_has_unsaved_changes_for_state(
|
||||
router: &Router,
|
||||
) -> bool {
|
||||
fn get_has_unsaved_changes_for_state(&self, router: &Router, app_state: &AppState) -> bool {
|
||||
match &router.current {
|
||||
Page::Login(state) => state.has_unsaved_changes(),
|
||||
Page::Register(state) => state.has_unsaved_changes(),
|
||||
Page::Form(state) => state.has_unsaved_changes(),
|
||||
Page::Form(path) => app_state
|
||||
.form_state_for_path_ref(path)
|
||||
.map(|fs| fs.has_unsaved_changes())
|
||||
.unwrap_or(false),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_current_input_for_state<'a>(
|
||||
&'a self,
|
||||
router: &'a Router,
|
||||
app_state: &'a AppState,
|
||||
) -> &'a str {
|
||||
match &router.current {
|
||||
Page::Login(state) => state.get_current_input(),
|
||||
Page::Register(state) => state.get_current_input(),
|
||||
Page::Form(state) => state.get_current_input(),
|
||||
Page::Form(path) => app_state
|
||||
.form_state_for_path_ref(path)
|
||||
.map(|fs| fs.get_current_input())
|
||||
.unwrap_or(""),
|
||||
_ => "",
|
||||
}
|
||||
}
|
||||
|
||||
fn set_current_cursor_pos_for_state(
|
||||
&mut self,
|
||||
router: &mut Router,
|
||||
app_state: &mut AppState,
|
||||
pos: usize,
|
||||
) {
|
||||
match &mut router.current {
|
||||
Page::Login(state) => state.set_current_cursor_pos(pos),
|
||||
Page::Register(state) => state.set_current_cursor_pos(pos),
|
||||
Page::Form(state) => state.set_current_cursor_pos(pos),
|
||||
Page::Form(path) => {
|
||||
if let Some(fs) = app_state.form_state_for_path(path) {
|
||||
fs.set_current_cursor_pos(pos);
|
||||
}
|
||||
}
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
fn get_cursor_pos_for_mixed_state(
|
||||
router: &Router,
|
||||
) -> usize {
|
||||
fn get_cursor_pos_for_mixed_state(&self, router: &Router, app_state: &AppState) -> usize {
|
||||
match &router.current {
|
||||
Page::Login(state) => state.current_cursor_pos(),
|
||||
Page::Register(state) => state.current_cursor_pos(),
|
||||
Page::Form(state) => state.current_cursor_pos(),
|
||||
Page::Form(path) => app_state
|
||||
.form_state_for_path_ref(path)
|
||||
.map(|fs| fs.current_cursor_pos())
|
||||
.unwrap_or(0),
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
@@ -254,7 +269,7 @@ impl EventHandler {
|
||||
Page::Admin(_) => AppView::Admin,
|
||||
Page::AddLogic(_) => AppView::AddLogic,
|
||||
Page::AddTable(_) => AppView::AddTable,
|
||||
Page::Form(_) => AppView::Form,
|
||||
Page::Form(path) => AppView::Form(path.clone()),
|
||||
};
|
||||
buffer_state.update_history(current_view);
|
||||
|
||||
@@ -495,7 +510,7 @@ impl EventHandler {
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Page::AddTable(state) => {
|
||||
if state.handle_movement(ma) {
|
||||
// Keep UI focus consistent with inputs vs. outer elements
|
||||
@@ -678,8 +693,10 @@ impl EventHandler {
|
||||
self.command_message.clear();
|
||||
self.command_mode = false;
|
||||
self.key_sequence_tracker.reset();
|
||||
if let Some(editor) = &mut app_state.form_editor {
|
||||
editor.set_mode(CanvasMode::ReadOnly);
|
||||
if let Page::Form(path) = &router.current {
|
||||
if let Some(editor) = app_state.editor_for_path(path) {
|
||||
editor.set_mode(CanvasMode::ReadOnly);
|
||||
}
|
||||
}
|
||||
return Ok(EventOutcome::Ok(
|
||||
"Exited command mode".to_string(),
|
||||
@@ -687,11 +704,18 @@ impl EventHandler {
|
||||
}
|
||||
|
||||
if config.is_command_execute(key_code, modifiers) {
|
||||
let (mut current_position, total_count) = if let Page::Form(fs) = &router.current {
|
||||
(fs.current_position, fs.total_count)
|
||||
} else {
|
||||
(1, 0)
|
||||
};
|
||||
let (mut current_position, total_count) =
|
||||
if let Page::Form(path) = &router.current {
|
||||
if let Some(fs) =
|
||||
app_state.form_state_for_path_ref(path)
|
||||
{
|
||||
(fs.current_position, fs.total_count)
|
||||
} else {
|
||||
(1, 0)
|
||||
}
|
||||
} else {
|
||||
(1, 0)
|
||||
};
|
||||
|
||||
let outcome = command_mode::handle_command_event(
|
||||
key_event,
|
||||
@@ -706,8 +730,10 @@ impl EventHandler {
|
||||
&mut current_position,
|
||||
total_count,
|
||||
).await?;
|
||||
if let Page::Form(fs) = &mut router.current {
|
||||
fs.current_position = current_position;
|
||||
if let Page::Form(path) = &router.current {
|
||||
if let Some(fs) = app_state.form_state_for_path(path) {
|
||||
fs.current_position = current_position;
|
||||
}
|
||||
}
|
||||
self.command_mode = false;
|
||||
self.key_sequence_tracker.reset();
|
||||
@@ -834,9 +860,10 @@ impl EventHandler {
|
||||
.await?;
|
||||
Ok(EventOutcome::Ok(message))
|
||||
} else {
|
||||
let save_outcome = if let Page::Form(_) = &router.current {
|
||||
let save_outcome = if let Page::Form(path) = &router.current {
|
||||
save(
|
||||
app_state,
|
||||
path,
|
||||
&mut self.grpc_client,
|
||||
)
|
||||
.await?
|
||||
@@ -852,8 +879,10 @@ impl EventHandler {
|
||||
}
|
||||
}
|
||||
"force_quit" => {
|
||||
if let Some(editor) = &mut app_state.form_editor {
|
||||
editor.cleanup_cursor()?;
|
||||
if let Page::Form(path) = &router.current {
|
||||
if let Some(editor) = app_state.editor_for_path(path) {
|
||||
editor.cleanup_cursor()?;
|
||||
}
|
||||
}
|
||||
terminal.cleanup()?;
|
||||
Ok(EventOutcome::Exit(
|
||||
@@ -870,18 +899,21 @@ impl EventHandler {
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
let save_outcome = save(
|
||||
app_state,
|
||||
&mut self.grpc_client,
|
||||
).await?;
|
||||
let save_outcome = if let Page::Form(path) = &router.current {
|
||||
save(app_state, path, &mut self.grpc_client).await?
|
||||
} else {
|
||||
SaveOutcome::NoChange
|
||||
};
|
||||
match save_outcome {
|
||||
SaveOutcome::NoChange => "No changes to save.".to_string(),
|
||||
SaveOutcome::UpdatedExisting => "Entry updated.".to_string(),
|
||||
SaveOutcome::CreatedNew(_) => "New entry created.".to_string(),
|
||||
}
|
||||
};
|
||||
if let Some(editor) = &mut app_state.form_editor {
|
||||
editor.cleanup_cursor()?;
|
||||
if let Page::Form(path) = &router.current {
|
||||
if let Some(editor) = app_state.editor_for_path(path) {
|
||||
editor.cleanup_cursor()?;
|
||||
}
|
||||
}
|
||||
terminal.cleanup()?;
|
||||
Ok(EventOutcome::Exit(format!(
|
||||
@@ -899,12 +931,8 @@ impl EventHandler {
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
if let Page::Form(_) = &router.current {
|
||||
revert(
|
||||
app_state,
|
||||
&mut self.grpc_client,
|
||||
)
|
||||
.await?
|
||||
if let Page::Form(path) = &router.current {
|
||||
revert(app_state, path, &mut self.grpc_client).await?
|
||||
} else {
|
||||
"Nothing to revert".to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user