Fix panic in ctrl-g (#33474)

Release Notes:

- vim: Fixed a crash with ctrl-g
This commit is contained in:
Conrad Irwin 2025-06-26 21:26:58 -06:00 committed by GitHub
parent 20a3e613b8
commit 8c9116daa5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -30,7 +30,7 @@ use editor::scroll::Autoscroll;
use editor::{Anchor, SelectionEffects}; use editor::{Anchor, SelectionEffects};
use editor::{display_map::ToDisplayPoint, movement}; use editor::{display_map::ToDisplayPoint, movement};
use gpui::{Context, Window, actions}; use gpui::{Context, Window, actions};
use language::{Point, SelectionGoal, ToPoint}; use language::{Point, SelectionGoal};
use log::error; use log::error;
use multi_buffer::MultiBufferRow; use multi_buffer::MultiBufferRow;
@ -663,38 +663,42 @@ impl Vim {
Vim::take_forced_motion(cx); Vim::take_forced_motion(cx);
self.update_editor(window, cx, |vim, editor, _window, cx| { self.update_editor(window, cx, |vim, editor, _window, cx| {
let selection = editor.selections.newest_anchor(); let selection = editor.selections.newest_anchor();
if let Some((_, buffer, _)) = editor.active_excerpt(cx) { let Some((buffer, point, _)) = editor
let filename = if let Some(file) = buffer.read(cx).file() { .buffer()
if count.is_some() { .read(cx)
if let Some(local) = file.as_local() { .point_to_buffer_point(selection.head(), cx)
local.abs_path(cx).to_string_lossy().to_string() else {
} else { return;
file.full_path(cx).to_string_lossy().to_string() };
} let filename = if let Some(file) = buffer.read(cx).file() {
if count.is_some() {
if let Some(local) = file.as_local() {
local.abs_path(cx).to_string_lossy().to_string()
} else { } else {
file.path().to_string_lossy().to_string() file.full_path(cx).to_string_lossy().to_string()
} }
} else { } else {
"[No Name]".into() file.path().to_string_lossy().to_string()
}; }
let buffer = buffer.read(cx); } else {
let snapshot = buffer.snapshot(); "[No Name]".into()
let lines = buffer.max_point().row + 1; };
let current_line = selection.head().text_anchor.to_point(&snapshot).row; let buffer = buffer.read(cx);
let percentage = current_line as f32 / lines as f32; let lines = buffer.max_point().row + 1;
let modified = if buffer.is_dirty() { " [modified]" } else { "" }; let current_line = point.row;
vim.status_label = Some( let percentage = current_line as f32 / lines as f32;
format!( let modified = if buffer.is_dirty() { " [modified]" } else { "" };
"{}{} {} lines --{:.0}%--", vim.status_label = Some(
filename, format!(
modified, "{}{} {} lines --{:.0}%--",
lines, filename,
percentage * 100.0, modified,
) lines,
.into(), percentage * 100.0,
); )
cx.notify(); .into(),
} );
cx.notify();
}); });
} }