-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(highlight): forward search / matching in long lines (#1976)
fix: cursor position after scrolling with incsearch refactor: remove viewport hack when in cmdline mode
- Loading branch information
Showing
9 changed files
with
264 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
local M = {} | ||
|
||
local api, fn = vim.api, vim.fn | ||
|
||
M.event_group = api.nvim_create_augroup("vscode-neovim.viewport", { clear = true }) | ||
M.viewport_changed_ns = api.nvim_create_namespace("vscode-neovim.viewport.changed") | ||
|
||
---@class WinView All positions are 0-based | ||
---@field winid integer | ||
---@field bufnr integer | ||
---@field lnum integer | ||
---@field col integer | ||
---@field coladd integer | ||
---@field curswant integer | ||
---@field topline integer | ||
---@field botline integer | ||
---@field topfill integer | ||
---@field leftcol integer | ||
---@field skipcol integer | ||
|
||
local function setup_viewport_changed() | ||
---@type table<integer, WinView> | ||
local view_cache = {} | ||
|
||
api.nvim_set_decoration_provider(M.viewport_changed_ns, { | ||
on_win = function(_, win, buf, topline, botline) | ||
-- We don't need the first window. | ||
if win == 1000 then | ||
return | ||
end | ||
---@type WinView | ||
local view = api.nvim_win_call(win, fn.winsaveview) | ||
view.winid = win | ||
view.bufnr = buf | ||
view.topline = topline | ||
view.botline = botline | ||
view.lnum = view.lnum - 1 | ||
|
||
local cache = view_cache[view.winid] | ||
if cache and vim.deep_equal(view, cache) then | ||
return | ||
end | ||
view_cache[view.winid] = view | ||
fn.VSCodeExtensionNotify("viewport-changed", view) | ||
end, | ||
}) | ||
|
||
-- cleanup cache | ||
api.nvim_create_autocmd({ "WinClosed" }, { | ||
group = M.event_group, | ||
callback = function() | ||
local wins = vim.tbl_keys(view_cache) | ||
for _, win in ipairs(wins) do | ||
if not api.nvim_win_is_valid(win) then | ||
view_cache[win] = nil | ||
end | ||
end | ||
end, | ||
}) | ||
end | ||
|
||
function M.setup() | ||
-- Highlighting needs to wait for the viewport-changed event to complete. | ||
-- When the UI attaches, there are numerous highlight events (hl_attr_define, grid_line) to process. | ||
-- | ||
-- Without delaying the setup, the viewport-changed event will cause frequent | ||
-- pauses in highlight processing, resulting in screen flickering. | ||
api.nvim_create_autocmd({ "UIEnter" }, { | ||
once = true, | ||
callback = function() | ||
-- Don't worry about whether it's set too late. | ||
vim.defer_fn(setup_viewport_changed, 1000) | ||
end, | ||
}) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { strict as assert } from "assert"; | ||
import path from "path"; | ||
|
||
import { NeovimClient } from "neovim"; | ||
|
||
import { | ||
assertContent, | ||
attachTestNvimClient, | ||
closeAllActiveEditors, | ||
closeNvimClient, | ||
openTextDocument, | ||
sendNeovimKeys, | ||
sendVSCodeKeys, | ||
wait, | ||
} from "./integrationUtils"; | ||
|
||
describe("Test incsearch", () => { | ||
let client: NeovimClient; | ||
before(async () => { | ||
client = await attachTestNvimClient(); | ||
}); | ||
after(async () => { | ||
await closeNvimClient(client); | ||
await closeAllActiveEditors(); | ||
}); | ||
afterEach(async () => { | ||
await closeAllActiveEditors(); | ||
}); | ||
it("Cursor is ok for incsearch after scroll", async () => { | ||
const e = await openTextDocument(path.join(__dirname, "../../../test_fixtures/incsearch-scroll.ts")); | ||
|
||
await sendVSCodeKeys("gg"); | ||
await sendVSCodeKeys("/bla"); | ||
await assertContent({ cursor: [115, 19] }, client); | ||
assert.ok(e.visibleRanges[0].start.line <= 115); | ||
}); | ||
|
||
it("Cursor is ok for incsearch even if register / is not empty", async function () { | ||
this.retries(0); | ||
await openTextDocument(path.join(__dirname, "../../../test_fixtures/incsearch-scroll.ts")); | ||
|
||
await sendVSCodeKeys("gg"); | ||
await sendVSCodeKeys("/bla"); | ||
await assertContent({ cursor: [115, 19] }, client); | ||
await sendNeovimKeys(client, "<cr>"); | ||
await assertContent({ cursor: [115, 16] }, client); | ||
await sendNeovimKeys(client, "/h2"); | ||
await client.command("mode"); | ||
await wait(500); | ||
await assertContent({ cursor: [170, 21] }, client); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.