working general mode only with canvas, removing highlight, readonly or edit

This commit is contained in:
filipriec
2025-08-23 23:34:14 +02:00
parent 88a4b2d69c
commit 06cc1663b3
6 changed files with 112 additions and 259 deletions

View File

@@ -318,7 +318,7 @@ impl EventHandler {
return Ok(EventOutcome::Ok(message));
}
if !matches!(current_mode, AppMode::Edit | AppMode::Command) {
if current_mode == AppMode::General {
if let Some(action) = config.get_action_for_key_in_mode(
&config.keybindings.global,
key_code,
@@ -352,9 +352,7 @@ impl EventHandler {
}
}
if let Some(action) =
config.get_general_action(key_code, modifiers)
{
if let Some(action) = config.get_general_action(key_code, modifiers) {
if action == "open_search" {
if let Page::Form(_) = &router.current {
if let Some(table_name) =
@@ -520,143 +518,35 @@ impl EventHandler {
}
}
AppMode::ReadOnly => {
// First let the canvas editor try to handle the key
if let Page::Form(_) = &router.current {
if let Some(editor) = &mut app_state.form_editor {
let outcome = editor.handle_key_event(key_event);
let new_mode = AppMode::from(editor.mode());
match outcome {
KeyEventOutcome::Consumed(Some(msg)) => {
app_state.update_mode(new_mode);
return Ok(EventOutcome::Ok(msg));
}
KeyEventOutcome::Consumed(None) => {
app_state.update_mode(new_mode);
return Ok(EventOutcome::Ok(String::new()));
}
KeyEventOutcome::Pending => {
app_state.update_mode(new_mode);
return Ok(EventOutcome::Ok(String::new()));
}
KeyEventOutcome::NotMatched => {
app_state.update_mode(new_mode);
// Fall through
AppMode::General => {
match &router.current {
Page::Form(_)
| Page::Login(_)
| Page::Register(_)
| Page::AddTable(_)
| Page::AddLogic(_) => {
if !app_state.ui.focus_outside_canvas {
if let Some(editor) = &mut app_state.form_editor {
editor.set_keymap(config.build_canvas_keymap());
match editor.handle_key_event(key_event) {
KeyEventOutcome::Consumed(Some(msg)) => {
return Ok(EventOutcome::Ok(msg));
}
KeyEventOutcome::Consumed(None) => {
return Ok(EventOutcome::Ok(String::new()));
}
KeyEventOutcome::Pending => {
return Ok(EventOutcome::Ok(String::new()));
}
KeyEventOutcome::NotMatched => {
// fall through to client actions
}
}
}
}
}
}
_ => {}
}
// Entering command mode is still a client-level action
if config.get_app_action(key_code, modifiers) == Some("enter_command_mode")
&& ModeManager::can_enter_command_mode(current_mode)
{
if let Some(editor) = &mut app_state.form_editor {
editor.set_mode(CanvasMode::Command);
}
self.command_mode = true;
self.command_input.clear();
self.command_message.clear();
return Ok(EventOutcome::Ok(String::new()));
}
// Handle common actions (save, quit, etc.)
if let Some(action) = config.get_app_action(key_code, modifiers) {
match action {
"save" | "force_quit" | "save_and_quit" | "revert" => {
return self
.handle_core_action(
action,
auth_state,
terminal,
app_state,
router,
)
.await;
}
_ => {}
}
}
return Ok(EventOutcome::Ok(self.command_message.clone()));
}
AppMode::Highlight => {
if let Page::Form(_) = &router.current {
if let Some(editor) = &mut app_state.form_editor {
let outcome = editor.handle_key_event(key_event);
let new_mode = AppMode::from(editor.mode());
match outcome {
KeyEventOutcome::Consumed(Some(msg)) => {
app_state.update_mode(new_mode);
return Ok(EventOutcome::Ok(msg));
}
KeyEventOutcome::Consumed(None) => {
app_state.update_mode(new_mode);
return Ok(EventOutcome::Ok(String::new()));
}
KeyEventOutcome::Pending => {
app_state.update_mode(new_mode);
return Ok(EventOutcome::Ok(String::new()));
}
KeyEventOutcome::NotMatched => {
app_state.update_mode(new_mode);
// Fall through
}
}
}
}
return Ok(EventOutcome::Ok(self.command_message.clone()));
}
AppMode::Edit => {
// Handle common actions (save, quit, etc.)
if let Some(action) = config.get_app_action(key_code, modifiers) {
match action {
"save" | "force_quit" | "save_and_quit" | "revert" => {
return self
.handle_core_action(
action,
auth_state,
terminal,
app_state,
router,
)
.await;
}
_ => {}
}
}
// Let the canvas editor handle edit-mode keys
if let Page::Form(_) = &router.current {
if let Some(editor) = &mut app_state.form_editor {
let outcome = editor.handle_key_event(key_event);
let new_mode = AppMode::from(editor.mode());
match outcome {
KeyEventOutcome::Consumed(Some(msg)) => {
self.command_message = msg.clone();
app_state.update_mode(new_mode);
return Ok(EventOutcome::Ok(msg));
}
KeyEventOutcome::Consumed(None) => {
app_state.update_mode(new_mode);
return Ok(EventOutcome::Ok(String::new()));
}
KeyEventOutcome::Pending => {
app_state.update_mode(new_mode);
return Ok(EventOutcome::Ok(String::new()));
}
KeyEventOutcome::NotMatched => {
app_state.update_mode(new_mode);
// Fall through
}
}
}
}
return Ok(EventOutcome::Ok(self.command_message.clone()));
}
AppMode::Command => {