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

fix(#378): fix runtime error on execution #379

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/vgit/controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ local toggle_live_gutter = loop.coroutine(function()
local live_gutter_enabled = live_gutter_setting:get('enabled')

live_gutter_setting:set('enabled', not live_gutter_enabled)
live_gutter:reset()
live_gutter:toggle()
end)

local toggle_tracing = loop.coroutine(function()
Expand Down
17 changes: 14 additions & 3 deletions lua/vgit/features/buffer/Hunks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local Object = require('vgit.core.Object')
local console = require('vgit.core.console')
local navigation = require('vgit.core.navigation')
local git_buffer_store = require('vgit.git.git_buffer_store')
local live_gutter_setting = require('vgit.settings.live_gutter')

local Hunks = Object:extend()

Expand All @@ -13,7 +14,13 @@ function Hunks:constructor()
}
end

function Hunks:is_enabled()
return live_gutter_setting:get('enabled') == true
end

function Hunks:move_up()
if not self:is_enabled() then return end

local buffer = git_buffer_store.current()
if not buffer then return end

Expand All @@ -25,6 +32,8 @@ function Hunks:move_up()
end

function Hunks:move_down()
if not self:is_enabled() then return end

local buffer = git_buffer_store.current()
if not buffer then return end

Expand Down Expand Up @@ -67,7 +76,7 @@ function Hunks:stage_all()
end

function Hunks:cursor_stage()
loop.free_textlock()
if not self:is_enabled() then return end

local buffer = git_buffer_store.current()
if not buffer then return end
Expand Down Expand Up @@ -114,6 +123,8 @@ function Hunks:reset_all()
end

function Hunks:cursor_reset()
if not self:is_enabled() then return end

loop.free_textlock()
local buffer = git_buffer_store.current()
if not buffer then return end
Expand Down Expand Up @@ -144,8 +155,8 @@ function Hunks:cursor_reset()
for i = 1, #hunks do
local hunk = hunks[i]
if
(lnum >= hunk.top and lnum <= hunk.bot)
or (hunk.top == 0 and hunk.bot == 0 and lnum - 1 == hunk.top and lnum - 1 == hunk.bot)
(lnum >= hunk.top and lnum <= hunk.bot)
or (hunk.top == 0 and hunk.bot == 0 and lnum - 1 == hunk.top and lnum - 1 == hunk.bot)
then
selected_hunk = hunk
selected_hunk_index = i
Expand Down
50 changes: 29 additions & 21 deletions lua/vgit/features/buffer/LiveGutter.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
local loop = require('vgit.core.loop')
local utils = require('vgit.core.utils')
local Object = require('vgit.core.Object')
local console = require('vgit.core.console')
local buffer_store = require('vgit.core.buffer_store')
local git_buffer_store = require('vgit.git.git_buffer_store')
local live_gutter_setting = require('vgit.settings.live_gutter')

Expand All @@ -12,9 +10,11 @@ function LiveGutter:constructor()
return { name = 'Live Gutter' }
end

function LiveGutter:fetch(buffer)
if not live_gutter_setting:get('enabled') then return end
function LiveGutter:is_enabled()
return live_gutter_setting:get('enabled') == true
end

function LiveGutter:fetch(buffer)
loop.free_textlock()
if not buffer:is_valid() then return end

Expand All @@ -33,28 +33,36 @@ LiveGutter.fetch_debounced = loop.debounce_coroutine(function(self, buffer)
self:fetch(buffer)
end, 10)

function LiveGutter:reset()
local buffers = buffer_store.list()
utils.list.for_each(buffers, function(buffer)
buffer:clear_signs()
function LiveGutter:toggle()
git_buffer_store.for_each(function(buffer)
if self:is_enabled() then
self:fetch(buffer)
else
buffer:reset_signs()
end
buffer:render_signs()
end)
end

function LiveGutter:register_events()
git_buffer_store
.on({ 'attach', 'reload' }, function(buffer)
self:fetch(buffer)
buffer:render_signs()
end)
.on({ 'change' }, function(buffer)
self:fetch_debounced(buffer)
end)
.on('sync', function(buffer)
self:fetch_debounced(buffer)
end)
.on('detach', function(buffer)
buffer:clear_extmarks()
end)
.on({ 'attach', 'reload' }, function(buffer)
if not self:is_enabled() then return end

self:fetch(buffer)
buffer:render_signs()
end)
.on({ 'change' }, function(buffer)
if not self:is_enabled() then return end
self:fetch_debounced(buffer)
end)
.on('sync', function(buffer)
if not self:is_enabled() then return end
self:fetch_debounced(buffer)
end)
.on('detach', function(buffer)
buffer:clear_extmarks()
end)
end

return LiveGutter
5 changes: 5 additions & 0 deletions lua/vgit/git/GitBuffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ function GitBuffer:sync()
return self
end

function GitBuffer:reset_signs()
self.state.signs = {}
return self
end

function Buffer:clear_conflicts(top, bot)
top = top or 0
bot = bot or -1
Expand Down
Loading