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

feat: add filetype for diff and blame window #609

Closed
wants to merge 1 commit into from

Conversation

seblyng
Copy link
Contributor

@seblyng seblyng commented Aug 21, 2022

I want to run some code to substitute a gitmoji code for the actual emoji in the git-blame window (for example %s/:sparkles:/✨, and I need the filetype to do this. I figured I could add a filetype to the diff-window as well.

Not 100% sure of the naming of filetype though, so open for other suggestions here

@seblyng
Copy link
Contributor Author

seblyng commented Sep 8, 2022

What do you think? @lewis6991. I have another usecase for this as well. I want to be able to move into the popup window of the diff/blame. I do this with something like this:

local open_or_attach = function(filetype, callback)
    local found = false
    local wininfo = vim.fn.getwininfo()
    for _, win in ipairs(wininfo) do
        if vim.bo[win.bufnr].filetype == filetype then
            found = true
            vim.cmd.wincmd({ 'w', count = win.winnr })
        end
    end
    if not found then
        callback()
    end
end

local gs = package.loaded.gitsigns
local map = function(m, l, r, opts)
    opts = opts or {}
    opts.buffer = bufnr
    vim.keymap.set(m, l, r, opts)
end

map('n', '<leader>gd', function()
    open_or_attach('gitsigns_diff', gs.preview_hunk)
end, { desc = 'Gitsigns: Preview diff hunk' })

@lewis6991
Copy link
Owner

It sounds like you want a preview callback instead.

@seblyng
Copy link
Contributor Author

seblyng commented Sep 8, 2022

That would also work. Is that preferable over just doing it in after/ftplugin/<filetype>.lua? I guess I can have a go at it if you prefer a preview callback. In that case, should it be one option in the setup for all previews, and then match on what type of preview it is?

For me it would work just as well with just giving the previews a filetype though.

@lewis6991
Copy link
Owner

Instead of looking at the filetype, you can instead look for the window variable gitsigns_preview which gets set to true.

For #609 (comment). We can consider just doing this by default as it seems to be a developing convention that calling a preview function twice causes it to get focus.

@seblyng
Copy link
Contributor Author

seblyng commented Sep 12, 2022

Instead of looking at the filetype, you can instead look for the window variable gitsigns_preview which gets set to true.

For #609 (comment). We can consider just doing this by default as it seems to be a developing convention that calling a preview function twice causes it to get focus.

I opened another PR for attaching to the popups if they are already open as I agree that it could definitely be the default behaviour as it is the default behaviour in most lsp stuff with a popup.

I am not too sure if I could use the window variable for search and replace in the blame window for setting gitmojis. I could listen for BufNew events and search for the variable, and just do search and replace regardless of if it is a diff-popup or blame-popup, as it will probably never cause any issues for me in a diff-popup. I would however prefer running it on some ftplugin or a preview callback. I could have a go at implementing a preview callback if you think that could be nice

@lewis6991
Copy link
Owner

Preview windows now have the window variable gitsigns_preview which will either be set to hunk or blame.

@lewis6991 lewis6991 closed this Sep 14, 2022
@daedroza
Copy link

daedroza commented Dec 7, 2023

@seblj : Were you able to implement preview navigation? If possible, can you share code? Thanks!

@seblyng
Copy link
Contributor Author

seblyng commented Dec 7, 2023

I am not sure what you mean by preview navigation, but I was able to implement what I wanted to do with this:

https://github.com/seblj/dotfiles/blob/bee66d727ca022cf574d12661fa59de5601bd536/nvim/lua/config/gitsigns.lua#L3-L26

@daedroza
Copy link

daedroza commented Dec 7, 2023

I am not sure what you mean by preview navigation, but I was able to implement what I wanted to do with this:

https://github.com/seblj/dotfiles/blob/bee66d727ca022cf574d12661fa59de5601bd536/nvim/lua/config/gitsigns.lua#L3-L26

I would like to navigate the preview using j and k, right now the preview is full screen but I cannot scroll it to view the change.

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.

3 participants