open_file: fix possible underflow in delete_to_previous_path_segment
When opening a file, if one writes only "/" then presses ctrl+backspace the "path" slice will end up [0 .. -1]. This crashes in debug build, and possibly in some rare circumstances in release build.
This commit is contained in:
parent
d11ea9dde4
commit
c3603443f9
1 changed files with 4 additions and 0 deletions
|
@ -228,6 +228,10 @@ fn process_project_manager(self: *Self, m: tp.message) !void {
|
||||||
fn delete_to_previous_path_segment(self: *Self) void {
|
fn delete_to_previous_path_segment(self: *Self) void {
|
||||||
self.complete_trigger_count = 0;
|
self.complete_trigger_count = 0;
|
||||||
if (self.file_path.items.len == 0) return;
|
if (self.file_path.items.len == 0) return;
|
||||||
|
if (self.file_path.items.len == 1) {
|
||||||
|
self.file_path.clearRetainingCapacity();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const path = if (self.file_path.items[self.file_path.items.len - 1] == std.fs.path.sep)
|
const path = if (self.file_path.items[self.file_path.items.len - 1] == std.fs.path.sep)
|
||||||
self.file_path.items[0 .. self.file_path.items.len - 2]
|
self.file_path.items[0 .. self.file_path.items.len - 2]
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue