Merge branch with modifications for 2.0.2 release

This commit is contained in:
Francesco Abbate
2021-09-11 08:19:40 +02:00
10 changed files with 148 additions and 38 deletions
+7 -1
View File
@@ -148,7 +148,9 @@ command.add(nil, {
["core:change-project-folder"] = function()
local dirname = common.dirname(core.project_dir)
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
if dirname then
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
end
core.command_view:enter("Change Project Folder", function(text, item)
text = system.absolute_path(common.home_expand(item and item.text or text))
if text == core.project_dir then return end
@@ -162,6 +164,10 @@ command.add(nil, {
end,
["core:open-project-folder"] = function()
local dirname = common.dirname(core.project_dir)
if dirname then
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
end
core.command_view:enter("Open Project", function(text, item)
text = common.home_expand(item and item.text or text)
local path_stat = system.get_file_info(text)
+31 -9
View File
@@ -12,6 +12,7 @@ local last_finds, last_view, last_fn, last_text, last_sel
local case_sensitive = config.find_case_sensitive or false
local find_regex = config.find_regex or false
local found_expression
local function doc()
return core.active_view:is(DocView) and core.active_view.doc or last_view.doc
@@ -34,24 +35,37 @@ local function update_preview(sel, search_fn, text)
if ok and line1 and text ~= "" then
last_view.doc:set_selection(line2, col2, line1, col1)
last_view:scroll_to_line(line2, true)
return true
found_expression = true
else
last_view.doc:set_selection(unpack(sel))
return false
found_expression = false
end
end
local function insert_unique(t, v)
local n = #t
for i = 1, n do
if t[i] == v then return end
end
t[n + 1] = v
end
local function find(label, search_fn)
last_view, last_sel, last_finds = core.active_view,
{ core.active_view.doc:get_selection() }, {}
local text, found = last_view.doc:get_text(unpack(last_sel)), false
local text = last_view.doc:get_text(unpack(last_sel))
found_expression = false
core.command_view:set_text(text, true)
core.status_view:show_tooltip(get_find_tooltip())
core.command_view:enter(label, function(text)
core.command_view:set_hidden_suggestions()
core.command_view:enter(label, function(text, item)
insert_unique(core.previous_find, text)
core.status_view:remove_tooltip()
if found then
if found_expression then
last_fn, last_text = search_fn, text
else
core.error("Couldn't find %q", text)
@@ -59,8 +73,9 @@ local function find(label, search_fn)
last_view:scroll_to_make_visible(unpack(last_sel))
end
end, function(text)
found = update_preview(last_sel, search_fn, text)
update_preview(last_sel, search_fn, text)
last_fn, last_text = search_fn, text
return core.previous_find
end, function(explicit)
core.status_view:remove_tooltip()
if explicit then
@@ -75,19 +90,24 @@ local function replace(kind, default, fn)
core.command_view:set_text(default, true)
core.status_view:show_tooltip(get_find_tooltip())
core.command_view:set_hidden_suggestions()
core.command_view:enter("Find To Replace " .. kind, function(old)
insert_unique(core.previous_find, old)
core.command_view:set_text(old, true)
local s = string.format("Replace %s %q With", kind, old)
core.command_view:set_hidden_suggestions()
core.command_view:enter(s, function(new)
core.status_view:remove_tooltip()
insert_unique(core.previous_replace, new)
local n = doc():replace(function(text)
return fn(text, old, new)
end)
core.log("Replaced %d instance(s) of %s %q with %q", n, kind, old, new)
end, function() end, function()
end, function() return core.previous_replace end, function()
core.status_view:remove_tooltip()
end)
end, function() end, function()
end, function() return core.previous_find end, function()
core.status_view:remove_tooltip()
end)
end
@@ -161,7 +181,9 @@ command.add("core.docview", {
end,
["find-replace:replace"] = function()
replace("Text", doc():get_text(doc():get_selection(true)), function(text, old, new)
local l1, c1, l2, c2 = doc():get_selection()
local selected_text = doc():get_text(l1, c1, l2, c2)
replace("Text", l1 == l2 and selected_text or "", function(text, old, new)
if not find_regex then
return text:gsub(old:gsub("%W", "%%%1"), new:gsub("%%", "%%%%"), nil)
end
+35 -6
View File
@@ -34,6 +34,7 @@ function CommandView:new()
self.suggestion_idx = 1
self.suggestions = {}
self.suggestions_height = 0
self.show_suggestions = true
self.last_change_id = 0
self.gutter_width = 0
self.gutter_text_brightness = 0
@@ -45,6 +46,11 @@ function CommandView:new()
end
function CommandView:set_hidden_suggestions()
self.show_suggestions = false
end
function CommandView:get_name()
return View.get_name(self)
end
@@ -83,10 +89,29 @@ end
function CommandView:move_suggestion_idx(dir)
local n = self.suggestion_idx + dir
self.suggestion_idx = common.clamp(n, 1, #self.suggestions)
self:complete()
self.last_change_id = self.doc:get_change_id()
if self.show_suggestions then
local n = self.suggestion_idx + dir
self.suggestion_idx = common.clamp(n, 1, #self.suggestions)
self:complete()
self.last_change_id = self.doc:get_change_id()
else
local current_suggestion = #self.suggestions > 0 and self.suggestions[self.suggestion_idx].text
local text = self:get_text()
if text == current_suggestion then
local n = self.suggestion_idx + dir
if n == 0 and self.save_suggestion then
self:set_text(self.save_suggestion)
else
self.suggestion_idx = common.clamp(n, 1, #self.suggestions)
self:complete()
end
else
self.save_suggestion = text
self:complete()
end
self.last_change_id = self.doc:get_change_id()
self.state.suggest(self:get_text())
end
end
@@ -134,6 +159,8 @@ function CommandView:exit(submitted, inexplicit)
self.doc:reset()
self.suggestions = {}
if not submitted then cancel(not inexplicit) end
self.show_suggestions = true
self.save_suggestion = nil
end
@@ -187,7 +214,7 @@ function CommandView:update()
-- update suggestions box height
local lh = self:get_suggestion_line_height()
local dest = math.min(#self.suggestions, max_suggestions) * lh
local dest = self.show_suggestions and math.min(#self.suggestions, max_suggestions) * lh or 0
self:move_towards("suggestions_height", dest)
-- update suggestion cursor offset
@@ -256,7 +283,9 @@ end
function CommandView:draw()
CommandView.super.draw(self)
core.root_view:defer_draw(draw_suggestions_box, self)
if self.show_suggestions then
core.root_view:defer_draw(draw_suggestions_box, self)
end
end
+3 -1
View File
@@ -276,6 +276,7 @@ end
function common.normalize_path(filename)
if not filename then return end
if PATHSEP == '\\' then
filename = filename:gsub('[/\\]', '\\')
local drive, rem = filename:match('^([a-zA-Z])(:.*)')
@@ -290,7 +291,8 @@ function common.normalize_path(filename)
table.insert(accu, part)
end
end
return table.concat(accu, PATHSEP)
local npath = table.concat(accu, PATHSEP)
return npath == "" and PATHSEP or npath
end
+16 -12
View File
@@ -17,10 +17,7 @@ local core = {}
local function load_session()
local ok, t = pcall(dofile, USERDIR .. "/session.lua")
if ok and t then
return t.recents, t.window, t.window_mode
end
return {}
return ok and t or {}
end
@@ -30,6 +27,8 @@ local function save_session()
fp:write("return {recents=", common.serialize(core.recent_projects),
", window=", common.serialize(table.pack(system.get_window_size())),
", window_mode=", common.serialize(system.get_window_mode()),
", previous_find=", common.serialize(core.previous_find),
", previous_replace=", common.serialize(core.previous_replace),
"}\n")
fp:close()
end
@@ -320,8 +319,8 @@ local style = require "core.style"
------------------------------- Fonts ----------------------------------------
-- customize fonts:
-- style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 13 * SCALE)
-- style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 13 * SCALE)
-- style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 14 * SCALE)
-- style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 14 * SCALE)
--
-- font names used by lite:
-- style.font : user interface
@@ -435,13 +434,15 @@ function core.init()
end
do
local recent_projects, window_position, window_mode = load_session()
if window_mode == "normal" then
system.set_window_size(table.unpack(window_position))
elseif window_mode == "maximized" then
local session = load_session()
if session.window_mode == "normal" then
system.set_window_size(table.unpack(session.window))
elseif session.window_mode == "maximized" then
system.set_window_mode("maximized")
end
core.recent_projects = recent_projects or {}
core.recent_projects = session.recents or {}
core.previous_find = session.previous_find or {}
core.previous_replace = session.previous_replace or {}
end
local project_dir = core.recent_projects[1] or "."
@@ -461,7 +462,10 @@ function core.init()
project_dir = arg_filename
project_dir_explicit = true
else
delayed_error = string.format("error: invalid file or directory %q", ARGS[i])
-- on macOS we can get an argument like "-psn_0_52353" that we just ignore.
if not ARGS[i]:match("^-psn") then
delayed_error = string.format("error: invalid file or directory %q", ARGS[i])
end
end
end
+1 -1
View File
@@ -23,7 +23,7 @@ end
-- Moves to the end of the identified character.
local function end_character(str, index)
local byte = string.byte(str, index + 1)
while byte >= 128 and byte < 192 do
while byte and byte >= 128 and byte < 192 do
index = index + 1
byte = string.byte(str, index + 1)
end
+4 -4
View File
@@ -21,11 +21,11 @@ style.tab_width = common.round(170 * SCALE)
--
-- On High DPI monitor or non RGB monitor you may consider using antialiasing grayscale instead.
-- The antialiasing grayscale with full hinting is interesting for crisp font rendering.
style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 13 * SCALE)
style.font = renderer.font.load(DATADIR .. "/fonts/FiraSans-Regular.ttf", 14 * SCALE)
style.big_font = style.font:copy(40 * SCALE)
style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 14 * SCALE, {antialiasing="grayscale", hinting="full"})
style.icon_big_font = style.icon_font:copy(20 * SCALE)
style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 13 * SCALE)
style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 16 * SCALE, {antialiasing="grayscale", hinting="full"})
style.icon_big_font = style.icon_font:copy(24 * SCALE)
style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 14 * SCALE)
style.background = { common.color "#2e2e32" }
style.background2 = { common.color "#252529" }