mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-12 20:23:35 +00:00
parent
134854e688
commit
4b59808f84
@ -204,7 +204,7 @@ impl View for StackView {
|
|||||||
fn take_focus(&mut self, source: Direction) -> bool {
|
fn take_focus(&mut self, source: Direction) -> bool {
|
||||||
match self.layers.last_mut() {
|
match self.layers.last_mut() {
|
||||||
None => false,
|
None => false,
|
||||||
Some(mut v) => v.view.take_focus(source),
|
Some(v) => v.view.take_focus(source),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,10 +148,10 @@ impl TextArea {
|
|||||||
fn move_left(&mut self) {
|
fn move_left(&mut self) {
|
||||||
let len = {
|
let len = {
|
||||||
// We don't want to utf8-parse the entire content.
|
// We don't want to utf8-parse the entire content.
|
||||||
// So restrict to the last row.
|
// So only consider the last row.
|
||||||
let mut row = self.selected_row();
|
let mut row = self.selected_row();
|
||||||
if self.rows[row].start == self.cursor {
|
if self.rows[row].start == self.cursor {
|
||||||
row -= 1;
|
row = row.saturating_sub(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let text = &self.content[self.rows[row].start..self.cursor];
|
let text = &self.content[self.rows[row].start..self.cursor];
|
||||||
@ -179,7 +179,12 @@ impl TextArea {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are editing the text, we add a fake "space" character for the cursor to indicate
|
||||||
|
// where the next character will appear.
|
||||||
|
// If the current line is full, adding a character will overflow into the next line. To
|
||||||
|
// show that, we need to add a fake "ghost" row, just for the cursor.
|
||||||
fn fix_ghost_row(&mut self) {
|
fn fix_ghost_row(&mut self) {
|
||||||
|
|
||||||
if self.rows.is_empty() ||
|
if self.rows.is_empty() ||
|
||||||
self.rows.last().unwrap().end != self.content.len()
|
self.rows.last().unwrap().end != self.content.len()
|
||||||
{
|
{
|
||||||
@ -199,11 +204,13 @@ impl TextArea {
|
|||||||
// println_stderr!("Computing! Oh yeah!");
|
// println_stderr!("Computing! Oh yeah!");
|
||||||
|
|
||||||
let mut available = size.x;
|
let mut available = size.x;
|
||||||
|
|
||||||
self.rows = make_rows(&self.content, available);
|
self.rows = make_rows(&self.content, available);
|
||||||
self.fix_ghost_row();
|
self.fix_ghost_row();
|
||||||
|
|
||||||
if self.rows.len() > size.y {
|
if self.rows.len() > size.y {
|
||||||
available -= 1;
|
available = available.saturating_sub(1);
|
||||||
// Doh :(
|
// Apparently we'll need a scrollbar. Doh :(
|
||||||
self.rows = make_rows(&self.content, available);
|
self.rows = make_rows(&self.content, available);
|
||||||
self.fix_ghost_row();
|
self.fix_ghost_row();
|
||||||
}
|
}
|
||||||
@ -295,14 +302,12 @@ impl TextArea {
|
|||||||
|
|
||||||
// Find affected text.
|
// Find affected text.
|
||||||
// We know the damage started at this row, so it'll need to go.
|
// We know the damage started at this row, so it'll need to go.
|
||||||
let mut first_row = self.selected_row();
|
//
|
||||||
// Actually, if possible, also re-compute the previous row.
|
// Actually, if possible, also re-compute the previous row.
|
||||||
// Indeed, the previous row may have been cut short, and if we now
|
// Indeed, the previous row may have been cut short, and if we now
|
||||||
// break apart a big word, maybe the first half can go up one level.
|
// break apart a big word, maybe the first half can go up one level.
|
||||||
if first_row > 0 {
|
let first_row = self.selected_row().saturating_sub(1);
|
||||||
first_row -= 1;
|
|
||||||
}
|
|
||||||
// The
|
|
||||||
let first_byte = self.rows[first_row].start;
|
let first_byte = self.rows[first_row].start;
|
||||||
|
|
||||||
// We don't need to go beyond a newline.
|
// We don't need to go beyond a newline.
|
||||||
@ -328,7 +333,7 @@ impl TextArea {
|
|||||||
let scrollable = self.rows.len() > size.y;
|
let scrollable = self.rows.len() > size.y;
|
||||||
if scrollable {
|
if scrollable {
|
||||||
// ... not if a scrollbar is there
|
// ... not if a scrollbar is there
|
||||||
available -= 1;
|
available = available.saturating_sub(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// First attempt, if scrollbase status didn't change.
|
// First attempt, if scrollbase status didn't change.
|
||||||
@ -385,7 +390,7 @@ impl View for TextArea {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let w = if self.scrollbase.scrollable() {
|
let w = if self.scrollbase.scrollable() {
|
||||||
printer.size.x - 1
|
printer.size.x.saturating_sub(1)
|
||||||
} else {
|
} else {
|
||||||
printer.size.x
|
printer.size.x
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user