aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortiziw <34965470+tiziw@users.noreply.github.com>2020-06-18 07:23:27 +0200
committerGitHub <noreply@github.com>2020-06-18 07:23:27 +0200
commit0a2dbaac8fbd5d3a1c782a9b092c1d41d25bee58 (patch)
tree3b1c7f646242f731dbd7e4ae235a99d96ecec9a2
parent900648e94fb778b443d75127e8d6c16a6bce4141 (diff)
parent1696515f5a3eb7548b373ff585531044c21b68c2 (diff)
downloadlite-xl-plugins-0a2dbaac8fbd5d3a1c782a9b092c1d41d25bee58.tar.gz
lite-xl-plugins-0a2dbaac8fbd5d3a1c782a9b092c1d41d25bee58.zip
Merge pull request #1 from tiziw/patch-2
Patch 2
-rw-r--r--README.md1
-rw-r--r--plugins/autoinsert.lua27
-rw-r--r--plugins/workspace.lua23
3 files changed, 44 insertions, 7 deletions
diff --git a/README.md b/README.md
index 218798a..ad9d90e 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,7 @@ Plugin | Description
[`language_batch`](plugins/language_batch.lua?raw=1) | Syntax for Windows [Batch Files](https://en.wikipedia.org/wiki/Batch_file)
[`language_cpp`](plugins/language_cpp.lua?raw=1) | Syntax for the [C++](https://isocpp.org/) programming language
[`language_csharp`](plugins/language_csharp.lua?raw=1) | Syntax for the [C#](http://csharp.net) programming language
+[`language_java`](plugins/language_java.lua?raw=1) | Syntax for the [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) programming language
[`language_d`](plugins/language_d.lua?raw=1) | Syntax for the [D](https://dlang.org/) programming language
[`language_fe`](plugins/language_fe.lua?raw=1) | Syntax for the [fe](https://github.com/rxi/fe) programming language
[`language_fennel`](plugins/language_fennel.lua?raw=1) | Syntax for the [fennel](https://fennel-lang.org) programming language
diff --git a/plugins/autoinsert.lua b/plugins/autoinsert.lua
index a3c8f98..0bf5a5a 100644
--- a/plugins/autoinsert.lua
+++ b/plugins/autoinsert.lua
@@ -1,4 +1,5 @@
local core = require "core"
+local translate = require "core.doc.translate"
local config = require "core.config"
local DocView = require "core.docview"
local command = require "core.command"
@@ -60,7 +61,13 @@ function DocView:on_text_input(text)
end
-command.add("core.docview", {
+
+local function predicate()
+ return getmetatable(core.active_view) == DocView
+ and not core.active_view.doc:has_selection()
+end
+
+command.add(predicate, {
["autoinsert:backspace"] = function()
local doc = core.active_view.doc
local l, c = doc:get_selection()
@@ -70,6 +77,22 @@ command.add("core.docview", {
end
command.perform "doc:backspace"
end,
+
+ ["autoinsert:delete-to-previous-word-start"] = function()
+ local doc = core.active_view.doc
+ local le, ce = translate.previous_word_start(doc, doc:get_selection())
+ while true do
+ local l, c = doc:get_selection()
+ if l == le and c == ce then
+ break
+ end
+ command.perform "autoinsert:backspace"
+ end
+ end,
})
-keymap.add { ["backspace"] = "autoinsert:backspace" }
+keymap.add {
+ ["backspace"] = "autoinsert:backspace",
+ ["ctrl+backspace"] = "autoinsert:delete-to-previous-word-start",
+ ["ctrl+shift+backspace"] = "autoinsert:delete-to-previous-word-start",
+}
diff --git a/plugins/workspace.lua b/plugins/workspace.lua
index b40ab4b..8f8dfcc 100644
--- a/plugins/workspace.lua
+++ b/plugins/workspace.lua
@@ -41,6 +41,7 @@ local function save_view(view)
if mt == DocView then
return {
type = "doc",
+ active = (core.active_view == view),
filename = view.doc.filename,
selection = { view.doc:get_selection() },
scroll = { x = view.scroll.to.x, y = view.scroll.to.y },
@@ -49,7 +50,11 @@ local function save_view(view)
end
for name, mod in pairs(package.loaded) do
if mod == mt then
- return { type = "view", module = name }
+ return {
+ type = "view",
+ active = (core.active_view == view),
+ module = name
+ }
end
end
end
@@ -98,17 +103,22 @@ end
local function load_node(node, t)
if t.type == "leaf" then
+ local res
for _, v in ipairs(t.views) do
- node:add_view(load_view(v))
+ local view = load_view(v)
+ if v.active then res = view end
+ node:add_view(view)
end
if t.active_view then
node:set_active_view(node.views[t.active_view])
end
+ return res
else
node:split(t.type == "hsplit" and "right" or "down")
node.divider = t.divider
- load_node(node.a, t.a)
- load_node(node.b, t.b)
+ local res1 = load_node(node.a, t.a)
+ local res2 = load_node(node.b, t.b)
+ return res1 or res2
end
end
@@ -126,7 +136,10 @@ local function load_workspace()
os.remove(workspace_filename)
if ok then
local root = get_unlocked_root(core.root_view.root_node)
- load_node(root, t)
+ local active_view = load_node(root, t)
+ if active_view then
+ core.set_active_view(active_view)
+ end
end
end