-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
152 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
local resultsList = require('grug-far/render/resultsList') | ||
|
||
local function previewLocation(params) | ||
local api = vim.api | ||
local fn = vim.fn | ||
local buf = params.buf | ||
local context = params.context | ||
local grugfar_win = fn.bufwinid(buf) | ||
local cursor_row = unpack(api.nvim_win_get_cursor(grugfar_win)) | ||
local location = resultsList.getResultLocation(cursor_row - 1, buf, context) | ||
if location == nil then | ||
return | ||
end | ||
|
||
local width = api.nvim_win_get_width(0) | ||
local height = api.nvim_win_get_height(0) | ||
local opts = { | ||
relative = 'win', | ||
border = 'rounded', | ||
width = width, | ||
height = math.floor(height / 3), | ||
bufpos = { fn.line('.') - 1, fn.col('.') }, | ||
focusable = true, | ||
win = grugfar_win, | ||
style = 'minimal', | ||
} | ||
|
||
local w = api.nvim_open_win(0, true, opts) | ||
local bufnr = fn.bufnr(location.filename) | ||
if bufnr == -1 then | ||
fn.win_execute(w, 'e ' .. vim.fn.fnameescape(location.filename), true) | ||
else | ||
api.nvim_win_set_buf(w, bufnr) | ||
end | ||
api.nvim_win_set_cursor(w, { location.lnum, location.col - 1 }) | ||
local b = fn.winbufnr(w) | ||
api.nvim_set_option_value('bufhidden', 'wipe', { buf = b }) | ||
end | ||
|
||
return previewLocation |
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
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,45 @@ | ||
local MiniTest = require('mini.test') | ||
local helpers = require('grug-far/test/helpers') | ||
local keymaps = helpers.getKeymaps() | ||
|
||
---@type NeovimChild | ||
local child = MiniTest.new_child_neovim() | ||
|
||
local T = MiniTest.new_set({ | ||
hooks = { | ||
pre_case = function() | ||
helpers.initChildNeovim(child) | ||
end, | ||
-- Stop once all test cases are finished | ||
post_once = child.stop, | ||
}, | ||
}) | ||
|
||
T['can preview a given location'] = function() | ||
helpers.writeTestFiles({ | ||
{ filename = 'file1.txt', content = [[ | ||
grug walks | ||
then grug swims | ||
]] }, | ||
{ | ||
filename = 'file2.doc', | ||
content = [[ | ||
grug talks and grug drinks | ||
then grug thinks | ||
]], | ||
}, | ||
}) | ||
|
||
helpers.childRunGrugFar(child, { | ||
windowCreationCommand = 'vsplit', | ||
prefills = { search = 'grug' }, | ||
}) | ||
helpers.childWaitForFinishedStatus(child) | ||
|
||
child.type_keys('<esc>10G') | ||
child.type_keys('<esc>' .. keymaps.previewLocation.n) | ||
helpers.childWaitForScreenshotText(child, '│ grug walks │') | ||
helpers.childExpectScreenshot(child) | ||
end | ||
|
||
return T |
51 changes: 51 additions & 0 deletions
51
tests/screenshots/tests-base-test_preview.lua---can-preview-a-given-location
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,51 @@ | ||
--|---------|---------|---------|---------|---------|---------|---------|---------| | ||
01| Actions / Help <g?> ... │ | ||
02| │~ | ||
03| Search: │~ | ||
04| grug │~ | ||
05| Replace: │~ | ||
06| │~ | ||
07| Files Filter: │~ | ||
08| │~ | ||
09| Flags: │~ | ||
10| │~ | ||
11| Paths: │~ | ||
12| │~ | ||
13| │~ | ||
14| STATUS_SUCCESS ⟪ ripgrep ⟫│~ | ||
15| 5 ma╭────────────────────────────────────────╮ | ||
16| │ │ | ||
17| file│ grug walks │ | ||
18|-2:8:│ then grug swims │ | ||
19|│3:13│ │ | ||
20| │ │ | ||
21| file│ │ | ||
22|-2:7:│ │ | ||
23|Grug ╰────────────────────────────────────────╯me] 0,0-1 All | ||
24| 2,8 All | ||
|
||
--|---------|---------|---------|---------|---------|---------|---------|---------| | ||
01|01111111111111111111112222222222222222223222222222222222222222222222222222222222 | ||
02|02222222222222222222222222222222222222223000000000000000000000000000000000000000 | ||
03|44444444442222222222222222222222222222223000000000000000000000000000000000000000 | ||
04|02222222222222222222222222222222222222223000000000000000000000000000000000000000 | ||
05|44444444444222222222222222222222222222223000000000000000000000000000000000000000 | ||
06|02222222222222222222222222222222222222223000000000000000000000000000000000000000 | ||
07|44444444444444442222222222222222222222223000000000000000000000000000000000000000 | ||
08|02222222222222222222222222222222222222223000000000000000000000000000000000000000 | ||
09|44444444422222222222222222222222222222223000000000000000000000000000000000000000 | ||
10|02222222222222222222222222222222222222223000000000000000000000000000000000000000 | ||
11|44444444422222222222222222222222222222223000000000000000000000000000000000000000 | ||
12|02222222222222222222222222222222222222223000000000000000000000000000000000000000 | ||
13|22222222222222222222222222222222222222223000000000000000000000000000000000000000 | ||
14|55555555555555555555555555555555555555553000000000000000000000000000000000000000 | ||
15|55555666666666666666666666666666666666666666666000000000000000000000000000000000 | ||
16|02222666666666666666666666666666666666666666666000000000000000000000000000000000 | ||
17|07777666666666666666666666666666666666666666666000000000000000000000000000000000 | ||
18|08282666666666666666666666666666666666666666666000000000000000000000000000000000 | ||
19|08288666666666666666666666666666666666666666666000000000000000000000000000000000 | ||
20|02222699999999999999999999999999999999999999996000000000000000000000000000000000 | ||
21|07777699999999999999999999999999999999999999996000000000000000000000000000000000 | ||
22|08282699999999999999999999999999999999999999996000000000000000000000000000000000 | ||
23|:::::666666666666666666666666666666666666666666::::::::::::::::::::::::::::::::: | ||
24|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |