Skip to content

Commit

Permalink
Merge pull request #25 from julienvincent/jv/element-selections
Browse files Browse the repository at this point in the history
Add ae/ie text-selection keymaps for elements
  • Loading branch information
julienvincent authored Aug 20, 2023
2 parents c24a806 + 7e99285 commit b03534c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ require("nvim-paredit").setup({
repeatable = false,
mode = { "o", "v" }
},
["ae"] = {
api.select_element,
"Around element",
repeatable = false,
mode = { "o", "v" },
},
["ie"] = {
api.select_element,
"Element",
repeatable = false,
mode = { "o", "v" },
},
}
})
```
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-paredit/api/selections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function M.select_element()
M.ensure_visual_mode()
vim.api.nvim_win_set_cursor(0, { range[1] + 1, range[2] })
vim.api.nvim_command("normal! o")
vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] })
vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 })
end

return M
13 changes: 13 additions & 0 deletions lua/nvim-paredit/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ M.default_keys = {
repeatable = false,
mode = { "o", "v" },
},

["ae"] = {
api.select_element,
"Around element",
repeatable = false,
mode = { "o", "v" },
},
["ie"] = {
api.select_element,
"Element",
repeatable = false,
mode = { "o", "v" },
},
}

M.defaults = {
Expand Down
41 changes: 41 additions & 0 deletions tests/nvim-paredit/text_object_selections_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,44 @@ describe("form selections", function()
assert.are.same("a a", utils.get_selected_text())
end)
end)

describe("element deletions", function()
vim.api.nvim_buf_set_option(0, "filetype", "clojure")

before_each(function()
keybindings.setup_keybindings({
keys = defaults.default_keys,
})
end)

it("should delete the element", function()
prepare_buffer({
content = "(a :a/b)",
cursor = { 1, 5 },
})
feedkeys("die")
expect({
content = "(a )",
cursor = { 1, 3 },
})
end)
end)

describe("element selections", function()
vim.api.nvim_buf_set_option(0, "filetype", "clojure")

before_each(function()
keybindings.setup_keybindings({
keys = defaults.default_keys,
})
end)

it("should select the element", function()
prepare_buffer({
content = "(a :a/b)",
cursor = { 1, 5 },
})
feedkeys("vie")
assert.are.same(":a/b", utils.get_selected_text())
end)
end)

0 comments on commit b03534c

Please sign in to comment.