use ratatui::Frame;
use ratatui::layout::Rect;
use ratatui::text::Span;
use super::line_editor::{EditorTheme, TruncationMarker};
use super::theme::*;
use ratatui::style::{Color, Style};
pub(crate) use super::line_editor::{Editor, apply_edit_key, apply_edit_key_full};
pub(crate) fn word_left(ed: &mut Editor) {
if ed.col == 0 {
ed.left();
return;
}
let chars: Vec<char> = ed.lines[ed.row].chars().collect();
let mut c = ed.col;
while c > 0 && chars[c - 1].is_whitespace() {
c -= 1;
}
while c > 0 && !chars[c - 1].is_whitespace() {
c -= 1;
}
ed.col = c;
}
pub(crate) fn word_right(ed: &mut Editor) {
let len = ed.line_len(ed.row);
if ed.col >= len {
ed.right();
return;
}
let chars: Vec<char> = ed.lines[ed.row].chars().collect();
let mut c = ed.col;
while c < len && chars[c].is_whitespace() {
c += 1;
}
while c < len && !chars[c].is_whitespace() {
c += 1;
}
ed.col = c;
}
fn editor_theme(th: &Theme) -> EditorTheme {
EditorTheme {
text: th.text,
panel: th.panel,
dim: th.dim,
select_fg: th.select_fg,
select_bg: th.select_bg,
}
}
pub(crate) fn render_editor(f: &mut Frame, area: Rect, ed: &Editor, masked: bool, th: &Theme) {
super::line_editor::render_editor(f, area, ed, &editor_theme(th), masked);
}
pub(crate) fn render_editor_highlighted(
f: &mut Frame,
area: Rect,
ed: &Editor,
th: &Theme,
highlight: impl Fn(usize, &str) -> Vec<Span<'static>>,
) {
super::line_editor::render_editor_highlighted(f, area, ed, &editor_theme(th), highlight);
}
pub(crate) fn render_line_field(
f: &mut Frame,
area: Rect,
ed: &Editor,
focused: bool,
mask: bool,
th: &Theme,
) {
super::line_editor::render_line_field(f, area, ed, &editor_theme(th), focused, mask);
}
pub(crate) fn render_clipped_line(f: &mut Frame, area: Rect, text: &str, color: Color, th: &Theme) {
let marker = TruncationMarker {
glyph: '\u{2026}',
style: Style::default().fg(th.dim),
};
super::line_editor::render_clipped_line(f, area, text, color, Some(marker));
}