Skip to content

Commit 67288fe

Browse files
fix: account for columns before text when getting window width
## Details The current window width gets the entire available space for a window, but not the usable space. This was okay for getting a fill width but is not great when computing offsets to center blocks. The fix is to use the `getwininfo` `textoff` property which conveniently tells us the width of foldcolumn, signcolumn and numbers before text, exactly what we're looking for. To avoid re-computing this cache the value after it is first accessed so we can re-use it within the same parse cycle.
1 parent cb9a5e2 commit 67288fe

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- pad setext header lines [75a0a95](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/75a0a9596a91130fae43d3b7c0d6c651645ef1df)
1212
- center headings and code blocks [#179](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/179)
1313
[0986638](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/0986638b381a4b01eb108bb946f3a67a9eb3d0ec)
14+
- integrate with lazy.nvim filetypes [cb9a5e2](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/cb9a5e2412d21c7a89627e0d6da5459acbc0eb9c)
1415

1516
### Bug Fixes
1617

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local util = require('render-markdown.core.util')
1111
---@field private components table<integer, render.md.CustomComponent>
1212
---@field private conceal? table<integer, [integer, integer][]>
1313
---@field private links table<integer, [integer, integer, integer][]>
14+
---@field private window_width? integer
1415
---@field last_heading integer
1516
local Context = {}
1617
Context.__index = Context
@@ -29,6 +30,7 @@ function Context.new(buf, win, offset)
2930
self.components = {}
3031
self.conceal = nil
3132
self.links = {}
33+
self.window_width = nil
3234
self.last_heading = -1
3335
return self
3436
end
@@ -112,7 +114,14 @@ end
112114

113115
---@return integer
114116
function Context:get_width()
115-
return vim.api.nvim_win_get_width(self.win)
117+
if self.window_width == nil then
118+
self.window_width = vim.api.nvim_win_get_width(self.win)
119+
local window_info = vim.fn.getwininfo(self.win)
120+
if #window_info == 1 then
121+
self.window_width = self.window_width - window_info[1].textoff
122+
end
123+
end
124+
return self.window_width
116125
end
117126

118127
---@param other render.md.Context

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.1.8'
7+
M.version = '7.1.9'
88

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

0 commit comments

Comments
 (0)