-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: partial match for multi-mode maps in duplicates (#57)
fix: capture more than two duplicates of a mapping refactor: store modes as table, convert to string on render
- Loading branch information
Showing
7 changed files
with
140 additions
and
6 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
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,65 @@ | ||
local hawtkeys = require("hawtkeys") | ||
local util = require("hawtkeys.utils") | ||
local ts = require("hawtkeys.ts") | ||
---@diagnostic disable-next-line: undefined-field | ||
local eq = assert.are.same | ||
|
||
describe("HawtkeysDupes", function() | ||
before_each(function() | ||
require("plenary.reload").reload_module("hawtkeys") | ||
ts.reset_scanned_files() | ||
hawtkeys.setup({}) | ||
end) | ||
|
||
it("should detect duplicates", function() | ||
local keymap = ts.find_maps_in_file( | ||
"tests/hawtkeys/example_configs/duplicates.lua" | ||
) | ||
|
||
eq("n", keymap[1].mode) | ||
eq("<leader>t", keymap[1].lhs) | ||
|
||
eq("n", keymap[2].mode) | ||
eq("<leader>t", keymap[2].lhs) | ||
|
||
eq("x", keymap[3].mode) | ||
eq("<leader>f", keymap[3].lhs) | ||
|
||
eq("x", keymap[4].mode) | ||
eq("<leader>f", keymap[4].lhs) | ||
|
||
local dupes = util.find_duplicates(keymap) | ||
|
||
eq("n", dupes["<leader>t"][1].mode) | ||
eq("n", dupes["<leader>t"][2].mode) | ||
|
||
eq("x", dupes["<leader>f"][1].mode) | ||
eq("x", dupes["<leader>f"][2].mode) | ||
end) | ||
|
||
it( | ||
"should detect duplicates with partial mode matches for multi-mode maps", | ||
function() | ||
local keymap = ts.find_maps_in_file( | ||
"tests/hawtkeys/example_configs/multi_mode.lua" | ||
) | ||
eq({ "n", "x" }, keymap[1].mode) | ||
eq("<leader>2", keymap[1].lhs) | ||
eq(':echo "hello"<CR>', keymap[1].rhs) | ||
|
||
eq({ "x", "v" }, keymap[2].mode) | ||
eq("<leader>2", keymap[2].lhs) | ||
eq(':echo "hello2"<CR>', keymap[2].rhs) | ||
|
||
eq("v", keymap[3].mode) | ||
eq("<leader>2", keymap[3].lhs) | ||
eq(':echo "hello3"<CR>', keymap[3].rhs) | ||
|
||
local dupes = util.find_duplicates(keymap) | ||
|
||
eq({ "n", "x" }, dupes["<leader>2"][1].mode) | ||
eq({ "x", "v" }, dupes["<leader>2"][2].mode) | ||
eq("v", dupes["<leader>2"][3].mode) | ||
end | ||
) | ||
end) |
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,7 @@ | ||
vim.keymap.set("n", "<leader>t", ":term", {}) | ||
|
||
vim.api.nvim_set_keymap("n", "<leader>t", "<cmd>ToggleTerm<CR>", {}) | ||
|
||
vim.keymap.set("x", "<leader>f", ':echo "test"<CR>', {}) | ||
|
||
vim.api.nvim_set_keymap("x", "<leader>f", '<cmd>echo "test"<CR>', {}) |
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,5 @@ | ||
vim.keymap.set({ "n", "x" }, "<leader>2", ':echo "hello"<CR>') | ||
|
||
vim.keymap.set({ "x", "v" }, "<leader>2", ':echo "hello2"<CR>') | ||
|
||
vim.keymap.set("v", "<leader>2", ':echo "hello3"<CR>') |
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