diff options
author | Polyfructol <polyfructol@gmail.com> | 2020-06-13 11:54:02 +0200 |
---|---|---|
committer | Polyfructol <polyfructol@gmail.com> | 2020-06-13 12:05:10 +0200 |
commit | 9514a0eec6131ee5e4783310ab99726a49ab6617 (patch) | |
tree | baece7ee89e19570e387ca8ba5c6e9c30c8f062f /plugins/linecopypaste.lua | |
parent | 0e8605da5c9ad371eb1f96e22f821d8c29a026e2 (diff) | |
download | lite-xl-plugins-9514a0eec6131ee5e4783310ab99726a49ab6617.tar.gz lite-xl-plugins-9514a0eec6131ee5e4783310ab99726a49ab6617.zip |
Added `linecopypaste.lua` plugin (resolves #57)
Diffstat (limited to 'plugins/linecopypaste.lua')
-rwxr-xr-x | plugins/linecopypaste.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/linecopypaste.lua b/plugins/linecopypaste.lua new file mode 100755 index 0000000..eb6f375 --- /dev/null +++ b/plugins/linecopypaste.lua @@ -0,0 +1,45 @@ +local core = require "core"
+local command = require "core.command"
+
+local function doc()
+ return core.active_view.doc
+end
+
+local line_in_clipboard = false
+
+local doc_copy = command.map["doc:copy"].perform
+command.map["doc:copy"].perform = function()
+ if doc():has_selection() then
+ doc_copy()
+ line_in_clipboard = false
+ else
+ local line = doc():get_selection()
+ system.set_clipboard(doc().lines[line])
+ line_in_clipboard = true
+ end
+end
+
+local doc_cut = command.map["doc:cut"].perform
+command.map["doc:cut"].perform = function()
+ if doc():has_selection() then
+ doc_cut()
+ line_in_clipboard = false
+ else
+ local line = doc():get_selection()
+ system.set_clipboard(doc().lines[line])
+ doc():remove(line, 1, line+1, 1)
+ doc():set_selection(line, 1)
+ line_in_clipboard = true
+ end
+end
+
+local doc_paste = command.map["doc:paste"].perform
+command.map["doc:paste"].perform = function()
+ if line_in_clipboard == false then
+ doc_paste()
+ else
+ local line, col = doc():get_selection()
+ doc():insert(line, 1, system.get_clipboard():gsub("\r", ""))
+ doc():set_selection(line+1, col)
+ end
+end
|