Skip to content

Commit

Permalink
eval:selected multi-cursor support (#441)
Browse files Browse the repository at this point in the history
* eval:selected multi-cursor support

* Bumped manifest version.

---------

Co-authored-by: Adam Harrison <[email protected]>
  • Loading branch information
exelotl and adamharrison authored Feb 14, 2025
1 parent fe4ce8d commit 2ff91be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
"id": "eval",
"mod_version": "3",
"path": "plugins/eval.lua",
"version": "0.1"
"version": "0.2"
},
{
"description": "Adds Treesitter syntax highlighting support",
Expand Down
15 changes: 8 additions & 7 deletions plugins/eval.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ command.add("core.docview", {
end,

["eval:selected"] = function(dv)
if dv.doc:has_selection() then
local text = dv.doc:get_text(dv.doc:get_selection())
dv.doc:text_input(eval(text))
else
local line = dv.doc:get_selection()
local text = dv.doc.lines[line]
dv.doc:insert(line+1, 0, "= " .. eval(text) .. "\n")
for idx, line1, col1, line2, col2 in dv.doc:get_selections() do
if line1 ~= line2 or col1 ~= col2 then
local text = dv.doc:get_text(line1, col1, line2, col2)
dv.doc:text_input(eval(text), idx)
else
local text = dv.doc.lines[line1]
dv.doc:replace_cursor(idx, line1, 0, line1, #text, eval)
end
end
end,
})
Expand Down

0 comments on commit 2ff91be

Please sign in to comment.