Skip to content

Commit

Permalink
feat(preview): add preview_hunk_inline()
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Oct 29, 2022
1 parent 6321c88 commit 9110ea1
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Build Neovim
if: steps.cache-deps.outputs.cache-hit != 'true'
run: make test_deps NEOVIM_BRANCH=$NEOVIM_BRANCH
run: make test_deps

- name: Run Test
run: make test
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FILTER ?= .*

LUA_VERSION := 5.1
TL_VERSION := 0.14.1
NEOVIM_BRANCH := master
NEOVIM_BRANCH ?= master

DEPS_DIR := $(PWD)/deps/nvim-$(NEOVIM_BRANCH)

Expand Down
3 changes: 3 additions & 0 deletions doc/gitsigns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ get_hunks({bufnr}) *gitsigns.get_hunks()*
select_hunk() *gitsigns.select_hunk()*
Select the hunk under the cursor.

preview_hunk_inline() *gitsigns.preview_hunk_inline()*
Preview the hunk at the cursor position inline in the buffer.

preview_hunk() *gitsigns.preview_hunk()*
Preview the hunk at the cursor position in a floating
window. If the preview is already open, calling this
Expand Down
27 changes: 26 additions & 1 deletion lua/gitsigns/actions.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lua/gitsigns/diff_int.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lua/gitsigns/hunks.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 66 additions & 39 deletions lua/gitsigns/manager.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion teal/gitsigns/actions.tl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ local record M
next_hunk : function(NavHunkOpts)
prev_hunk : function(NavHunkOpts)
preview_hunk : function()
preview_hunk_inline: function()
select_hunk : function()
get_hunks : function(bufnr: integer): {Hunk_Public}

Expand Down Expand Up @@ -588,7 +589,7 @@ local function hlmarks_for_hunk(hunk: Hunk, hl: string): {HlMark}
for _, region in ipairs(added_regions) do
hls[#hls+1] = {
hl_group = 'GitSignsAddInline',
start_row = region[1] - 1,
start_row = region[1] + removed.count - 1,
start_col = region[3],
end_col = region[4],
}
Expand Down Expand Up @@ -652,6 +653,30 @@ M.preview_hunk = noautocmd(function()
popup.create(lines_spec, config.preview_config, 'hunk')
end)

--- Preview the hunk at the cursor position inline in the buffer.
M.preview_hunk_inline = function()
local bufnr = current_buf()

local hunk = get_cursor_hunk(bufnr)

if not hunk then
return
end

local nsp = api.nvim_create_namespace('gitsigns_preview_inline')

manager.show_added(bufnr, nsp, hunk)
manager.show_deleted(bufnr, nsp, hunk)

api.nvim_create_autocmd({ 'CursorMoved', 'InsertEnter' }, {
callback = function()
api.nvim_buf_clear_namespace(bufnr, nsp, 0, -1)
end,
once = true
})

end

--- Select the hunk under the cursor.
M.select_hunk = function()
local hunk = get_cursor_hunk()
Expand Down
4 changes: 2 additions & 2 deletions teal/gitsigns/diff_int.tl
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ function M.run_word_diff(removed: {string}, added: {string}): {Region}, {Region}
hunks = denoise_hunks(hunks)

for _, h in ipairs(hunks) do
adds[#adds+1] = {i+#removed, h.type, h.added.start , h.added.start + h.added.count}
rems[#rems+1] = {i , h.type, h.removed.start, h.removed.start + h.removed.count}
adds[#adds+1] = {i, h.type, h.added.start , h.added.start + h.added.count}
rems[#rems+1] = {i, h.type, h.removed.start, h.removed.start + h.removed.count}
end
end
return rems, adds
Expand Down
2 changes: 2 additions & 0 deletions teal/gitsigns/hunks.tl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ end

-- Calculate signs needed to be applied from a hunk for a specified line range.
function M.calc_signs(hunk: Hunk, min_lnum: integer, max_lnum: integer): {Sign}
min_lnum = min_lnum or 1
max_lnum = max_lnum or math.huge as integer
local start, added, removed = hunk.added.start, hunk.added.count, hunk.removed.count

if hunk.type == 'delete' and start == 0 then
Expand Down
Loading

0 comments on commit 9110ea1

Please sign in to comment.