aboutsummaryrefslogtreecommitdiff
path: root/data/core/commands
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/commands
parent68c1cc606fda70769db200d79421db2311d4313f (diff)
downloadpragtical-9d4e944549b48ae2c311860f913bc1f217fa6748.tar.gz
pragtical-9d4e944549b48ae2c311860f913bc1f217fa6748.zip
Added in two new VSC-style multicursor shortcuts.
Diffstat (limited to 'data/core/commands')
-rw-r--r--data/core/commands/findreplace.lua30
1 files changed, 25 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", {