clean up selection rendering
This commit is contained in:
parent
df0b6b6ff0
commit
a5ce49576b
1 changed files with 17 additions and 20 deletions
|
@ -169,25 +169,22 @@ impl Editor {
|
||||||
let end = (self.scroll + max_rows).min(self.lines.len());
|
let end = (self.scroll + max_rows).min(self.lines.len());
|
||||||
let visible_rows = self.scroll..end;
|
let visible_rows = self.scroll..end;
|
||||||
|
|
||||||
let cursor = self.char_index();
|
let selection = self.selection().unwrap_or_default();
|
||||||
let marker = self.marker.unwrap_or(0);
|
|
||||||
let selection = (marker.min(cursor))..(marker.max(cursor));
|
|
||||||
|
|
||||||
for (line_index, line) in self.lines[visible_rows].iter().enumerate() {
|
for (line_index, line) in self.lines[visible_rows].iter().enumerate() {
|
||||||
let text = &self.text[line.clone()];
|
let text = &self.text[line.clone()];
|
||||||
|
|
||||||
queue!(stdout(), MoveTo(0, line_index as u16)).unwrap();
|
queue!(stdout(), MoveTo(0, line_index as u16)).unwrap();
|
||||||
|
|
||||||
if self.marker.is_none() {
|
|
||||||
print!("{}", text.replace('\t', &" ".repeat(TAB_SIZE)));
|
|
||||||
} else {
|
|
||||||
let mut in_selection = false;
|
let mut in_selection = false;
|
||||||
for (i, char) in text.char_indices() {
|
for (i, char) in text.char_indices() {
|
||||||
let char_i = line.start + i;
|
let char_i = line.start + i;
|
||||||
if char_i >= selection.start && char_i <= selection.end && !in_selection {
|
if selection.contains(&char_i) {
|
||||||
|
if !in_selection {
|
||||||
color_highlight();
|
color_highlight();
|
||||||
in_selection = true;
|
in_selection = true;
|
||||||
} else if char_i > selection.end && in_selection {
|
}
|
||||||
|
} else if in_selection {
|
||||||
color_reset();
|
color_reset();
|
||||||
in_selection = false;
|
in_selection = false;
|
||||||
}
|
}
|
||||||
|
@ -199,7 +196,6 @@ impl Editor {
|
||||||
}
|
}
|
||||||
color_reset();
|
color_reset();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
self.status_line();
|
self.status_line();
|
||||||
queue!(
|
queue!(
|
||||||
stdout(),
|
stdout(),
|
||||||
|
@ -207,7 +203,8 @@ impl Editor {
|
||||||
self.physical_column() as u16,
|
self.physical_column() as u16,
|
||||||
(self.cursor.line - self.scroll) as u16
|
(self.cursor.line - self.scroll) as u16
|
||||||
),
|
),
|
||||||
cursor::Show
|
cursor::Show,
|
||||||
|
cursor::SetCursorStyle::BlinkingBar
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
stdout().flush().unwrap();
|
stdout().flush().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue