diff options
| author | Takase <20792268+takase1121@users.noreply.github.com> | 2021-11-17 08:42:08 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-17 08:42:08 +0800 |
| commit | 8e6f594790701c499c5aa544f4e90b98e207dcb7 (patch) | |
| tree | 7adc0fa2afa10618ad8e328f0a1fa5bfe6ec61a4 /data/plugins | |
| parent | 6d36f2684a376a4698a62f453cf46bba74d4b9bc (diff) | |
| parent | 18959aebefe22e7bcfff80a2affc8ad0fda76328 (diff) | |
| download | lite-xl-8e6f594790701c499c5aa544f4e90b98e207dcb7.tar.gz lite-xl-8e6f594790701c499c5aa544f4e90b98e207dcb7.zip | |
Merge branch 'master' into replace-unpack
Diffstat (limited to 'data/plugins')
| -rw-r--r-- | data/plugins/autocomplete.lua | 9 | ||||
| -rw-r--r-- | data/plugins/detectindent.lua | 92 | ||||
| -rw-r--r-- | data/plugins/drawwhitespace.lua | 32 | ||||
| -rw-r--r-- | data/plugins/language_md.lua | 45 | ||||
| -rw-r--r-- | data/plugins/language_python.lua | 2 | ||||
| -rw-r--r-- | data/plugins/lineguide.lua | 3 | ||||
| -rw-r--r-- | data/plugins/projectsearch.lua | 5 | ||||
| -rw-r--r-- | data/plugins/scale.lua | 36 | ||||
| -rw-r--r-- | data/plugins/treeview.lua | 26 |
9 files changed, 191 insertions, 59 deletions
diff --git a/data/plugins/autocomplete.lua b/data/plugins/autocomplete.lua index c41f233d..fde9487e 100644 --- a/data/plugins/autocomplete.lua +++ b/data/plugins/autocomplete.lua @@ -10,9 +10,9 @@ local RootView = require "core.rootview" local DocView = require "core.docview" local Doc = require "core.doc" -config.plugins.autocomplete = { +config.plugins.autocomplete = { -- Amount of characters that need to be written for autocomplete - min_len = 1, + min_len = 3, -- The max amount of visible items max_height = 6, -- The max amount of scrollable items @@ -502,6 +502,11 @@ command.add(predicate, { suggestions_idx = math.min(suggestions_idx + 1, #suggestions) end, + ["autocomplete:cycle"] = function() + local newidx = suggestions_idx + 1 + suggestions_idx = newidx > #suggestions and 1 or newidx + end, + ["autocomplete:cancel"] = function() reset_suggestions() end, diff --git a/data/plugins/detectindent.lua b/data/plugins/detectindent.lua index 45ebaee6..20541c82 100644 --- a/data/plugins/detectindent.lua +++ b/data/plugins/detectindent.lua @@ -102,6 +102,11 @@ end local function update_cache(doc) local type, size, score = detect_indent_stat(doc) local score_threshold = 4 + if score < score_threshold then + -- use default values + type = config.tab_type + size = config.indent_size + end cache[doc] = { type = type, size = size, confirmed = (score >= score_threshold) } doc.indent_info = cache[doc] end @@ -111,20 +116,14 @@ local new = Doc.new function Doc:new(...) new(self, ...) update_cache(self) - if not cache[self].confirmed then - core.add_thread(function () - while not cache[self].confirmed do - update_cache(self) - coroutine.yield(1) - end - end, self) - end end local clean = Doc.clean function Doc:clean(...) clean(self, ...) - update_cache(self) + if not cache[self].confirmed then + update_cache(self) + end end @@ -152,3 +151,78 @@ function DocView:draw(...) return with_indent_override(self.doc, draw, self, ...) end + +local function set_indent_type(doc, type) + cache[doc] = {type = type, + size = cache[doc].value or config.indent_size, + confirmed = true} + doc.indent_info = cache[doc] +end + +local function set_indent_type_command() + core.command_view:enter( + "Specify indent style for this file", + function(value) -- submit + local doc = core.active_view.doc + value = value:lower() + set_indent_type(doc, value == "tabs" and "hard" or "soft") + end, + function(text) -- suggest + return common.fuzzy_match({"tabs", "spaces"}, text) + end, + nil, -- cancel + function(text) -- validate + local t = text:lower() + return t == "tabs" or t == "spaces" + end + ) +end + + +local function set_indent_size(doc, size) + cache[doc] = {type = cache[doc].type or config.tab_type, + size = size, + confirmed = true} + doc.indent_info = cache[doc] +end + +local function set_indent_size_command() + core.command_view:enter( + "Specify indent size for current file", + function(value) -- submit + local value = math.floor(tonumber(value)) + local doc = core.active_view.doc + set_indent_size(doc, value) + end, + nil, -- suggest + nil, -- cancel + function(value) -- validate + local value = tonumber(value) + return value ~= nil and value >= 1 + end + ) +end + + +command.add("core.docview", { + ["indent:set-file-indent-type"] = set_indent_type_command, + ["indent:set-file-indent-size"] = set_indent_size_command +}) + + +command.add(function() + return core.active_view:is(DocView) + and cache[core.active_view.doc] + and cache[core.active_view.doc].type == "soft" + end, { + ["indent:switch-file-to-tabs-indentation"] = function() set_indent_type(core.active_view.doc, "hard") end +}) + + +command.add(function() + return core.active_view:is(DocView) + and cache[core.active_view.doc] + and cache[core.active_view.doc].type == "hard" + end, { + ["indent:switch-file-to-spaces-indentation"] = function() set_indent_type(core.active_view.doc, "soft") end +}) diff --git a/data/plugins/drawwhitespace.lua b/data/plugins/drawwhitespace.lua new file mode 100644 index 00000000..da9d1b12 --- /dev/null +++ b/data/plugins/drawwhitespace.lua @@ -0,0 +1,32 @@ +-- mod-version:2 -- lite-xl 2.0 + +local style = require "core.style" +local DocView = require "core.docview" +local common = require "core.common" + +local draw_line_text = DocView.draw_line_text + +function DocView:draw_line_text(idx, x, y) + local font = (self:get_font() or style.syntax_fonts["comment"]) + local color = style.syntax.comment + local ty, tx = y + self:get_line_text_y_offset() + local text, offset, s, e = self.doc.lines[idx], 1 + while true do + s, e = text:find(" +", offset) + if not s then break end + tx = self:get_col_x_offset(idx, s) + x + renderer.draw_text(font, string.rep("·", e - s + 1), tx, ty, color) + offset = e + 1 + end + offset = 1 + while true do + s, e = text:find("\t", offset) + if not s then break end + tx = self:get_col_x_offset(idx, s) + x + renderer.draw_text(font, "»", tx, ty, color) + offset = e + 1 + end + draw_line_text(self, idx, x, y) +end + + diff --git a/data/plugins/language_md.lua b/data/plugins/language_md.lua index 6e6e4255..3c1c329a 100644 --- a/data/plugins/language_md.lua +++ b/data/plugins/language_md.lua @@ -1,22 +1,41 @@ -- mod-version:2 -- lite-xl 2.0 local syntax = require "core.syntax" + + syntax.add { files = { "%.md$", "%.markdown$" }, patterns = { - { pattern = "\\.", type = "normal" }, - { pattern = { "<!%-%-", "%-%->" }, type = "comment" }, - { pattern = { "```", "```" }, type = "string" }, - { pattern = { "``", "``", "\\" }, type = "string" }, - { pattern = { "`", "`", "\\" }, type = "string" }, - { pattern = { "~~", "~~", "\\" }, type = "keyword2" }, - { pattern = "%-%-%-+", type = "comment" }, - { pattern = "%*%s+", type = "operator" }, - { pattern = { "%*", "[%*\n]", "\\" }, type = "operator" }, - { pattern = { "%_", "[%_\n]", "\\" }, type = "keyword2" }, - { pattern = "#.-\n", type = "keyword" }, - { pattern = "!?%[.-%]%(.-%)", type = "function" }, - { pattern = "https?://%S+", type = "function" }, + { pattern = "\\.", type = "normal" }, + { pattern = { "<!%-%-", "%-%->" }, type = "comment" }, + { pattern = { "```c", "```" }, type = "string", syntax = ".c" }, + { pattern = { "```c++", "```" }, type = "string", syntax = ".cpp" }, + { pattern = { "```python", "```" }, type = "string", syntax = ".py" }, + { pattern = { "```ruby", "```" }, type = "string", syntax = ".rb" }, + { pattern = { "```perl", "```" }, type = "string", syntax = ".pl" }, + { pattern = { "```php", "```" }, type = "string", syntax = ".php" }, + { pattern = { "```javascript", "```" }, type = "string", syntax = ".js" }, + { pattern = { "```html", "```" }, type = "string", syntax = ".html" }, + { pattern = { "```xml", "```" }, type = "string", syntax = ".xml" }, + { pattern = { "```css", "```" }, type = "string", syntax = ".css" }, + { pattern = { "```lua", "```" }, type = "string", syntax = ".lua" }, + { pattern = { "```bash", "```" }, type = "string", syntax = ".sh" }, + { pattern = { "```java", "```" }, type = "string", syntax = ".java" }, + { pattern = { "```c#", "```" }, type = "string", syntax = ".cs" }, + { pattern = { "```cmake", "```" }, type = "string", syntax = ".cmake" }, + { pattern = { "```d", "```" }, type = "string", syntax = ".d" }, + { pattern = { "```glsl", "```" }, type = "string", syntax = ".glsl" }, + { pattern = { "```", "```" }, type = "string" }, + { pattern = { "``", "``", "\\" }, type = "string" }, + { pattern = { "`", "`", "\\" }, type = "string" }, + { pattern = { "~~", "~~", "\\" }, type = "keyword2" }, + { pattern = "%-%-%-+", type = "comment" }, + { pattern = "%*%s+", type = "operator" }, + { pattern = { "%*", "[%*\n]", "\\" }, type = "operator" }, + { pattern = { "%_", "[%_\n]", "\\" }, type = "keyword2" }, + { pattern = "#.-\n", type = "keyword" }, + { pattern = "!?%[.-%]%(.-%)", type = "function" }, + { pattern = "https?://%S+", type = "function" }, }, symbols = { }, } diff --git a/data/plugins/language_python.lua b/data/plugins/language_python.lua index e19caa63..252a0d14 100644 --- a/data/plugins/language_python.lua +++ b/data/plugins/language_python.lua @@ -2,7 +2,7 @@ local syntax = require "core.syntax" syntax.add { - files = { "%.py$", "%.pyw$" }, + files = { "%.py$", "%.pyw$", "%.rpy$" }, headers = "^#!.*[ /]python", comment = "#", patterns = { diff --git a/data/plugins/lineguide.lua b/data/plugins/lineguide.lua index 61debbff..5a17c8ca 100644 --- a/data/plugins/lineguide.lua +++ b/data/plugins/lineguide.lua @@ -7,8 +7,7 @@ local draw_overlay = DocView.draw_overlay function DocView:draw_overlay(...) local ns = ("n"):rep(config.line_limit) - local ss = self:get_font():subpixel_scale() - local offset = self:get_font():get_width_subpixel(ns) / ss + local offset = self:get_font():get_width(ns) local x = self:get_line_screen_position(1) + offset local y = self.position.y local w = math.ceil(SCALE * 1) diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index 45967697..d0d75d7f 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -92,7 +92,7 @@ end function ResultsView:on_mouse_pressed(...) local caught = ResultsView.super.on_mouse_pressed(self, ...) if not caught then - self:open_selected_result() + return self:open_selected_result() end end @@ -108,6 +108,7 @@ function ResultsView:open_selected_result() dv.doc:set_selection(res.line, res.col) dv:scroll_to_line(res.line, false, true) end) + return true end @@ -171,7 +172,7 @@ function ResultsView:draw() local ox, oy = self:get_content_offset() local x, y = ox + style.padding.x, oy + style.padding.y local files_number = core.project_files_number() - local per = files_number and self.last_file_idx / files_number or 1 + local per = common.clamp(files_number and self.last_file_idx / files_number or 1, 0, 1) local text if self.searching then if files_number then diff --git a/data/plugins/scale.lua b/data/plugins/scale.lua index 8d16304b..56eabbb0 100644 --- a/data/plugins/scale.lua +++ b/data/plugins/scale.lua @@ -13,9 +13,6 @@ config.plugins.scale = { use_mousewheel = true } -local MINIMUM_SCALE = 0.25; - -local scale_level = 0 local scale_steps = 0.05 local current_scale = SCALE @@ -36,9 +33,6 @@ local function set_scale(scale) local s = scale / current_scale current_scale = scale - -- we set scale_level in case this was called by user - scale_level = (scale - default_scale) / scale_steps - if config.plugins.scale.mode == "ui" then SCALE = scale @@ -50,10 +44,14 @@ local function set_scale(scale) style.tab_width = style.tab_width * s for _, name in ipairs {"font", "big_font", "icon_font", "icon_big_font", "code_font"} do - renderer.font.set_size(style[name], s * style[name]:get_size()) + style[name] = renderer.font.copy(style[name], s * style[name]:get_size()) end else - renderer.font.set_size(style.code_font, s * style.code_font:get_size()) + style.code_font = renderer.font.copy(style.code_font, s * style.code_font:get_size()) + end + + for _, font in pairs(style.syntax_fonts) do + renderer.font.set_size(font, s * font:get_size()) end -- restore scroll positions @@ -69,30 +67,16 @@ local function get_scale() return current_scale end -local on_mouse_wheel = RootView.on_mouse_wheel - -function RootView:on_mouse_wheel(d, ...) - if keymap.modkeys["ctrl"] and config.plugins.scale.use_mousewheel then - if d < 0 then command.perform "scale:decrease" end - if d > 0 then command.perform "scale:increase" end - else - return on_mouse_wheel(self, d, ...) - end -end - local function res_scale() - scale_level = 0 set_scale(default_scale) end local function inc_scale() - scale_level = scale_level + 1 - set_scale(default_scale + scale_level * scale_steps) + set_scale(current_scale + scale_steps) end -local function dec_scale() - scale_level = scale_level - 1 - set_scale(math.max(default_scale + scale_level * scale_steps), MINIMUM_SCALE) +local function dec_scale() + set_scale(current_scale - scale_steps) end @@ -106,6 +90,8 @@ keymap.add { ["ctrl+0"] = "scale:reset", ["ctrl+-"] = "scale:decrease", ["ctrl+="] = "scale:increase", + ["ctrl+wheelup"] = "scale:increase", + ["ctrl+wheeldown"] = "scale:decrease" } return { diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index f9a67aaf..fa3ab53a 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -243,7 +243,7 @@ function TreeView:on_mouse_pressed(button, x, y, clicks) end else core.try(function() - local doc_filename = common.relative_path(core.project_dir, hovered_item.abs_filename) + local doc_filename = core.normalize_to_project_dir(hovered_item.abs_filename) core.root_view:open_doc(core.open_doc(doc_filename)) end) end @@ -437,15 +437,31 @@ menu:register( command.add(nil, { ["treeview:toggle"] = function() view.visible = not view.visible - end, + end}) + +command.add(function() return view.hovered_item ~= nil end, { ["treeview:rename"] = function() local old_filename = view.hovered_item.filename + local old_abs_filename = view.hovered_item.abs_filename core.command_view:set_text(old_filename) core.command_view:enter("Rename", function(filename) - os.rename(old_filename, filename) + filename = core.normalize_to_project_dir(filename) + local abs_filename = core.project_absolute_path(filename) + local res, err = os.rename(old_abs_filename, abs_filename) + if res then -- successfully renamed + for _, doc in ipairs(core.docs) do + if doc.abs_filename and old_abs_filename == doc.abs_filename then + doc:set_filename(filename, abs_filename) -- make doc point to the new filename + doc:reset_syntax() + break -- only first needed + end + end + core.log("Renamed \"%s\" to \"%s\"", old_filename, filename) + else + core.error("Error while renaming \"%s\" to \"%s\": %s", old_abs_filename, abs_filename, err) + end core.reschedule_project_scan() - core.log("Renamed \"%s\" to \"%s\"", old_filename, filename) end, common.path_suggest) end, @@ -521,7 +537,7 @@ command.add(nil, { local hovered_item = view.hovered_item if PLATFORM == "Windows" then - system.exec("start " .. hovered_item.abs_filename) + system.exec(string.format("start \"\" %q", hovered_item.abs_filename)) elseif string.find(PLATFORM, "Mac") then system.exec(string.format("open %q", hovered_item.abs_filename)) elseif PLATFORM == "Linux" then |
