Skip to content

feat: add --selected-row option for cursor positioning#7

Merged
dlyongemallo merged 1 commit into
mainfrom
feat_selected_row
Feb 6, 2026
Merged

feat: add --selected-row option for cursor positioning#7
dlyongemallo merged 1 commit into
mainfrom
feat_selected_row

Conversation

@dlyongemallo

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 6, 2026 16:06
@dlyongemallo dlyongemallo merged commit 8ef5221 into main Feb 6, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new --selected-row command-line option that allows users to position the cursor at a specific row when opening a diff view. The feature complements the existing --selected-file option by providing finer-grained control over the initial cursor position.

Changes:

  • Added selected_row option parsing in both Git and Hg adapters
  • Added type annotation and cursor positioning logic in the DiffView class
  • Added command-line completion for the new flag in GitAdapter

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lua/diffview/vcs/adapters/git/init.lua Parses the --selected-row flag and adds completion support for the new option
lua/diffview/vcs/adapters/hg/init.lua Parses the --selected-row flag in the Mercurial adapter
lua/diffview/scene/views/diff/diff_view.lua Adds type annotation for selected_row and implements cursor positioning logic on first view initialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

selected_file = argo:get_flag("selected-file", { no_empty = true, expand = true })
or (vim.bo.buftype == "" and pl:vim_expand("%:p"))
or nil,
selected_row = tonumber(argo:get_flag("selected-row", { no_empty = true })),

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HgAdapter is missing completion setup for the selected-row flag. While GitAdapter includes self.comp.open:put({ "selected-row" }) in its init_completion method (line 2262), HgAdapter's init_completion method doesn't set up any completion for the open command. Consider adding completion setup similar to GitAdapter to maintain consistency across adapters.

Copilot uses AI. Check for mistakes.
Comment on lines +521 to +528
-- Position cursor at the requested row on first open.
if not self.initialized and self.options.selected_row then
local win = self.cur_layout:get_main_win()
if win and api.nvim_win_is_valid(win.id) then
local buf = api.nvim_win_get_buf(win.id)
local line_count = api.nvim_buf_line_count(buf)
local row = math.min(self.options.selected_row, line_count)
pcall(api.nvim_win_set_cursor, win.id, { math.max(1, row), 0 })

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using utils.set_cursor instead of directly calling api.nvim_win_set_cursor with manual clamping. The codebase has a utility function utils.set_cursor(winid, line, column) that handles cursor positioning with automatic clamping and error handling, which would be more consistent with the rest of the codebase (e.g., see lines 53, 65 in lua/diffview/scene/views/file_history/listeners.lua or lines 292, 322, 388 in lua/diffview/scene/views/diff/file_panel.lua).

Copilot uses AI. Check for mistakes.
@dlyongemallo dlyongemallo deleted the feat_selected_row branch February 9, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants