Skip to content

Commit

Permalink
Clear search error when toggling fixed strings
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschafer committed Dec 2, 2024
1 parent 8dab768 commit 94cb8e6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
14 changes: 13 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,16 @@ impl SearchFields {
}
}

fn highlighted_field_impl(&self) -> &SearchField {
&self.fields[self.highlighted]
}

pub fn highlighted_field(&self) -> &Arc<RwLock<Field>> {
&self.fields[self.highlighted].field
&self.highlighted_field_impl().field
}

pub fn highlighted_field_name(&self) -> &FieldName {
&self.highlighted_field_impl().name
}

pub fn focus_next(&mut self) {
Expand Down Expand Up @@ -498,6 +506,10 @@ impl App {
self.search_fields.focus_next();
}
(code, modifiers) => {
if let FieldName::FixedStrings = self.search_fields.highlighted_field_name() {
// TODO: ideally this should only happen when the field is checked, but for now this will do
self.search_fields.search_mut().clear_error();
};
self.search_fields
.highlighted_field()
.write()
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ fn parse_log_level(s: &str) -> Result<LevelFilter, String> {
LevelFilter::from_str(s).map_err(|_| format!("Invalid log level: {}", s))
}

// In main(), update the logging setup:
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = Args::parse();
Expand Down
15 changes: 7 additions & 8 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ fn render_search_view(frame: &mut Frame<'_>, app: &App, rect: Rect) {
)
});

let highlighted_area = areas[app.search_fields.highlighted];
if let Some(cursor_idx) = app.search_fields.highlighted_field().read().cursor_idx() {
frame.set_cursor(
highlighted_area.x + cursor_idx as u16 + 1,
highlighted_area.y + 1,
)
}

if app.search_fields.show_error_popup {
let error_lines: Vec<Line<'_>> = app
.search_fields
Expand Down Expand Up @@ -102,6 +94,13 @@ fn render_search_view(frame: &mut Frame<'_>, app: &App, rect: Rect) {
.wrap(Wrap { trim: true });
frame.render_widget(Clear, popup_area);
frame.render_widget(popup, popup_area);
} else if let Some(cursor_idx) = app.search_fields.highlighted_field().read().cursor_idx() {
let highlighted_area = areas[app.search_fields.highlighted];

frame.set_cursor(
highlighted_area.x + cursor_idx as u16 + 1,
highlighted_area.y + 1,
)
}
}

Expand Down
3 changes: 0 additions & 3 deletions tests/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ fn test_text_field_operations() {
assert_eq!(field.text(), "Hello");
assert_eq!(field.cursor_idx(), 5);

// Test cursor movement
field.move_cursor_left();
assert_eq!(field.cursor_idx(), 4);
field.move_cursor_right();
Expand All @@ -27,7 +26,6 @@ fn test_text_field_operations() {
field.move_cursor_end();
assert_eq!(field.cursor_idx(), 5);

// Test word movement
field.clear();
for c in "Hello world".chars() {
field.enter_char(c);
Expand Down Expand Up @@ -68,7 +66,6 @@ fn test_checkbox_field() {
field.handle_keys(KeyCode::Char(' '), KeyModifiers::empty());
assert!(!field.checked);

// Test that other keys don't affect the checkbox
field.handle_keys(KeyCode::Enter, KeyModifiers::empty());
assert!(!field.checked);
}
Expand Down

0 comments on commit 94cb8e6

Please sign in to comment.