removing highlightmode from the app, handled by the library now
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
// src/components/admin/add_logic.rs
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::app::highlight::HighlightState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::add_logic::{AddLogicFocus, AddLogicState};
|
||||
use canvas::{render_canvas, FormEditor};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// src/components/admin/add_table.rs
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::app::highlight::HighlightState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::add_table::{AddTableFocus, AddTableState};
|
||||
use canvas::{render_canvas_default, render_canvas, FormEditor};
|
||||
|
||||
@@ -12,7 +12,6 @@ use ratatui::{
|
||||
widgets::{Block, BorderType, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use crate::state::app::highlight::HighlightState;
|
||||
use canvas::{
|
||||
FormEditor,
|
||||
render_canvas,
|
||||
|
||||
@@ -13,18 +13,7 @@ use ratatui::{
|
||||
widgets::{Block, BorderType, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use crate::state::app::highlight::HighlightState;
|
||||
use canvas::{FormEditor, render_canvas_default, render_canvas, render_suggestions_dropdown, DefaultCanvasTheme};
|
||||
use canvas::canvas::HighlightState as CanvasHighlightState;
|
||||
|
||||
// Helper function to convert between HighlightState types
|
||||
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
|
||||
match local {
|
||||
HighlightState::Off => CanvasHighlightState::Off,
|
||||
HighlightState::Characterwise { anchor } => CanvasHighlightState::Characterwise { anchor: *anchor },
|
||||
HighlightState::Linewise { anchor_line } => CanvasHighlightState::Linewise { anchor_line: *anchor_line },
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_register(
|
||||
f: &mut Frame,
|
||||
|
||||
@@ -20,7 +20,6 @@ use canvas::{FormEditor, AppMode as CanvasMode};
|
||||
use crate::state::{
|
||||
app::{
|
||||
buffer::{AppView, BufferState},
|
||||
highlight::HighlightState,
|
||||
search::SearchState,
|
||||
state::AppState,
|
||||
},
|
||||
@@ -71,7 +70,6 @@ pub struct EventHandler {
|
||||
pub command_input: String,
|
||||
pub command_message: String,
|
||||
pub is_edit_mode: bool,
|
||||
pub highlight_state: HighlightState,
|
||||
pub edit_mode_cooldown: bool,
|
||||
pub ideal_cursor_column: usize,
|
||||
pub key_sequence_tracker: KeySequenceTracker,
|
||||
@@ -103,7 +101,6 @@ impl EventHandler {
|
||||
command_input: String::new(),
|
||||
command_message: String::new(),
|
||||
is_edit_mode: false,
|
||||
highlight_state: HighlightState::Off,
|
||||
edit_mode_cooldown: false,
|
||||
ideal_cursor_column: 0,
|
||||
key_sequence_tracker: KeySequenceTracker::new(400),
|
||||
@@ -653,45 +650,30 @@ impl EventHandler {
|
||||
}
|
||||
|
||||
AppMode::ReadOnly => {
|
||||
// Handle highlight mode transitions
|
||||
if config.get_read_only_action_for_key(key_code, modifiers) == Some("enter_highlight_mode_linewise")
|
||||
// Handle highlight mode transitions (delegated to FormEditor)
|
||||
if config.get_read_only_action_for_key(key_code, modifiers)
|
||||
== Some("enter_highlight_mode_linewise")
|
||||
&& ModeManager::can_enter_highlight_mode(current_mode)
|
||||
{
|
||||
let current_field_index = Self::get_current_field_for_state(
|
||||
app_state,
|
||||
login_state,
|
||||
register_state,
|
||||
form_state
|
||||
);
|
||||
self.highlight_state = HighlightState::Linewise {
|
||||
anchor_line: current_field_index
|
||||
};
|
||||
if let Some(editor) = &mut app_state.form_editor {
|
||||
editor.enter_highlight_line_mode();
|
||||
}
|
||||
self.command_message = "-- LINE HIGHLIGHT --".to_string();
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
else if config.get_read_only_action_for_key(key_code, modifiers) == Some("enter_highlight_mode")
|
||||
} else if config.get_read_only_action_for_key(key_code, modifiers)
|
||||
== Some("enter_highlight_mode")
|
||||
&& ModeManager::can_enter_highlight_mode(current_mode)
|
||||
{
|
||||
let current_field_index = Self::get_current_field_for_state(
|
||||
app_state,
|
||||
login_state,
|
||||
register_state,
|
||||
form_state
|
||||
);
|
||||
let current_cursor_pos = Self::get_current_cursor_pos_for_state(
|
||||
app_state,
|
||||
login_state,
|
||||
register_state,
|
||||
form_state
|
||||
);
|
||||
let anchor = (current_field_index, current_cursor_pos);
|
||||
self.highlight_state = HighlightState::Characterwise { anchor };
|
||||
if let Some(editor) = &mut app_state.form_editor {
|
||||
editor.enter_highlight_mode();
|
||||
}
|
||||
self.command_message = "-- HIGHLIGHT --".to_string();
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
|
||||
// Handle edit mode transitions
|
||||
else if config.get_read_only_action_for_key(key_code, modifiers).as_deref() == Some("enter_edit_mode_before")
|
||||
else if config.get_read_only_action_for_key(key_code, modifiers).as_deref()
|
||||
== Some("enter_edit_mode_before")
|
||||
&& ModeManager::can_enter_edit_mode(current_mode)
|
||||
{
|
||||
if let Some(editor) = &mut app_state.form_editor {
|
||||
@@ -701,21 +683,18 @@ impl EventHandler {
|
||||
self.edit_mode_cooldown = true;
|
||||
self.command_message = "Edit mode".to_string();
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
else if config.get_read_only_action_for_key(key_code, modifiers).as_deref() == Some("enter_edit_mode_after")
|
||||
} else if config.get_read_only_action_for_key(key_code, modifiers).as_deref()
|
||||
== Some("enter_edit_mode_after")
|
||||
&& ModeManager::can_enter_edit_mode(current_mode)
|
||||
{
|
||||
let current_input = Self::get_current_input_for_state(
|
||||
app_state,
|
||||
login_state,
|
||||
register_state,
|
||||
form_state
|
||||
);
|
||||
let current_cursor_pos = Self::get_cursor_pos_for_mixed_state(
|
||||
app_state,
|
||||
login_state,
|
||||
form_state
|
||||
form_state,
|
||||
);
|
||||
let current_cursor_pos =
|
||||
Self::get_cursor_pos_for_mixed_state(app_state, login_state, form_state);
|
||||
|
||||
// Move cursor forward if possible
|
||||
if !current_input.is_empty() && current_cursor_pos < current_input.len() {
|
||||
@@ -725,13 +704,13 @@ impl EventHandler {
|
||||
login_state,
|
||||
register_state,
|
||||
form_state,
|
||||
new_cursor_pos
|
||||
new_cursor_pos,
|
||||
);
|
||||
self.ideal_cursor_column = Self::get_current_cursor_pos_for_state(
|
||||
app_state,
|
||||
login_state,
|
||||
register_state,
|
||||
form_state
|
||||
form_state,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -743,8 +722,8 @@ impl EventHandler {
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
self.command_message = "Edit mode (after cursor)".to_string();
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
else if config.get_read_only_action_for_key(key_code, modifiers) == Some("enter_command_mode")
|
||||
} else if config.get_read_only_action_for_key(key_code, modifiers)
|
||||
== Some("enter_command_mode")
|
||||
&& ModeManager::can_enter_command_mode(current_mode)
|
||||
{
|
||||
if let Some(editor) = &mut app_state.form_editor {
|
||||
@@ -779,12 +758,9 @@ impl EventHandler {
|
||||
// Try canvas action for form first
|
||||
if app_state.ui.show_form {
|
||||
if let Some(editor) = &mut app_state.form_editor {
|
||||
if let Ok(Some(canvas_message)) = self.handle_form_canvas_action(
|
||||
key_event,
|
||||
editor,
|
||||
config,
|
||||
false,
|
||||
).await {
|
||||
if let Ok(Some(canvas_message)) =
|
||||
self.handle_form_canvas_action(key_event, editor, config, false).await
|
||||
{
|
||||
return Ok(EventOutcome::Ok(canvas_message));
|
||||
}
|
||||
}
|
||||
@@ -794,20 +770,22 @@ impl EventHandler {
|
||||
}
|
||||
|
||||
AppMode::Highlight => {
|
||||
if config.get_highlight_action_for_key(key_code, modifiers) == Some("exit_highlight_mode") {
|
||||
if config.get_highlight_action_for_key(key_code, modifiers)
|
||||
== Some("exit_highlight_mode")
|
||||
{
|
||||
if let Some(editor) = &mut app_state.form_editor {
|
||||
editor.exit_highlight_mode();
|
||||
}
|
||||
self.highlight_state = HighlightState::Off;
|
||||
self.command_message = "Exited highlight mode".to_string();
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
} else if config.get_highlight_action_for_key(key_code, modifiers) == Some("enter_highlight_mode_linewise") {
|
||||
if let HighlightState::Characterwise { anchor } = self.highlight_state {
|
||||
self.highlight_state = HighlightState::Linewise { anchor_line: anchor.0 };
|
||||
self.command_message = "-- LINE HIGHLIGHT --".to_string();
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
} else if config.get_highlight_action_for_key(key_code, modifiers)
|
||||
== Some("enter_highlight_mode_linewise")
|
||||
{
|
||||
if let Some(editor) = &mut app_state.form_editor {
|
||||
editor.enter_highlight_line_mode();
|
||||
}
|
||||
return Ok(EventOutcome::Ok("".to_string()));
|
||||
self.command_message = "-- LINE HIGHLIGHT --".to_string();
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
}
|
||||
|
||||
return Ok(EventOutcome::Ok(self.command_message.clone()));
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::modes::handlers::event::EventHandler;
|
||||
use crate::state::pages::add_logic::AddLogicFocus;
|
||||
use crate::state::app::highlight::HighlightState;
|
||||
use crate::state::pages::admin::AdminState;
|
||||
use canvas::AppMode as CanvasMode;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum AppMode {
|
||||
@@ -31,8 +31,11 @@ impl ModeManager {
|
||||
return AppMode::Command;
|
||||
}
|
||||
|
||||
if !matches!(event_handler.highlight_state, HighlightState::Off) {
|
||||
return AppMode::Highlight;
|
||||
// NEW: delegate highlight detection to FormEditor
|
||||
if let Some(editor) = &app_state.form_editor {
|
||||
if editor.mode() == CanvasMode::Highlight {
|
||||
return AppMode::Highlight;
|
||||
}
|
||||
}
|
||||
|
||||
let is_canvas_view = app_state.ui.show_login
|
||||
@@ -42,39 +45,33 @@ impl ModeManager {
|
||||
|| app_state.ui.show_add_logic;
|
||||
|
||||
if app_state.ui.show_add_logic {
|
||||
// Specific logic for AddLogic view
|
||||
match admin_state.add_logic_state.current_focus {
|
||||
AddLogicFocus::InputLogicName
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
| AddLogicFocus::InputDescription => {
|
||||
// These are canvas inputs
|
||||
if event_handler.is_edit_mode {
|
||||
AppMode::Edit
|
||||
} else {
|
||||
AppMode::ReadOnly
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
| AddLogicFocus::InputDescription => {
|
||||
if event_handler.is_edit_mode {
|
||||
AppMode::Edit
|
||||
} else {
|
||||
AppMode::ReadOnly
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => AppMode::General,
|
||||
}
|
||||
} else if app_state.ui.show_add_table {
|
||||
if app_state.ui.focus_outside_canvas {
|
||||
AppMode::General
|
||||
} else if event_handler.is_edit_mode {
|
||||
AppMode::Edit
|
||||
} else {
|
||||
if event_handler.is_edit_mode {
|
||||
AppMode::Edit
|
||||
} else {
|
||||
AppMode::ReadOnly
|
||||
}
|
||||
AppMode::ReadOnly
|
||||
}
|
||||
} else if is_canvas_view {
|
||||
if app_state.ui.focus_outside_canvas {
|
||||
AppMode::General
|
||||
} else if event_handler.is_edit_mode {
|
||||
AppMode::Edit
|
||||
} else {
|
||||
if event_handler.is_edit_mode {
|
||||
AppMode::Edit
|
||||
} else {
|
||||
AppMode::ReadOnly
|
||||
}
|
||||
AppMode::ReadOnly
|
||||
}
|
||||
} else {
|
||||
AppMode::General
|
||||
|
||||
@@ -3,4 +3,3 @@
|
||||
pub mod state;
|
||||
pub mod buffer;
|
||||
pub mod search;
|
||||
pub mod highlight;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// src/state/app/highlight.rs
|
||||
|
||||
/// Represents the different states of text highlighting.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum HighlightState {
|
||||
/// Highlighting is inactive.
|
||||
Off,
|
||||
/// Highlighting character by character. Stores the anchor point (line index, char index).
|
||||
Characterwise { anchor: (usize, usize) },
|
||||
/// Highlighting line by line. Stores the anchor line index.
|
||||
Linewise { anchor_line: usize },
|
||||
}
|
||||
|
||||
impl Default for HighlightState {
|
||||
/// The default state is no highlighting.
|
||||
fn default() -> Self {
|
||||
HighlightState::Off
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use crate::config::colors::themes::Theme;
|
||||
use canvas::{DataProvider, AppMode, EditorState, FormEditor};
|
||||
use canvas::canvas::HighlightState;
|
||||
use common::proto::komp_ac::search::search_response::Hit;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::Frame;
|
||||
@@ -123,7 +122,6 @@ impl FormState {
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
is_edit_mode: bool,
|
||||
highlight_state: &HighlightState,
|
||||
) {
|
||||
// Wrap in FormEditor for new API
|
||||
let mut editor = FormEditor::new(self.clone());
|
||||
|
||||
@@ -17,8 +17,6 @@ use crate::components::{
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::modes::general::command_navigation::NavigationState;
|
||||
use crate::state::app::buffer::BufferState;
|
||||
use crate::state::app::highlight::HighlightState as LocalHighlightState;
|
||||
use canvas::canvas::HighlightState as CanvasHighlightState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::admin::AdminState;
|
||||
use crate::state::pages::auth::AuthState;
|
||||
@@ -31,15 +29,6 @@ use ratatui::{
|
||||
Frame,
|
||||
};
|
||||
|
||||
// Helper function to convert between HighlightState types
|
||||
fn convert_highlight_state(local: &LocalHighlightState) -> CanvasHighlightState {
|
||||
match local {
|
||||
LocalHighlightState::Off => CanvasHighlightState::Off,
|
||||
LocalHighlightState::Characterwise { anchor } => CanvasHighlightState::Characterwise { anchor: *anchor },
|
||||
LocalHighlightState::Linewise { anchor_line } => CanvasHighlightState::Linewise { anchor_line: *anchor_line },
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn render_ui(
|
||||
f: &mut Frame,
|
||||
@@ -52,7 +41,6 @@ pub fn render_ui(
|
||||
buffer_state: &BufferState,
|
||||
theme: &Theme,
|
||||
is_event_handler_edit_mode: bool,
|
||||
highlight_state: &LocalHighlightState, // Keep using local version
|
||||
event_handler_command_input: &str,
|
||||
event_handler_command_mode_active: bool,
|
||||
event_handler_command_message: &str,
|
||||
@@ -205,13 +193,11 @@ pub fn render_ui(
|
||||
};
|
||||
|
||||
// CHANGED: Convert local HighlightState to canvas HighlightState for FormState
|
||||
let canvas_highlight_state = convert_highlight_state(highlight_state);
|
||||
form_state.render(
|
||||
f,
|
||||
form_render_area,
|
||||
theme,
|
||||
is_event_handler_edit_mode,
|
||||
&canvas_highlight_state, // Use converted version
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -599,7 +599,6 @@ pub async fn run_ui() -> Result<()> {
|
||||
&buffer_state,
|
||||
&theme,
|
||||
event_handler.is_edit_mode,
|
||||
&event_handler.highlight_state,
|
||||
&event_handler.command_input,
|
||||
event_handler.command_mode,
|
||||
&event_handler.command_message,
|
||||
|
||||
Reference in New Issue
Block a user