add logic now using general movement
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// src/pages/admin_panel/add_logic/state.rs
|
||||
use crate::config::binds::config::{EditorConfig, EditorKeybindingMode};
|
||||
use crate::components::common::text_editor::{TextEditor, VimState};
|
||||
use canvas::{DataProvider, AppMode, FormEditor};
|
||||
use canvas::{DataProvider, AppMode, FormEditor, SuggestionItem};
|
||||
use crossterm::event::KeyCode;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use tui_textarea::TextArea;
|
||||
@@ -98,6 +99,19 @@ impl AddLogicState {
|
||||
|
||||
pub const INPUT_FIELD_COUNT: usize = 3;
|
||||
|
||||
/// Build canvas SuggestionItem list for target column
|
||||
pub fn column_suggestions_sync(&self, query: &str) -> Vec<SuggestionItem> {
|
||||
let q = query.to_lowercase();
|
||||
self.table_columns_for_suggestions
|
||||
.iter()
|
||||
.filter(|c| q.is_empty() || c.to_lowercase().contains(&q))
|
||||
.map(|c| SuggestionItem {
|
||||
display_text: c.clone(),
|
||||
value_to_store: c.clone(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Updates the target_column_suggestions based on current input.
|
||||
pub fn update_target_column_suggestions(&mut self) {
|
||||
let current_input = self.target_column_input.to_lowercase();
|
||||
@@ -450,6 +464,84 @@ impl AddLogicFormState {
|
||||
&mut self,
|
||||
key_event: crossterm::event::KeyEvent,
|
||||
) -> canvas::keymap::KeyEventOutcome {
|
||||
// Customize behavior for Target Column (field index 1) in Edit mode,
|
||||
// mirroring how Register page does suggestions for Role.
|
||||
let in_target_col_field = self.editor.current_field() == 1;
|
||||
let in_edit_mode = self.editor.mode() == canvas::AppMode::Edit;
|
||||
|
||||
if in_target_col_field && in_edit_mode {
|
||||
match key_event.code {
|
||||
// Tab: open suggestions if inactive; otherwise cycle next
|
||||
KeyCode::Tab => {
|
||||
if !self.editor.is_suggestions_active() {
|
||||
if let Some(query) = self.editor.start_suggestions(1) {
|
||||
let items = self.state.column_suggestions_sync(&query);
|
||||
let applied =
|
||||
self.editor.apply_suggestions_result(1, &query, items);
|
||||
if applied {
|
||||
self.editor.update_inline_completion();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.editor.suggestions_next();
|
||||
}
|
||||
return canvas::keymap::KeyEventOutcome::Consumed(None);
|
||||
}
|
||||
// Shift+Tab: cycle suggestions too (fallback to next)
|
||||
KeyCode::BackTab => {
|
||||
if self.editor.is_suggestions_active() {
|
||||
self.editor.suggestions_next();
|
||||
return canvas::keymap::KeyEventOutcome::Consumed(None);
|
||||
}
|
||||
}
|
||||
// Enter: apply selected suggestion (if active)
|
||||
KeyCode::Enter => {
|
||||
if self.editor.is_suggestions_active() {
|
||||
let _ = self.editor.apply_suggestion();
|
||||
return canvas::keymap::KeyEventOutcome::Consumed(None);
|
||||
}
|
||||
}
|
||||
// Esc: close suggestions if active
|
||||
KeyCode::Esc => {
|
||||
if self.editor.is_suggestions_active() {
|
||||
self.editor.close_suggestions();
|
||||
return canvas::keymap::KeyEventOutcome::Consumed(None);
|
||||
}
|
||||
}
|
||||
// Character input: mutate then refresh suggestions if active
|
||||
KeyCode::Char(_) => {
|
||||
let outcome = self.editor.handle_key_event(key_event);
|
||||
if self.editor.is_suggestions_active() {
|
||||
if let Some(query) = self.editor.start_suggestions(1) {
|
||||
let items = self.state.column_suggestions_sync(&query);
|
||||
let applied =
|
||||
self.editor.apply_suggestions_result(1, &query, items);
|
||||
if applied {
|
||||
self.editor.update_inline_completion();
|
||||
}
|
||||
}
|
||||
}
|
||||
return outcome;
|
||||
}
|
||||
// Backspace/Delete: mutate then refresh suggestions if active
|
||||
KeyCode::Backspace | KeyCode::Delete => {
|
||||
let outcome = self.editor.handle_key_event(key_event);
|
||||
if self.editor.is_suggestions_active() {
|
||||
if let Some(query) = self.editor.start_suggestions(1) {
|
||||
let items = self.state.column_suggestions_sync(&query);
|
||||
let applied =
|
||||
self.editor.apply_suggestions_result(1, &query, items);
|
||||
if applied {
|
||||
self.editor.update_inline_completion();
|
||||
}
|
||||
}
|
||||
}
|
||||
return outcome;
|
||||
}
|
||||
_ => { /* fall through */ }
|
||||
}
|
||||
}
|
||||
// Default: let canvas handle it
|
||||
self.editor.handle_key_event(key_event)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user