From b52d2d9142937d8a037c99705e8abcb20563d818 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Tue, 31 Dec 2024 20:35:21 -0600 Subject: [PATCH 1/6] Fix window picker's hint logic to filter to only valid, visible windows --- lua/org-roam/core/ui/window-picker/hint.lua | 44 ++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/lua/org-roam/core/ui/window-picker/hint.lua b/lua/org-roam/core/ui/window-picker/hint.lua index 389ec9e..e4fc844 100644 --- a/lua/org-roam/core/ui/window-picker/hint.lua +++ b/lua/org-roam/core/ui/window-picker/hint.lua @@ -43,6 +43,7 @@ function M:new(opts) return instance end +---@private ---@param window integer ---@return {x:number, y:number} function M:__get_float_win_pos(window) @@ -57,6 +58,7 @@ function M:__get_float_win_pos(window) return point end +---@private ---@param lines string[] ---@return string[] function M.__add_big_char_margin(lines) @@ -87,6 +89,7 @@ function M.__add_big_char_margin(lines) return centered_lines end +---@private ---@param window integer ---@param char string ---@return integer @@ -119,9 +122,26 @@ function M:__show_letter_in_window(window, char) return window_id end +---Draws a letter as a window on top of each valid, visible window supplied. ---@param windows integer[] function M:draw(windows) - for i, window in ipairs(windows) do + -- Filter out to only include valid windows + local valid_windows = {} + for _, window in ipairs(windows) do + if self:__should_draw_on_window(window) then + table.insert(valid_windows, window) + end + end + + -- If we still have too many windows to populate with our characters, + -- fail cleanly with a recommendation + local max_windows = self:__max_windows() + assert(#valid_windows <= max_windows, table.concat({ + "Too many valid, visible windows!", + "Increase the characters available to the window picker.", + }, " ")) + + for i, window in ipairs(valid_windows) do local char = string.sub(self.config.chars, i, i) local big_char = assert(font[char:lower()], "font missing for " .. char:lower()) local window_id = self:__show_letter_in_window(window, big_char) @@ -129,6 +149,7 @@ function M:draw(windows) end end +---Clears the hint. function M:clear() for _, window in ipairs(self.__windows) do if vim.api.nvim_win_is_valid(window) then @@ -141,4 +162,25 @@ function M:clear() self.__windows = {} end +---@private +---Returns true if the window should be drawn on, meaning it's valid and visible. +---@param window integer #handle of the window +---@return boolean +function M:__should_draw_on_window(window) + if not vim.api.nvim_win_is_valid(window) then + return false + end + + ---@type vim.api.keyset.win_config + local config = vim.api.nvim_win_get_config(window) + return config.relative == "" +end + +---@private +---Returns the maximum number of valid, visible windows supported. +---@return integer +function M:__max_windows() + return string.len(self.config.chars) +end + return M From 1cc4a6386613e2395adff98f17147f5f5c26a898 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Tue, 31 Dec 2024 20:38:03 -0600 Subject: [PATCH 2/6] Update stylings to be compliant --- lua/org-roam/core/ui/window-picker/hint.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/org-roam/core/ui/window-picker/hint.lua b/lua/org-roam/core/ui/window-picker/hint.lua index e4fc844..321e2a4 100644 --- a/lua/org-roam/core/ui/window-picker/hint.lua +++ b/lua/org-roam/core/ui/window-picker/hint.lua @@ -136,10 +136,13 @@ function M:draw(windows) -- If we still have too many windows to populate with our characters, -- fail cleanly with a recommendation local max_windows = self:__max_windows() - assert(#valid_windows <= max_windows, table.concat({ - "Too many valid, visible windows!", - "Increase the characters available to the window picker.", - }, " ")) + assert( + #valid_windows <= max_windows, + table.concat({ + "Too many valid, visible windows!", + "Increase the characters available to the window picker.", + }, " ") + ) for i, window in ipairs(valid_windows) do local char = string.sub(self.config.chars, i, i) From 92797075b2fd45d613fbdc0de2027b0566087502 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Tue, 31 Dec 2024 20:44:59 -0600 Subject: [PATCH 3/6] Update test matrix with new neovim instances --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index afbe5d6..a45810f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,11 +36,11 @@ jobs: strategy: fail-fast: false matrix: - version: [v0.9.2, v0.9.4, v0.9.5, nightly] + version: [v0.9.4, v0.9.5, v0.10.0, v0.10.1, v0.10.2, v0.10.3, nightly] os: [ubuntu-latest] include: - os: windows-latest - version: v0.9.5 + version: v0.10.3 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 9b30f84683f933eddf30f3743a2f25adbd418463 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Tue, 31 Dec 2024 20:45:59 -0600 Subject: [PATCH 4/6] Clean up some of the test versions of neovim used --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a45810f..2605cd0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,7 +36,7 @@ jobs: strategy: fail-fast: false matrix: - version: [v0.9.4, v0.9.5, v0.10.0, v0.10.1, v0.10.2, v0.10.3, nightly] + version: [v0.9.4, v0.9.5, v0.10.2, v0.10.3, nightly] os: [ubuntu-latest] include: - os: windows-latest From 57ef5b99bcbc4efbe043f88cfba98a86991a16aa Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Tue, 31 Dec 2024 21:30:26 -0600 Subject: [PATCH 5/6] Update utils.org_file() to actually write to the file, and adjust tests to use orgfile.metadata.mtime instead of 0 --- spec/core_file_spec.lua | 10 +++++----- spec/utils.lua | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/core_file_spec.lua b/spec/core_file_spec.lua index aa122bc..4e5d4cc 100644 --- a/spec/core_file_spec.lua +++ b/spec/core_file_spec.lua @@ -60,7 +60,7 @@ describe("org-roam.core.file", function() { column = 4, offset = 143, row = 6 }, }, }, - mtime = 0, + mtime = orgfile.metadata.mtime, range = { end_ = { column = MAX_NUMBER, @@ -146,7 +146,7 @@ describe("org-roam.core.file", function() { column = 8, offset = 323, row = 12 }, }, }, - mtime = 0, + mtime = orgfile.metadata.mtime, range = { end_ = { column = 0, @@ -299,7 +299,7 @@ describe("org-roam.core.file", function() }, }, }, - mtime = 0, + mtime = orgfile.metadata.mtime, range = { end_ = { column = MAX_NUMBER, @@ -329,7 +329,7 @@ describe("org-roam.core.file", function() }, }, }, - mtime = 0, + mtime = orgfile.metadata.mtime, range = { end_ = { column = 0, @@ -359,7 +359,7 @@ describe("org-roam.core.file", function() }, }, }, - mtime = 0, + mtime = orgfile.metadata.mtime, range = { end_ = { column = 0, diff --git a/spec/utils.lua b/spec/utils.lua index 5746d99..9e3dd89 100644 --- a/spec/utils.lua +++ b/spec/utils.lua @@ -111,7 +111,7 @@ end ---Creates a new orgfile, stripping common indentation. ---@param content string ----@param opts? {path?:string} +---@param opts? {path?:string, skip_write?:boolean} ---@return OrgFile function M.org_file(content, opts) opts = opts or {} @@ -121,6 +121,12 @@ function M.org_file(content, opts) filename = filename .. ".org" end + -- Write to the file to ensure that it matches the content + -- to avoid testing race conditions somehow + if not opts.skip_write then + M.write_to(filename, content) + end + ---@type OrgFile local file = OrgFile:new({ filename = filename, From 0080851c60092d3b7525fa5ad89300dbcf15ea87 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Tue, 31 Dec 2024 21:34:21 -0600 Subject: [PATCH 6/6] Disable nightly from github tests until neovim/neovim#30792 is fixed --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2605cd0..a553259 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,7 +36,9 @@ jobs: strategy: fail-fast: false matrix: - version: [v0.9.4, v0.9.5, v0.10.2, v0.10.3, nightly] + # NOTE: Nightly disabled until neovim/neovim#30792 is fixed! + # Once it is fixed, add "nightly" back to version list. + version: [v0.9.4, v0.9.5, v0.10.2, v0.10.3] os: [ubuntu-latest] include: - os: windows-latest