Skip to content

Commit b95005e

Browse files
authored
Merge pull request #6 from iquzart/develop
Enhancements
2 parents ec3f34a + 6b9f187 commit b95005e

3 files changed

Lines changed: 96 additions & 20 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ use {
5353
- enabled ⇄ disabled
5454
- yes ⇄ no
5555
- up ⇄ down
56+
- start ⇄ stop
57+
- open ⇄ close
58+
- allow ⇄ deny
59+
- accept ⇄ reject
60+
- read ⇄ write
61+
- push ⇄ pull
62+
- inbound ⇄ outbound
63+
- public ⇄ private
64+
- online ⇄ offline
65+
- local ⇄ remote
66+
- master ⇄ slave
67+
- primary ⇄ replica
68+
- active ⇄ passive
69+
- manual ⇄ automatic
70+
71+
- prod ⇄ uat ⇄ dev ⇄ preprod (cyclical)
5672
```
5773

5874
### Custom Toggle Pairs

lua/toggleword/init.lua

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,71 @@
11
local M = {}
22

3+
-- Extended toggle map with multi-value cycling support
34
M.toggles = {
4-
["true"] = "false",
5-
["false"] = "true",
6-
["on"] = "off",
7-
["off"] = "on",
8-
["enabled"] = "disabled",
9-
["disabled"] = "enabled",
10-
["yes"] = "no",
11-
["no"] = "yes",
12-
["up"] = "down",
13-
["down"] = "up",
5+
["true"] = { "false" },
6+
["false"] = { "true" },
7+
["on"] = { "off" },
8+
["off"] = { "on" },
9+
["enabled"] = { "disabled" },
10+
["disabled"] = { "enabled" },
11+
["yes"] = { "no" },
12+
["no"] = { "yes" },
13+
["up"] = { "down" },
14+
["down"] = { "up" },
15+
["start"] = { "stop" },
16+
["stop"] = { "start" },
17+
["open"] = { "close" },
18+
["close"] = { "open" },
19+
["allow"] = { "deny" },
20+
["deny"] = { "allow" },
21+
["accept"] = { "reject" },
22+
["reject"] = { "accept" },
23+
["read"] = { "write" },
24+
["write"] = { "read" },
25+
["push"] = { "pull" },
26+
["pull"] = { "push" },
27+
["inbound"] = { "outbound" },
28+
["outbound"] = { "inbound" },
29+
["public"] = { "private" },
30+
["private"] = { "public" },
31+
["online"] = { "offline" },
32+
["offline"] = { "online" },
33+
["local"] = { "remote" },
34+
["remote"] = { "local" },
35+
["master"] = { "slave" },
36+
["slave"] = { "master" },
37+
["primary"] = { "replica" },
38+
["replica"] = { "primary" },
39+
["active"] = { "passive" },
40+
["passive"] = { "active" },
41+
["manual"] = { "automatic" },
42+
["automatic"] = { "manual" },
43+
44+
-- Environments toggle
45+
["prod"] = { "uat", "dev", "preprod" },
46+
["uat"] = { "dev", "preprod", "prod" },
47+
["dev"] = { "preprod", "prod", "uat" },
48+
["preprod"] = { "prod", "uat", "dev" },
1449
}
1550

16-
--- Toggle the word under the cursor if it's in the toggle list
51+
-- Toggle word under cursor, cycling through defined alternates
1752
function M.toggle_word()
1853
local word = vim.fn.expand("<cword>")
19-
local replacement = M.toggles[word]
20-
if replacement then
21-
vim.cmd("normal! ciw" .. replacement)
22-
else
23-
vim.notify("No toggle match for: " .. word, vim.log.levels.WARN)
54+
for key, values in pairs(M.toggles) do
55+
if word == key then
56+
vim.cmd("normal! ciw" .. values[1])
57+
return
58+
elseif vim.tbl_contains(values, word) then
59+
local idx = vim.fn.index(values, word)
60+
local next_idx = (idx + 1) % #values
61+
vim.cmd("normal! ciw" .. values[next_idx + 1])
62+
return
63+
end
2464
end
65+
vim.notify("No toggle match for: " .. word, vim.log.levels.WARN)
2566
end
2667

27-
--- Setup keybindings and allow custom toggle pairs
68+
-- Optional setup: override toggles or keybinding
2869
-- @param opts table|nil: { key = "<leader>tt", toggles = table }
2970
function M.setup(opts)
3071
opts = opts or {}

spec/toggleword_spec.lua

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
1-
-- spec/toggleword_spec.lua
21
describe("toggleword", function()
32
local toggleword = require("toggleword")
43

54
it("should toggle 'true' to 'false'", function()
6-
assert.are.equal(toggleword.toggles["true"], "false")
5+
assert.are.same(toggleword.toggles["true"], { "false" })
76
end)
87

98
it("should toggle 'yes' to 'no'", function()
10-
assert.are.equal(toggleword.toggles["yes"], "no")
9+
assert.are.same(toggleword.toggles["yes"], { "no" })
10+
end)
11+
12+
it("should toggle 'prod' to 'uat', 'dev', 'preprod'", function()
13+
assert.are.same(toggleword.toggles["prod"], { "uat", "dev", "preprod" })
14+
end)
15+
16+
it("should toggle 'dev' to 'preprod', 'prod', 'uat'", function()
17+
assert.are.same(toggleword.toggles["dev"], { "preprod", "prod", "uat" })
18+
end)
19+
20+
it("should toggle 'enabled' to 'disabled'", function()
21+
assert.are.same(toggleword.toggles["enabled"], { "disabled" })
22+
end)
23+
24+
it("should toggle 'push' to 'pull'", function()
25+
assert.are.same(toggleword.toggles["push"], { "pull" })
26+
end)
27+
28+
it("should toggle 'offline' to 'online'", function()
29+
assert.are.same(toggleword.toggles["offline"], { "online" })
1130
end)
1231
end)

0 commit comments

Comments
 (0)