Skip to content

Commit

Permalink
Merge pull request #1 from tiziw/patch-2
Browse files Browse the repository at this point in the history
Patch 2
  • Loading branch information
tiziw authored Jun 18, 2020
2 parents 900648e + 1696515 commit 0a2dbaa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions plugins/autoinsert.lua
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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",
}
23 changes: 18 additions & 5 deletions plugins/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 0a2dbaa

Please sign in to comment.