Skip to content

Commit 91ce0b5

Browse files
fix: only set option value if it changes
## Details Issue: #186 In order to fix #177 the window option setting logic was updated to always modify window options rather than on a state transition. The reason was to handle out of band state transitions for a buffer that would cause the state of the window options to be changed without the inner states knowledge. As a result the window options were not being properly updated since effectively no state transition occured. While this does seem to have almost no performance penalty it does seem to reset some kind of state in neovim that causes some kinds of motions to be have differently, such as moving between ends of lines as reported in the issue. To fix this rather than always updating the option value, get the current value and only set the new value if it is different. In this way we properly handle out of band transitions since we're relying on the actual current option value and not some internal state. And since we don't unnecessarily change the value we don't mess with any internal neovim state and allow motions to behave as they normally would.
1 parent 0fe0f08 commit 91ce0b5

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

Diff for: lua/render-markdown/core/util.lua

+6-4
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,23 @@ end
5252

5353
---@param win integer
5454
---@param name string
55-
---@return number|string|boolean
55+
---@return render.md.option.Value
5656
function M.get_win(win, name)
5757
return vim.api.nvim_get_option_value(name, { scope = 'local', win = win })
5858
end
5959

6060
---@param win integer
6161
---@param name string
62-
---@param value number|string|boolean
62+
---@param value render.md.option.Value
6363
function M.set_win(win, name, value)
64-
vim.api.nvim_set_option_value(name, value, { scope = 'local', win = win })
64+
if value ~= M.get_win(win, name) then
65+
vim.api.nvim_set_option_value(name, value, { scope = 'local', win = win })
66+
end
6567
end
6668

6769
---@param buf integer
6870
---@param name string
69-
---@return number|string|boolean
71+
---@return render.md.option.Value
7072
function M.get_buf(buf, name)
7173
return vim.api.nvim_get_option_value(name, { buf = buf })
7274
end

Diff for: lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.2.1'
7+
M.version = '7.2.2'
88

99
function M.check()
1010
M.start('version')

Diff for: lua/render-markdown/init.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ local M = {}
2222
---@field public enabled? boolean
2323
---@field public query? string
2424

25+
---@alias render.md.option.Value number|string|boolean
26+
2527
---@class (exact) render.md.UserWindowOption
26-
---@field public default? number|string|boolean
27-
---@field public rendered? number|string|boolean
28+
---@field public default? render.md.option.Value
29+
---@field public rendered? render.md.option.Value
2830

2931
---@class (exact) render.md.UserIndent
3032
---@field public enabled? boolean

Diff for: lua/render-markdown/types.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
---@field public query string
1313

1414
---@class (exact) render.md.WindowOption
15-
---@field public default number|string|boolean
16-
---@field public rendered number|string|boolean
15+
---@field public default render.md.option.Value
16+
---@field public rendered render.md.option.Value
1717

1818
---@class (exact) render.md.Indent
1919
---@field public enabled boolean

0 commit comments

Comments
 (0)