fix: handle absolute file paths in open file prompt
This commit is contained in:
parent
eae28536d2
commit
e39a118c70
2 changed files with 16 additions and 5 deletions
|
|
@ -1040,6 +1040,8 @@ pub fn abbreviate_home(buf: []u8, path: []const u8) []const u8 {
|
||||||
return "~";
|
return "~";
|
||||||
} else if (homerelpath.len > 3 and std.mem.eql(u8, homerelpath[0..3], "../")) {
|
} else if (homerelpath.len > 3 and std.mem.eql(u8, homerelpath[0..3], "../")) {
|
||||||
return path;
|
return path;
|
||||||
|
} else if (homerelpath.len + 2 > buf.len) {
|
||||||
|
return path;
|
||||||
} else {
|
} else {
|
||||||
buf[0] = '~';
|
buf[0] = '~';
|
||||||
buf[1] = '/';
|
buf[1] = '/';
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,24 @@ pub const Type = @import("file_browser.zig").Create(@This());
|
||||||
pub const create = Type.create;
|
pub const create = Type.create;
|
||||||
|
|
||||||
pub fn load_entries(self: *Type) error{ Exit, OutOfMemory }!void {
|
pub fn load_entries(self: *Type) error{ Exit, OutOfMemory }!void {
|
||||||
var project_name_buf: [512]u8 = undefined;
|
var path_buf: [512]u8 = undefined;
|
||||||
const project_path = tp.env.get().str("project");
|
const project_path = tp.env.get().str("project");
|
||||||
const project_name = project_manager.abbreviate_home(&project_name_buf, project_path);
|
const project_name = project_manager.abbreviate_home(&path_buf, project_path);
|
||||||
try self.file_path.appendSlice(self.allocator, project_name);
|
try self.file_path.appendSlice(self.allocator, project_name);
|
||||||
try self.file_path.append(self.allocator, std.fs.path.sep);
|
try self.file_path.append(self.allocator, std.fs.path.sep);
|
||||||
const editor = tui.get_active_editor() orelse return;
|
const editor = tui.get_active_editor() orelse return;
|
||||||
if (editor.file_path) |old_path|
|
if (editor.file_path) |old_path| {
|
||||||
if (std.mem.lastIndexOf(u8, old_path, "/")) |pos|
|
if (std.fs.path.dirname(old_path)) |dirname| {
|
||||||
try self.file_path.appendSlice(self.allocator, old_path[0 .. pos + 1]);
|
if (std.fs.path.isAbsolute(dirname)) {
|
||||||
|
const abbreviated_dirname = project_manager.abbreviate_home(&path_buf, dirname);
|
||||||
|
self.file_path.clearRetainingCapacity();
|
||||||
|
try self.file_path.appendSlice(self.allocator, abbreviated_dirname);
|
||||||
|
} else {
|
||||||
|
try self.file_path.appendSlice(self.allocator, dirname);
|
||||||
|
}
|
||||||
|
try self.file_path.append(self.allocator, std.fs.path.sep);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (editor.get_primary().selection) |sel| ret: {
|
if (editor.get_primary().selection) |sel| ret: {
|
||||||
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
const text = editor.get_selection(sel, self.allocator) catch break :ret;
|
||||||
defer self.allocator.free(text);
|
defer self.allocator.free(text);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue