aboutsummaryrefslogtreecommitdiff
path: root/data/core
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2021-08-28 13:42:06 -0400
committerFrancesco Abbate <francesco.bbt@gmail.com>2021-09-07 15:03:00 +0200
commit9d4e944549b48ae2c311860f913bc1f217fa6748 (patch)
treebff4c8d4076808eb3df14764f4536d4500ac8427 /data/core
parent68c1cc606fda70769db200d79421db2311d4313f (diff)
downloadpragtical-9d4e944549b48ae2c311860f913bc1f217fa6748.tar.gz
pragtical-9d4e944549b48ae2c311860f913bc1f217fa6748.zip
Added in two new VSC-style multicursor shortcuts.
Diffstat (limited to 'data/core')
-rw-r--r--data/core/commands/findreplace.lua30
-rw-r--r--data/core/keymap-macos.lua1
-rw-r--r--data/core/keymap.lua1
3 files changed, 27 insertions, 5 deletions
diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua
index 6dd7ddae..b9a424fa 100644
--- a/data/core/commands/findreplace.lua
+++ b/data/core/commands/findreplace.lua
@@ -96,13 +96,33 @@ local function has_selection()
return core.active_view:is(DocView) and core.active_view.doc:has_selection()
end
-command.add(has_selection, {
- ["find-replace:select-next"] = function()
- local l1, c1, l2, c2 = doc():get_selection(true)
+local function has_unique_selection()
+ local text = nil
+ for idx, line1, col1, line2, col2 in doc():get_selections(true, true) do
+ if line1 == line2 and col1 == col2 then return false end
+ local selection = doc():get_text(line1, col1, line2, col2)
+ if text ~= nil and text ~= selection then return false end
+ text = selection
+ end
+ return text ~= nil
+end
+
+local function select_next(all)
+ local il1, ic1 = doc():get_selection(true)
+ for idx, l1, c1, l2, c2 in doc():get_selections(true, true) do
local text = doc():get_text(l1, c1, l2, c2)
- l1, c1, l2, c2 = search.find(doc(), l2, c2, text, { wrap = true })
- if l2 then doc():set_selection(l2, c2, l1, c1) end
+ repeat
+ l1, c1, l2, c2 = search.find(doc(), l2, c2, text, { wrap = true })
+ if l1 == il1 and c1 == ic1 then break end
+ if l2 then doc():add_selection(l2, c2, l1, c1) end
+ until not all or not l2
+ break
end
+end
+
+command.add(has_unique_selection, {
+ ["find-replace:select-next"] = function() select_next(false) end,
+ ["find-replace:select-all"] = function() select_next(true) end
})
command.add("core.docview", {
diff --git a/data/core/keymap-macos.lua b/data/core/keymap-macos.lua
index 647cb132..89f68949 100644
--- a/data/core/keymap-macos.lua
+++ b/data/core/keymap-macos.lua
@@ -66,6 +66,7 @@ local function keymap_macos(keymap)
["cmd+a"] = "doc:select-all",
["cmd+d"] = { "find-replace:select-next", "doc:select-word" },
["cmd+l"] = "doc:select-lines",
+ ["cmd+shift+l"] = { "find-replace:select-all", "doc:select-word" },
["cmd+/"] = "doc:toggle-line-comments",
["cmd+up"] = "doc:move-lines-up",
["cmd+down"] = "doc:move-lines-down",
diff --git a/data/core/keymap.lua b/data/core/keymap.lua
index 0b08259d..2be0dfc7 100644
--- a/data/core/keymap.lua
+++ b/data/core/keymap.lua
@@ -170,6 +170,7 @@ keymap.add_direct {
["ctrl+a"] = "doc:select-all",
["ctrl+d"] = { "find-replace:select-next", "doc:select-word" },
["ctrl+l"] = "doc:select-lines",
+ ["ctrl+shift+l"] = { "find-replace:select-all", "doc:select-word" },
["ctrl+/"] = "doc:toggle-line-comments",
["ctrl+up"] = "doc:move-lines-up",
["ctrl+down"] = "doc:move-lines-down",