This commit is contained in:
Greg Shuflin committed 2024-03-19 09:45:10 -07:00
1 parent 9ac513ff62
commit f0e9859c75
2 files changed
+27 -22

No files matched your search

+8 -4
View File
@@ -21,10 +21,6 @@ pub(crate) struct TextBuffer {
//TODO consider try_ versions of rope methods to avoid panic
impl TextBuffer {
pub(crate) fn title(&self) -> Option<&str> {
self.title.as_ref().map(|x| x.as_str())
}
pub(crate) fn new() -> Self {
Self {
title: None,
@@ -46,6 +42,14 @@ impl TextBuffer {
buf
}
pub(crate) fn title(&self) -> Option<&str> {
self.title.as_ref().map(|x| x.as_str())
}
pub(crate) fn cursor(&self) -> Option<Cursor> {
Some(self.cursor_pos)
}
pub(crate) fn load_file(file: &Path) -> Result<Self, BasicError> {
info!(file=%file.display(), "Opening file");
+19 -18
View File
@@ -148,7 +148,6 @@ impl TerminalState {
cursor_style: Style,
line_number_style: Style,
) -> Vec<Line<'a>> {
let cursor = active_buffer.cursor_pos;
let expand_tab = active_buffer.buffer_settings.expand_tab;
// TODO do this more efficiently
@@ -160,27 +159,29 @@ impl TerminalState {
let mut text = vec![];
for (n, line) in raw_lines.into_iter().enumerate() {
let line_number = Span::styled(format!("{} ", n + 1), line_number_style);
if n == cursor.y() as usize {
let x = cursor.x() as usize;
match active_buffer.cursor() {
Some(cursor) if n == cursor.y() as usize => {
let x = cursor.x() as usize;
let screen_x = if x >= line.len() { line.len() } else { x };
let screen_x = if x >= line.len() { line.len() } else { x };
let cursor = Span::styled(" ", cursor_style);
let cursor = Span::styled(" ", cursor_style);
//TODO utf-8 issues
let (precursor, postcursor) = line.split_at(screen_x);
//TODO utf-8 issues
let (precursor, postcursor) = line.split_at(screen_x);
let rendered_precursor = process_line(precursor, expand_tab);
let rendered_postcursor = process_line(postcursor, expand_tab);
let rendered_precursor = process_line(precursor, expand_tab);
let rendered_postcursor = process_line(postcursor, expand_tab);
text.push(Line::from(vec![
line_number,
rendered_precursor.into(),
cursor,
rendered_postcursor.to_owned().into(),
]));
} else {
text.push(Line::from(vec![line_number, line.into()]));
text.push(Line::from(vec![
line_number,
rendered_precursor.into(),
cursor,
rendered_postcursor.to_owned().into(),
]));
}
_ => {
text.push(Line::from(vec![line_number, line.into()]));
}
}
}