Fix crash when using vi visual selection on empty buffer
This commit is contained in:
@@ -3489,6 +3489,9 @@ impl LineBuf {
|
|||||||
impl Display for LineBuf {
|
impl Display for LineBuf {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let mut full_buf = self.buffer.clone();
|
let mut full_buf = self.buffer.clone();
|
||||||
|
if full_buf.is_empty() {
|
||||||
|
return write!(f, "{}", full_buf);
|
||||||
|
}
|
||||||
if let Some((start, end)) = self.select_range() {
|
if let Some((start, end)) = self.select_range() {
|
||||||
let mode = self.select_mode.unwrap();
|
let mode = self.select_mode.unwrap();
|
||||||
let start_byte = self.read_idx_byte_pos(start);
|
let start_byte = self.read_idx_byte_pos(start);
|
||||||
@@ -3497,7 +3500,7 @@ impl Display for LineBuf {
|
|||||||
match mode.anchor() {
|
match mode.anchor() {
|
||||||
SelectAnchor::Start => {
|
SelectAnchor::Start => {
|
||||||
let mut inclusive = start_byte..=end_byte;
|
let mut inclusive = start_byte..=end_byte;
|
||||||
if *inclusive.end() == full_buf.len() {
|
if *inclusive.end() >= full_buf.len() {
|
||||||
inclusive = start_byte..=end_byte.saturating_sub(1);
|
inclusive = start_byte..=end_byte.saturating_sub(1);
|
||||||
}
|
}
|
||||||
let selected = format!(
|
let selected = format!(
|
||||||
|
|||||||
@@ -225,5 +225,6 @@ vi_test! {
|
|||||||
vi_dollar_single : "h" => "$" => "h", 0;
|
vi_dollar_single : "h" => "$" => "h", 0;
|
||||||
vi_caret_no_ws : "hello" => "$^" => "hello", 0;
|
vi_caret_no_ws : "hello" => "$^" => "hello", 0;
|
||||||
vi_f_last_char : "hello" => "fo" => "hello", 4;
|
vi_f_last_char : "hello" => "fo" => "hello", 4;
|
||||||
vi_r_on_space : "hello world" => "5|r-" => "hell- world", 4
|
vi_r_on_space : "hello world" => "5|r-" => "hell- world", 4;
|
||||||
|
vi_vw_doesnt_crash : "" => "vw" => "", 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user