Basic search mechanism in editor

This commit is contained in:
2026-01-26 01:25:40 +01:00
parent 4ae8e28b2f
commit bde64e7dc5
4 changed files with 141 additions and 17 deletions

View File

@@ -570,8 +570,30 @@ fn render_modal(frame: &mut Frame, app: &App, snapshot: &SequencerSnapshot, term
highlight::highlight_line_with_runtime(line, &exec, &sel)
};
let editor_area = Rect::new(inner.x, inner.y, inner.width, inner.height.saturating_sub(1));
let hint_area = Rect::new(inner.x, inner.y + editor_area.height, inner.width, 1);
let show_search = app.editor_ctx.editor.search_active()
|| !app.editor_ctx.editor.search_query().is_empty();
let (search_area, editor_area, hint_area) = if show_search {
let search_area = Rect::new(inner.x, inner.y, inner.width, 1);
let editor_area = Rect::new(inner.x, inner.y + 1, inner.width, inner.height.saturating_sub(2));
let hint_area = Rect::new(inner.x, inner.y + 1 + editor_area.height, inner.width, 1);
(Some(search_area), editor_area, hint_area)
} else {
let editor_area = Rect::new(inner.x, inner.y, inner.width, inner.height.saturating_sub(1));
let hint_area = Rect::new(inner.x, inner.y + editor_area.height, inner.width, 1);
(None, editor_area, hint_area)
};
if let Some(sa) = search_area {
let style = if app.editor_ctx.editor.search_active() {
Style::default().fg(Color::Yellow)
} else {
Style::default().fg(Color::DarkGray)
};
let cursor = if app.editor_ctx.editor.search_active() { "_" } else { "" };
let text = format!("/{}{}", app.editor_ctx.editor.search_query(), cursor);
frame.render_widget(Paragraph::new(Line::from(Span::styled(text, style))), sa);
}
if let Some(kind) = flash_kind {
let bg = match kind {
@@ -586,17 +608,22 @@ fn render_modal(frame: &mut Frame, app: &App, snapshot: &SequencerSnapshot, term
let dim = Style::default().fg(Color::DarkGray);
let key = Style::default().fg(Color::Yellow);
let hint = Line::from(vec![
Span::styled("Esc", key), Span::styled(" save ", dim),
Span::styled("C-e", key), Span::styled(" eval ", dim),
Span::styled("C-u", key), Span::styled("/", dim),
Span::styled("C-r", key), Span::styled(" undo/redo ", dim),
Span::styled("C-j", key), Span::styled("/", dim),
Span::styled("C-k", key), Span::styled(" del-bol/eol ", dim),
Span::styled("C-x", key), Span::styled("/", dim),
Span::styled("C-c", key), Span::styled("/", dim),
Span::styled("C-y", key), Span::styled(" cut/copy/paste ", dim),
]);
let hint = if app.editor_ctx.editor.search_active() {
Line::from(vec![
Span::styled("Enter", key), Span::styled(" confirm ", dim),
Span::styled("Esc", key), Span::styled(" cancel", dim),
])
} else {
Line::from(vec![
Span::styled("Esc", key), Span::styled(" save ", dim),
Span::styled("C-e", key), Span::styled(" eval ", dim),
Span::styled("C-f", key), Span::styled(" find ", dim),
Span::styled("C-n", key), Span::styled("/", dim),
Span::styled("C-p", key), Span::styled(" next/prev ", dim),
Span::styled("C-u", key), Span::styled("/", dim),
Span::styled("C-r", key), Span::styled(" undo/redo", dim),
])
};
frame.render_widget(Paragraph::new(hint).alignment(Alignment::Right), hint_area);
}
}