Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project and buffer diff previews header keymaps broken #388

Closed
dpetka2001 opened this issue Feb 4, 2025 · 6 comments
Closed

Project and buffer diff previews header keymaps broken #388

dpetka2001 opened this issue Feb 4, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@dpetka2001
Copy link

Description

After this commit 6b7592c which tried to create a new feature for #377, the mappings in the header for each diff preview are showing nil (nil).

  • nvim --version output: NVIM v0.11.0-dev-1693+g8ce2833411
  • Operating system: Linux Mint 21.3
@dpetka2001 dpetka2001 added the bug Something isn't working label Feb 4, 2025
@tanvirtin
Copy link
Owner

Thanks for letting me know. Can I get your setup configuration please?

require('vgit').setup({}) -- <-- what are you passing here if anything?

@dpetka2001
Copy link
Author

{
    "tanvirtin/vgit.nvim",
    event = "VimEnter",
    branch = "v1.0.x",
    opts = {
      keymaps = {
        { mode = "n", key = "<leader>Gk", handler = "hunk_up", desc = "Hunk Up" },
        { mode = "n", key = "<leader>Gj", handler = "hunk_down", desc = "Hunk Down" },
        { mode = "n", key = "<leader>Gs", handler = "buffer_hunk_stage", desc = "Buffer Hunk Stage" },
        { mode = "n", key = "<leader>Gr", handler = "buffer_hunk_reset", desc = "Buffer Hunk Reset" },
        { mode = "n", key = "<leader>Gp", handler = "buffer_hunk_preview", desc = "Buffer Hunk Preview" },
        { mode = "n", key = "<leader>Gb", handler = "buffer_blame_preview", desc = "Buffer Blame Preview" },
        { mode = "n", key = "<leader>Gf", handler = "buffer_diff_preview", desc = "Buffer Diff Preview" },
        { mode = "n", key = "<leader>Gh", handler = "buffer_history_preview", desc = "Buffer History Preview" },
        { mode = "n", key = "<leader>Gu", handler = "buffer_reset", desc = "Buffer Reset" },
        { mode = "n", key = "<leader>Gd", handler = "project_diff_preview", desc = "Project Diff Preview" },
        { mode = "n", key = "<leader>Gx", handler = "toggle_diff_preference", desc = "Toggle Diff Preference" },
      },
      settings = {
        -- You can either allow corresponding mapping for existing hl, or re-define them yourself entirely.
        hls = {
          GitCount = "Keyword",
          GitSymbol = "CursorLineNr",
          GitTitle = "Directory",
          GitSelected = "QuickfixLine",
          GitBackground = "Normal",
          GitAppBar = "StatusLine",
          GitHeader = "NormalFloat",
          GitFooter = "NormalFloat",
          GitBorder = "LineNr",
          GitLineNr = "LineNr",
          GitComment = "Comment",
          GitSignsAdd = {
            gui = nil,
            fg = "#d7ffaf",
            bg = nil,
            sp = nil,
            override = false,
          },
          GitSignsChange = {
            gui = nil,
            fg = "#7AA6DA",
            bg = nil,
            sp = nil,
            override = false,
          },
          GitSignsDelete = {
            gui = nil,
            fg = "#e95678",
            bg = nil,
            sp = nil,
            override = false,
          },
          GitSignsAddLn = "DiffAdd",
          GitSignsDeleteLn = "DiffDelete",
          GitWordAdd = {
            gui = nil,
            fg = nil,
            bg = "#5d7a22",
            sp = nil,
            override = false,
          },
          GitWordDelete = {
            gui = nil,
            fg = nil,
            bg = "#960f3d",
            sp = nil,
            override = false,
          },
          GitConflictCurrentMark = "DiffAdd",
          GitConflictAncestorMark = "Visual",
          GitConflictIncomingMark = "DiffChange",
          GitConflictCurrent = "DiffAdd",
          GitConflictAncestor = "Visual",
          GitConflictMiddle = "Visual",
          GitConflictIncoming = "DiffChange",
        },
        live_blame = {
          enabled = true,
          format = function(blame, git_config)
            local config_author = git_config["user.name"]
            local author = blame.author
            if config_author == author then
              author = "You"
            end
            local time = os.difftime(os.time(), blame.author_time) / (60 * 60 * 24 * 30 * 12)
            local time_divisions = {
              { 1, "years" },
              { 12, "months" },
              { 30, "days" },
              { 24, "hours" },
              { 60, "minutes" },
              { 60, "seconds" },
            }
            local counter = 1
            local time_division = time_divisions[counter]
            local time_boundary = time_division[1]
            local time_postfix = time_division[2]
            while time < 1 and counter ~= #time_divisions do
              time_division = time_divisions[counter]
              time_boundary = time_division[1]
              time_postfix = time_division[2]
              time = time * time_boundary
              counter = counter + 1
            end
            local commit_message = blame.commit_message
            if not blame.committed then
              author = "You"
              commit_message = "Uncommitted changes"
              return string.format(" %s • %s", author, commit_message)
            end
            local max_commit_message_length = 255
            if #commit_message > max_commit_message_length then
              commit_message = commit_message:sub(1, max_commit_message_length) .. "..."
            end
            return string.format(
              " %s, %s • %s",
              author,
              string.format("%s %s ago", time >= 0 and math.floor(time + 0.5) or math.ceil(time - 0.5), time_postfix),
              commit_message
            )
          end,
        },
        live_gutter = {
          enabled = true,
          edge_navigation = true, -- This allows users to navigate within a hunk
        },
        scene = {
          diff_preference = "unified", -- unified or split
          keymaps = {
            quit = "q",
          },
        },
        diff_preview = {
          keymaps = {
            reset = "r",
            buffer_stage = "S",
            buffer_unstage = "U",
            buffer_hunk_stage = "s",
            buffer_hunk_unstage = "u",
            toggle_view = "t",
          },
        },
        project_diff_preview = {
          keymaps = {
            commit = "C",
            buffer_stage = "s",
            buffer_unstage = "u",
            buffer_hunk_stage = "gs",
            buffer_hunk_unstage = "gu",
            buffer_reset = "r",
            stage_all = "S",
            unstage_all = "U",
            reset_all = "R",
          },
        },
        project_stash_preview = {
          keymaps = {
            add = "A",
            apply = "a",
            pop = "p",
            drop = "d",
            clear = "C",
          },
        },
        project_logs_preview = {
          keymaps = {
            previous = "-",
            next = "=",
          },
        },
        project_commit_preview = {
          keymaps = {
            save = "S",
          },
        },
        signs = {
          priority = 10,
          definitions = {
            -- The sign definitions you provide will automatically be instantiated for you.
            GitConflictCurrentMark = {
              linehl = "GitConflictCurrentMark",
              texthl = nil,
              numhl = nil,
              icon = nil,
              text = "",
            },
            GitConflictAncestorMark = {
              linehl = "GitConflictAncestorMark",
              texthl = nil,
              numhl = nil,
              icon = nil,
              text = "",
            },
            GitConflictIncomingMark = {
              linehl = "GitConflictIncomingMark",
              texthl = nil,
              numhl = nil,
              icon = nil,
              text = "",
            },
            GitConflictCurrent = {
              linehl = "GitConflictCurrent",
              texthl = nil,
              numhl = nil,
              icon = nil,
              text = "",
            },
            GitConflictAncestor = {
              linehl = "GitConflictAncestor",
              texthl = nil,
              numhl = nil,
              icon = nil,
              text = "",
            },
            GitConflictMiddle = {
              linehl = "GitConflictMiddle",
              texthl = nil,
              numhl = nil,
              icon = nil,
              text = "",
            },
            GitConflictIncoming = {
              linehl = "GitConflictIncoming",
              texthl = nil,
              numhl = nil,
              icon = nil,
              text = "",
            },
            GitSignsAddLn = {
              linehl = "GitSignsAddLn",
              texthl = nil,
              numhl = nil,
              icon = nil,
              text = "",
            },
            GitSignsDeleteLn = {
              linehl = "GitSignsDeleteLn",
              texthl = nil,
              numhl = nil,
              icon = nil,
              text = "",
            },
            GitSignsAdd = {
              texthl = "GitSignsAdd",
              numhl = nil,
              icon = nil,
              linehl = nil,
              text = "",
            },
            GitSignsDelete = {
              texthl = "GitSignsDelete",
              numhl = nil,
              icon = nil,
              linehl = nil,
              text = "",
            },
            GitSignsChange = {
              texthl = "GitSignsChange",
              numhl = nil,
              icon = nil,
              linehl = nil,
              text = "",
            },
          },
          usage = {
            -- Please ensure these signs are defined.
            screen = {
              add = "GitSignsAddLn",
              remove = "GitSignsDeleteLn",
              conflict_current_mark = "GitConflictCurrentMark",
              conflict_current = "GitConflictCurrent",
              conflict_middle = "GitConflictMiddle",
              conflict_incoming_mark = "GitConflictIncomingMark",
              conflict_incoming = "GitConflictIncoming",
              conflict_ancestor_mark = "GitConflictAncestorMark",
              conflict_ancestor = "GitConflictAncestor",
            },
            main = {
              add = "GitSignsAdd",
              remove = "GitSignsDelete",
              change = "GitSignsChange",
            },
          },
        },
        symbols = {
          void = "",
          open = "",
          close = "",
        },
      },
    },
  },

Basically the advanced example setup from this repo's README and I'm just changing the mappings into tables, so that I can have descriptions.

@dpetka2001
Copy link
Author

dpetka2001 commented Feb 5, 2025

So, in the advanced example if I comment out the tables project_diff_preview and diff_preview, then I can see the default mappings in the header when I invoke those actions.

@tanvirtin
Copy link
Owner

It makes sense, I was able to replicate the issue. I'll issue a fix shortly, in the meantime you can just use a different format for these key mapping for example.

Also only use the advanced settings if you intend to reconfigure the defaults.

@dpetka2001
Copy link
Author

dpetka2001 commented Feb 5, 2025

I was testing the advanced example because I wanted to experiment with the signs and maybe get rid of gitsigns.nvim. But I will comment most of the stuff out for now (except for the keymaps section) and only gradually uncomment what I want to change indeed.

Thank you for your time.

@tanvirtin
Copy link
Owner

Should be fixed in the latest branch. If you face any issues as always leave an issue thanks!

tanvirtin added a commit that referenced this issue Feb 6, 2025
* refactor(git): implement better git abstraction

* rendering(line_numbers): utilize inline extmarks for creating virtual line numbers

* chore(authorship_code_lens)!: deprecate authorship code lens feature

* rendering: stabilize rendering

* feat(live_conflict): add highlight markers on buffer with conflict

* chore!: deprecate non view commands

* feat(conflict): add conflict resolution ability

* chore(debug): deprecate debug screen bloat

* fix(git): ensure vgit can operate on any buffer regardless of cwd

* feat(conflicts): add ability to compare merge conflict diffs

* chore(fmt): update formatting on project

* refactor(data): data fetching

* refactor(async): switch back to plenary

* feat(conflict): disable LSP on conflicts

* chore: remove Makefile

* refactor(data): make data fn returns consistent

* fix(foldable_list_view): fix entering fold list

* feat(conflict): ensure conflict management can be done on all different types

* refactor(project_diff_preview): data fetching

* feat(project_diff_preview): ensure foldable list view cursor is in sync with actions

* feat(project_diff_preview): add virtual text to indicate file status

* fix(project_diff_preview): fix rendering issues on cursor move

* chore(project_hunks_preview)!: deprecate screen in favour of more powerful project_diff_preview

* chore(project_hunks_qf)!: deprecate project_hunks_qf in favour of project_diff_preview

* feat(project_diff_preview): add change counters

* fix(project_diff_preview): fix cursor navigation on hunk (un)stage

* chore: fix formatting

* fix(project_diff_screen): notify users once all conflicts are resolved

* fix(project_commits_screen): fixed issues where certain fils would not be shown

* chore(buffer_gutter_blame_preview)!: deprecate infavour of live blame and buffer_line_blame_preview

* fix(project_commits_preview): fix incorrect diff

* fix(foldable_list_component): fixed issue where collapsing a folder would result in incorrect category count

* feat(project_diff_preview): synchronize navigation across buffers

* fix(diff): fixed an issue where deleted diffs would be inconsistent

* fix(rendering): fix issue where there would be gaps in split diff view

* chore: remove unused files

* fix(conflict): improve conflict detection

* fix(rendering): ensure no gaps appear in screens when dimensions are changed

* chore(tests): fix tests

* chore(tests): add tests for utils functions

* chore(tests): add tests for Rgb and Color

* chore(tests): add test for event.lua

* chore(tests): add tests for Watcher.lua

* chore(tests):fix test for icons

* chore(tests): add test for Namespace

* chore(tests): add test for keymap

* chore(tests): add test for renderer

* chore(tests): expand test for Window

* chore(format): format test files

* chore(tests): add test for Spawn

* fix(diff_screen): issue where a diff would appear even if no changes were found

* fix(git_log): use unit separator as delimiter

* fix(project_diff_screen): fix rendering and navigation issues when opened on subdirectory

* chore(tests): add unit test for Buffer class

* fix(buffer_diff_preview): fix error being thrown on invalid buffers

* chore(test): fix fs test

* chore(ui): remove unused component

* chore(refactor): scene.lua

* fix(project_diff_preview): fix toggle issues

* fix(ui): fix window shrinking issues

* feat(git_sync): add git change detection

* fix!(hunks): deprecate virtual hunk nav sign

* feat(live_gutter): optimize

* fix(live_blame): fix line blame not showing

* refactor(extmark): cleanup abstraction

* refactor(screens): clean up abstraction

* chore(fmt): fix code formatting

* fix(live_blame): fix duplicate rendering issue

* fix(project_diff_screen): fix incorrect deleted diff

* feat(conflicts): integrate conflicts into DiffView

* chore(refactor): rename files for clarity

* optimize(live_gutter): ensure gutter computation does not slow down on large files

* feat(conflicts): add conflict navigation

* refactor(commands): improve how commands are shown

* fix(project_logs_view): show toggled highlighted diff

* fix(ui): show appropriate error when data is empty

* fix(project_diff_screen): ensure first item is still focused

* feat(project_stash_preview): improve stash preview

* feat(project_commits_preview): improve commit details

* feat(buffer_blame_preview): improve line blame hls

* fix(project_stash_preview): fix incorrect stash popping

* chore(doc): update vim doc

* fix(project_stash_preview): fix incorrect stash order

* chore(doc): update vim.txt

* fix(project_diff_preview): fix incorrect handling of MD status

* chore(doc): update documentation

* chore(tests): remove unused test

* fix(folds): fix issue where icons were not highlighted

* fix(buffer_blame_preview): renamed files had issues showing blame

* chore(doc): add feature highlights gifs

* fix(project_diff_preview): fix unmerged files not showing

* chore(doc): add conflict management gif

* chore(doc): update project_diff_preview gif

* chore(doc): update README with proper gif title

* chore(doc): add installation warnings

* chore(docs): update docs

* feat(project_logs_preview): implement pagination

* fix(buffer_history_preview): restoring a deleted file shows diff

* chore(project_logs_preview): update pagination keymaps

* feat(project_diff_preview): improve cursor controls during staging/unstaging

* fix(settings): fix issue where logs and stash preview settings were not configurable

* fix(project_stash_preview): do not show stash preview if there is none

* fix(hls): adjust border colors for better contrast

* chore(doc): update README.md

* chore(docs): fix README.md typo

* fix(#375): fix case sensitivity issue with one of the files

* fix(toggle_live_gutter): fix runtime error on execution

* feat(#377): add keymap descriptions

* fix(#384): fix word diff no longer rendering

* chore(doc): prepare for release

* fix(#388): fix incompatibility with old setups

* fix(#388): fix incorrect key maps displayed in project_logs_preview

* chore(doc): update README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants