Skip to content

Commit

Permalink
Place cursor at filename not at the end of filename.
Browse files Browse the repository at this point in the history
  • Loading branch information
X3eRo0 committed Feb 27, 2024
1 parent 6680c60 commit 4224c9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 7 additions & 5 deletions lua/dired/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ function M.flush_buffer()
vim.api.nvim_buf_set_lines(0, 0, -1, true, M.buffer)
end

-- Move the cursor to the right end of a file name. This makes file icons and names
-- more visible. This is actually the default cursor behavior in nvim-tree.lua.
M.cursor_pos[2] = string.len(vim.fn.getline(5));
vim.bo.undolevels = undolevels
vim.api.nvim_win_set_cursor(0, M.cursor_pos)
vim.bo.modified = false
Expand Down Expand Up @@ -72,8 +69,13 @@ function M.get_directory_listing(directory)
info1 = string.format("%s:", fs.get_simplified_path(directory))
info2 = string.format("total used in directory %s:", dir_size_str)
end
local formatted_components, cursor_x =
ls.fs_entry.format(dir_files, vim.g.dired_show_dot_dirs, vim.g.dired_show_hidden, vim.g.dired_hide_details)
local formatted_components, cursor_x = ls.fs_entry.format(
dir_files,
vim.g.dired_show_dot_dirs,
vim.g.dired_show_hidden,
vim.g.dired_hide_details,
vim.g.dired_show_icons
)
table.insert(buffer_listing, { component = nil, line = info1 })
table.insert(buffer_listing, { component = nil, line = info2 })

Expand Down
8 changes: 6 additions & 2 deletions lua/dired/ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function fs_entry.get_directory(directory)
break
end

-- get file type of the file
-- get file type of the file
local proper_filetype = filetype_module.get_filetype(filename, filetype)

-- get fullpath of the file
Expand All @@ -150,7 +150,7 @@ function fs_entry.get_directory(directory)
end

-- function to format each component
function fs_entry.format(dir_files, show_dot_dirs, show_hidden, hide_details)
function fs_entry.format(dir_files, show_dot_dirs, show_hidden, hide_details, show_icon)
-- components :
-- 1. permissions
-- 2. # of links
Expand Down Expand Up @@ -263,6 +263,10 @@ function fs_entry.format(dir_files, show_dot_dirs, show_hidden, hide_details)
cursor_x = cursor_x + 8
end

if show_icon then
cursor_x = cursor_x + 1
end

if not hide_details then
-- we now have length for formatting
-- we now format the listing properly
Expand Down

0 comments on commit 4224c9a

Please sign in to comment.