aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--plugins/language_tsx.lua72
-rw-r--r--plugins/navigate.lua147
3 files changed, 220 insertions, 0 deletions
diff --git a/README.md b/README.md
index 0853fa8..48f9796 100644
--- a/README.md
+++ b/README.md
@@ -94,6 +94,7 @@ Plugin | Description
[`memoryusage`](plugins/memoryusage.lua?raw=1) | Show memory usage in the status view
[`motiontrail`](plugins/motiontrail.lua?raw=1) | Adds a motion-trail to the caret *([screenshot](https://user-images.githubusercontent.com/3920290/83256814-085ccb00-a1ab-11ea-9e35-e6633cbed1a9.gif))*
[`nagbar`](https://github.com/takase1121/lite-nagbar)* | consistent and _beautiful_ confirmation dialogs for lite and lite-xl *([gif](https://raw.githubusercontent.com/takase1121/lite-nagbar/master/assets/preview.gif))*
+[`navigate`](plugins/navigate.lua?raw=1) | Allows moving back and forward between document positions, reducing the amount of scrolling
[`openfilelocation`](plugins/openfilelocation.lua?raw=1) | Opens the parent directory of the current file in the file manager
[`openselected`](plugins/openselected.lua?raw=1) | Opens the selected filename or url
~~[`projectmanager`](plugins/projectmanager.lua?raw=1)~~ | Integrated in lite-xl with improvements ~~Save projects and load/reload them quickly~~
diff --git a/plugins/language_tsx.lua b/plugins/language_tsx.lua
new file mode 100644
index 0000000..9dd93ad
--- /dev/null
+++ b/plugins/language_tsx.lua
@@ -0,0 +1,72 @@
+-- mod-version:1 -- lite-xl 1.16
+-- Almost identical to JS, with the exception that / shouldn't denote a regex. Current JS syntax highlighter will highlight half the document due to closing tags.
+local syntax = require "core.syntax"
+
+syntax.add {
+ files = { "%.tsx$" },
+ comment = "//",
+ patterns = {
+ { pattern = "//.-\n", type = "comment" },
+ { pattern = { "/%*", "%*/" }, type = "comment" },
+ { pattern = { '"', '"', '\\' }, type = "string" },
+ { pattern = { "'", "'", '\\' }, type = "string" },
+ { pattern = { "`", "`", '\\' }, type = "string" },
+ { pattern = "0x[%da-fA-F]+", type = "number" },
+ { pattern = "-?%d+[%d%.eE]*", type = "number" },
+ { pattern = "-?%.?%d+", type = "number" },
+ { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
+ { pattern = "interface%s()[%a_][%w_]*", type = {"keyword", "keyword2"} },
+ { pattern = "type%s()[%a_][%w_]*", type = {"keyword", "keyword2"} },
+ { pattern = "[%a_][%w_]*%f[(]", type = "function" },
+ { pattern = "[%a_][%w_]*", type = "symbol" },
+ },
+ symbols = {
+ ["async"] = "keyword",
+ ["await"] = "keyword",
+ ["break"] = "keyword",
+ ["case"] = "keyword",
+ ["catch"] = "keyword",
+ ["class"] = "keyword",
+ ["const"] = "keyword",
+ ["continue"] = "keyword",
+ ["debugger"] = "keyword",
+ ["default"] = "keyword",
+ ["delete"] = "keyword",
+ ["do"] = "keyword",
+ ["else"] = "keyword",
+ ["export"] = "keyword",
+ ["extends"] = "keyword",
+ ["finally"] = "keyword",
+ ["for"] = "keyword",
+ ["function"] = "keyword",
+ ["get"] = "keyword",
+ ["if"] = "keyword",
+ ["import"] = "keyword",
+ ["implements"] = "keyword",
+ ["in"] = "keyword",
+ ["instanceof"] = "keyword",
+ ["let"] = "keyword",
+ ["new"] = "keyword",
+ ["return"] = "keyword",
+ ["set"] = "keyword",
+ ["static"] = "keyword",
+ ["super"] = "keyword",
+ ["switch"] = "keyword",
+ ["throw"] = "keyword",
+ ["try"] = "keyword",
+ ["typeof"] = "keyword",
+ ["var"] = "keyword",
+ ["void"] = "keyword",
+ ["while"] = "keyword",
+ ["with"] = "keyword",
+ ["yield"] = "keyword",
+ ["true"] = "literal",
+ ["false"] = "literal",
+ ["null"] = "literal",
+ ["undefined"] = "literal",
+ ["arguments"] = "keyword2",
+ ["Infinity"] = "keyword2",
+ ["NaN"] = "keyword2",
+ ["this"] = "keyword2",
+ },
+}
diff --git a/plugins/navigate.lua b/plugins/navigate.lua
new file mode 100644
index 0000000..5d37e76
--- /dev/null
+++ b/plugins/navigate.lua
@@ -0,0 +1,147 @@
+-- mod-version:1 -- lite-xl 1.16
+
+local core = require "core"
+local common = require "core.common"
+local command = require "core.command"
+local config = require "core.config"
+local keymap = require "core.keymap"
+local DocView = require "core.docview"
+
+local navigate = {
+ list = {},
+ current = nil,
+ index = 0
+}
+
+--
+-- Private functions
+--
+local function get_active_view()
+ if getmetatable(core.active_view) == DocView then
+ return core.active_view
+ end
+ return nil
+end
+
+local function add(doc)
+ -- Make new navigation point last in list
+ if navigate.index > 0 and navigate.index < #navigate.list then
+ local list_len = #navigate.list
+ for index=navigate.index+1, list_len, 1 do
+ if navigate.list[index] then
+ table.remove(navigate.list, index)
+ end
+ end
+ end
+
+ local line, col = doc:get_selection()
+ table.insert(navigate.list, {
+ filename = doc.filename,
+ line = line,
+ col = col
+ })
+
+ navigate.current = navigate.list[#navigate.list]
+ navigate.index = #navigate.list
+end
+
+local function open_doc(doc)
+ core.root_view:open_doc(
+ core.open_doc(
+ common.home_expand(
+ doc.filename
+ )
+ )
+ )
+
+ local av_doc = get_active_view().doc
+ local line, col = av_doc:get_selection()
+ if doc.line ~= line or doc.col ~= col then
+ av_doc:set_selection(doc.line, doc.col, doc.line, doc.col)
+ end
+end
+
+--
+-- Public functions
+--
+function navigate.next()
+ if navigate.index < #navigate.list then
+ navigate.index = navigate.index + 1
+ navigate.current = navigate.list[navigate.index]
+ open_doc(navigate.current)
+ end
+end
+
+function navigate.prev()
+ if navigate.index > 1 then
+ navigate.index = navigate.index - 1
+ navigate.current = navigate.list[navigate.index]
+ open_doc(navigate.current)
+ end
+end
+
+--
+-- Thread
+--
+core.add_thread(function()
+ while true do
+ local av = get_active_view()
+ if av and av.doc and av.doc.filename then
+ local doc = av.doc
+ local line, col = doc:get_selection()
+ local current = navigate.current
+ if
+ not current
+ or
+ current.filename ~= doc.filename
+ or
+ current.line ~= line
+ then
+ add(doc)
+ else
+ current.col = col
+ end
+ end
+
+ if system.window_has_focus() then
+ coroutine.yield(0.5)
+ else
+ coroutine.yield(config.project_scan_rate)
+ end
+ end
+end)
+
+core.add_close_hook(function(doc)
+ local filename = doc.filename
+ local list = {table.unpack(navigate.list)}
+ for index, position in ipairs(list) do
+ if position.filename == filename then
+ if navigate.list[index] then
+ table.remove(navigate.list, index)
+ end
+ end
+ end
+end)
+
+--
+-- Commands
+--
+command.add("core.docview", {
+ ["navigate:previous"] = function()
+ navigate.prev()
+ end,
+
+ ["navigate:next"] = function()
+ navigate.next()
+ end,
+})
+
+--
+-- Default Keybindings
+--
+keymap.add {
+ ["alt+left"] = "navigate:previous",
+ ["alt+right"] = "navigate:next",
+}
+
+return navigate