From 257b9ab753ed9ec3355df57ce6f4373c823d43d4 Mon Sep 17 00:00:00 2001 From: rxi Date: Sun, 24 May 2020 17:34:23 +0100 Subject: [PATCH 01/12] Added `core.temp_filename()` --- data/core/init.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/data/core/init.lua b/data/core/init.lua index 691fab10..0836440a 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -120,8 +120,34 @@ function core.init() end +math.randomseed(system.get_time() * 1000) + +local function uid() + return string.gsub("xxxxxx", ".", function() + local chars = "0123456789abcdefghijklmnopqrstuvwxyz" + local n = math.random(#chars) + return chars:sub(n, n) + end) +end + +local temp_file_prefix = ".temp_" .. uid() + +local function delete_temp_files() + for _, filename in ipairs(system.list_dir(EXEDIR)) do + if filename:find(temp_file_prefix, 1, true) == 1 then + os.remove(EXEDIR .. PATHSEP .. filename) + end + end +end + +function core.temp_filename(ext) + return EXEDIR .. PATHSEP .. temp_file_prefix .. uid() .. (ext or "") +end + + function core.quit(force) if force then + delete_temp_files() os.exit() end local dirty_count = 0 From 064b6d0b9551e483e02f1347dac0aa8a6225a8c8 Mon Sep 17 00:00:00 2001 From: rxi Date: Tue, 26 May 2020 10:17:36 +0100 Subject: [PATCH 02/12] Fixed changing of cwd and loading of commandline files the current-working-directory is now set at the start of `core.init` after the absolute path for all filename arguments have been resolved --- data/core/init.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 0836440a..ce17716f 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -82,6 +82,19 @@ function core.init() CommandView = require "core.commandview" Doc = require "core.doc" + local project_dir = "." + local files = {} + for i = 2, #ARGS do + local info = system.get_file_info(ARGS[i]) or {} + if info.type == "file" then + table.insert(files, system.absolute_path(ARGS[i])) + elseif info.type == "dir" then + project_dir = ARGS[i] + end + end + + system.chdir(project_dir) + core.frame_start = 0 core.clip_rect_stack = {{ 0,0,0,0 }} core.log_items = {} @@ -103,20 +116,13 @@ function core.init() local got_user_error = not core.try(require, "user") local got_project_error = not core.load_project_module() - for i = 2, #ARGS do - local filename = ARGS[i] - local info = system.get_file_info(filename) - if info and info.type == "file" then - core.root_view:open_doc(core.open_doc(filename)) - end + for _, filename in ipairs(files) do + core.root_view:open_doc(core.open_doc(filename)) end if got_plugin_error or got_user_error or got_project_error then command.perform("core:open-log") end - - local info = ARGS[2] and system.get_file_info(ARGS[2]) - system.chdir(info and info.type == "dir" and ARGS[2] or ".") end From e7cf551e2298f7e941ecb7f594a6747739d9a396 Mon Sep 17 00:00:00 2001 From: rxi Date: Tue, 26 May 2020 10:33:07 +0100 Subject: [PATCH 03/12] Changed EmptyView text from `empty` to `lite` --- data/core/rootview.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 97fc1c1e..3266ace9 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -13,7 +13,7 @@ function EmptyView:draw() self:draw_background(style.background) local pos = self.position local x, y, w, h = pos.x, pos.y, self.size.x, self.size.y - local _, y = common.draw_text(style.big_font, style.dim, "empty", "center", x, y, w, h) + local _, y = common.draw_text(style.big_font, style.dim, "lite", "center", x, y, w, h) local lines = { { fmt = "%s to run a command", cmd = "core:command-finder" }, { fmt = "%s to open a file from the project", cmd = "core:file-finder" }, From 74755f5b4a407f81661d6737ac3634fdc67cc9f4 Mon Sep 17 00:00:00 2001 From: rxi Date: Wed, 27 May 2020 11:38:42 +0100 Subject: [PATCH 04/12] Simplified implementation of `core.temp_filename()` --- data/core/init.lua | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index ce17716f..5ba0f005 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -126,17 +126,9 @@ function core.init() end -math.randomseed(system.get_time() * 1000) - -local function uid() - return string.gsub("xxxxxx", ".", function() - local chars = "0123456789abcdefghijklmnopqrstuvwxyz" - local n = math.random(#chars) - return chars:sub(n, n) - end) -end - -local temp_file_prefix = ".temp_" .. uid() +local temp_uid = (system.get_time() * 1000) % 0xffffffff +local temp_file_prefix = string.format(".lite_temp_%08x", temp_uid) +local temp_file_counter = 0 local function delete_temp_files() for _, filename in ipairs(system.list_dir(EXEDIR)) do @@ -147,7 +139,9 @@ local function delete_temp_files() end function core.temp_filename(ext) - return EXEDIR .. PATHSEP .. temp_file_prefix .. uid() .. (ext or "") + temp_file_counter = temp_file_counter + 1 + return EXEDIR .. PATHSEP .. temp_file_prefix + .. string.format("%06x", temp_file_counter) .. (ext or "") end From 9c652086e822d81dc1987d771bc6448c8359951f Mon Sep 17 00:00:00 2001 From: rxi Date: Thu, 28 May 2020 11:50:03 +0100 Subject: [PATCH 05/12] Improved behaviour of and renamed `translate.next|previous_word_boundary` --- data/core/commands/doc.lua | 4 ++-- data/core/doc/translate.lua | 39 ++++++++++++++++++------------------- data/core/keymap.lua | 16 +++++++-------- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index b7914ece..ef3bbc62 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -320,8 +320,8 @@ local commands = { local translations = { ["previous-char"] = translate.previous_char, ["next-char"] = translate.next_char, - ["previous-word-boundary"] = translate.previous_word_boundary, - ["next-word-boundary"] = translate.next_word_boundary, + ["previous-word-start"] = translate.previous_word_start, + ["next-word-end"] = translate.next_word_end, ["previous-start-of-block"] = translate.previous_start_of_block, ["next-start-of-block"] = translate.next_start_of_block, ["start-of-doc"] = translate.start_of_doc, diff --git a/data/core/doc/translate.lua b/data/core/doc/translate.lua index 477411c6..7c850eec 100644 --- a/data/core/doc/translate.lua +++ b/data/core/doc/translate.lua @@ -28,33 +28,32 @@ function translate.next_char(doc, line, col) end -function translate.previous_word_boundary(doc, line, col) - local char = doc:get_char(doc:position_offset(line, col, -1)) - local inword = not is_non_word(char) - repeat - local line2, col2 = line, col - line, col = doc:position_offset(line, col, -1) - if line == line2 and col == col2 then +function translate.previous_word_start(doc, line, col) + local prev + while line > 1 or col > 1 do + local l, c = doc:position_offset(line, col, -1) + local char = doc:get_char(l, c) + if prev and prev ~= char or not is_non_word(char) then break end - local c = doc:get_char(doc:position_offset(line, col, -1)) - until inword and is_non_word(c) or not inword and c ~= char - return line, col + prev, line, col = char, l, c + end + return translate.start_of_word(doc, line, col) end -function translate.next_word_boundary(doc, line, col) - local char = doc:get_char(line, col) - local inword = not is_non_word(char) - repeat - local line2, col2 = line, col - line, col = doc:position_offset(line, col, 1) - if line == line2 and col == col2 then +function translate.next_word_end(doc, line, col) + local prev + local end_line, end_col = translate.end_of_doc(doc, line, col) + while line < end_line or col < end_col do + local char = doc:get_char(line, col) + if prev and prev ~= char or not is_non_word(char) then break end - local c = doc:get_char(line, col) - until inword and is_non_word(c) or not inword and c ~= char - return line, col + line, col = doc:position_offset(line, col, 1) + prev = char + end + return translate.end_of_word(doc, line, col) end diff --git a/data/core/keymap.lua b/data/core/keymap.lua index ab5fa386..e45c106d 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -132,12 +132,12 @@ keymap.add { ["shift+tab"] = "doc:unindent", ["backspace"] = "doc:backspace", ["shift+backspace"] = "doc:backspace", - ["ctrl+backspace"] = "doc:delete-to-previous-word-boundary", - ["ctrl+shift+backspace"] = "doc:delete-to-previous-word-boundary", + ["ctrl+backspace"] = "doc:delete-to-previous-word-start", + ["ctrl+shift+backspace"] = "doc:delete-to-previous-word-start", ["delete"] = "doc:delete", ["shift+delete"] = "doc:delete", - ["ctrl+delete"] = "doc:delete-to-next-word-boundary", - ["ctrl+shift+delete"] = "doc:delete-to-next-word-boundary", + ["ctrl+delete"] = "doc:delete-to-next-word-end", + ["ctrl+shift+delete"] = "doc:delete-to-next-word-end", ["return"] = { "command:submit", "doc:newline" }, ["ctrl+return"] = "doc:newline-below", ["ctrl+shift+return"] = "doc:newline-above", @@ -155,8 +155,8 @@ keymap.add { ["right"] = "doc:move-to-next-char", ["up"] = { "command:select-previous", "doc:move-to-previous-line" }, ["down"] = { "command:select-next", "doc:move-to-next-line" }, - ["ctrl+left"] = "doc:move-to-previous-word-boundary", - ["ctrl+right"] = "doc:move-to-next-word-boundary", + ["ctrl+left"] = "doc:move-to-previous-word-start", + ["ctrl+right"] = "doc:move-to-next-word-end", ["ctrl+["] = "doc:move-to-previous-start-of-block", ["ctrl+]"] = "doc:move-to-next-start-of-block", ["home"] = "doc:move-to-start-of-line", @@ -170,8 +170,8 @@ keymap.add { ["shift+right"] = "doc:select-to-next-char", ["shift+up"] = "doc:select-to-previous-line", ["shift+down"] = "doc:select-to-next-line", - ["ctrl+shift+left"] = "doc:select-to-previous-word-boundary", - ["ctrl+shift+right"] = "doc:select-to-next-word-boundary", + ["ctrl+shift+left"] = "doc:select-to-previous-word-start", + ["ctrl+shift+right"] = "doc:select-to-next-word-end", ["ctrl+shift+["] = "doc:select-to-previous-start-of-block", ["ctrl+shift+]"] = "doc:select-to-next-start-of-block", ["shift+home"] = "doc:select-to-start-of-line", From 1b2fda28256d3bf72a978da8f78d1b4925bfafe4 Mon Sep 17 00:00:00 2001 From: rxi Date: Thu, 28 May 2020 13:08:18 +0100 Subject: [PATCH 06/12] Changed block movement to mimic word movement --- data/core/commands/doc.lua | 4 ++-- data/core/doc/translate.lua | 16 ++++++++-------- data/core/keymap.lua | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index ef3bbc62..1afd546c 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -322,8 +322,8 @@ local translations = { ["next-char"] = translate.next_char, ["previous-word-start"] = translate.previous_word_start, ["next-word-end"] = translate.next_word_end, - ["previous-start-of-block"] = translate.previous_start_of_block, - ["next-start-of-block"] = translate.next_start_of_block, + ["previous-block-start"] = translate.previous_block_start, + ["next-block-end"] = translate.next_block_end, ["start-of-doc"] = translate.start_of_doc, ["end-of-doc"] = translate.end_of_doc, ["start-of-line"] = translate.start_of_line, diff --git a/data/core/doc/translate.lua b/data/core/doc/translate.lua index 7c850eec..b084e89a 100644 --- a/data/core/doc/translate.lua +++ b/data/core/doc/translate.lua @@ -85,30 +85,30 @@ function translate.end_of_word(doc, line, col) end -function translate.previous_start_of_block(doc, line, col) +function translate.previous_block_start(doc, line, col) while true do line = line - 1 if line <= 1 then return 1, 1 end - if doc.lines[line-1]:match("^%s*$") - and not doc.lines[line]:match("^%s*$") then + if doc.lines[line-1]:find("^%s*$") + and not doc.lines[line]:find("^%s*$") then return line, (doc.lines[line]:find("%S")) end end end -function translate.next_start_of_block(doc, line, col) +function translate.next_block_end(doc, line, col) while true do - line = line + 1 if line >= #doc.lines then return #doc.lines, 1 end - if doc.lines[line-1]:match("^%s*$") - and not doc.lines[line]:match("^%s*$") then - return line, (doc.lines[line]:find("%S")) + if doc.lines[line+1]:find("^%s*$") + and not doc.lines[line]:find("^%s*$") then + return line+1, #doc.lines[line+1] end + line = line + 1 end end diff --git a/data/core/keymap.lua b/data/core/keymap.lua index e45c106d..6b5180a1 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -157,8 +157,8 @@ keymap.add { ["down"] = { "command:select-next", "doc:move-to-next-line" }, ["ctrl+left"] = "doc:move-to-previous-word-start", ["ctrl+right"] = "doc:move-to-next-word-end", - ["ctrl+["] = "doc:move-to-previous-start-of-block", - ["ctrl+]"] = "doc:move-to-next-start-of-block", + ["ctrl+["] = "doc:move-to-previous-block-start", + ["ctrl+]"] = "doc:move-to-next-block-end", ["home"] = "doc:move-to-start-of-line", ["end"] = "doc:move-to-end-of-line", ["ctrl+home"] = "doc:move-to-start-of-doc", @@ -172,8 +172,8 @@ keymap.add { ["shift+down"] = "doc:select-to-next-line", ["ctrl+shift+left"] = "doc:select-to-previous-word-start", ["ctrl+shift+right"] = "doc:select-to-next-word-end", - ["ctrl+shift+["] = "doc:select-to-previous-start-of-block", - ["ctrl+shift+]"] = "doc:select-to-next-start-of-block", + ["ctrl+shift+["] = "doc:select-to-previous-block-start", + ["ctrl+shift+]"] = "doc:select-to-next-block-end", ["shift+home"] = "doc:select-to-start-of-line", ["shift+end"] = "doc:select-to-end-of-line", ["ctrl+shift+home"] = "doc:select-to-start-of-doc", From b96609b7b86187c12674a0bd60b9ba1ac9b8f7f3 Mon Sep 17 00:00:00 2001 From: rxi Date: Fri, 29 May 2020 09:33:42 +0100 Subject: [PATCH 07/12] Removed redundant __APPLE__ case in get_scale() --- src/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.c b/src/main.c index 21e94397..11331d1b 100644 --- a/src/main.c +++ b/src/main.c @@ -20,8 +20,6 @@ static double get_scale(void) { SDL_GetDisplayDPI(0, NULL, &dpi, NULL); #if _WIN32 return dpi / 96.0; -#elif __APPLE__ - return 1.0; /* dpi / 72.0; */ #else return 1.0; #endif From cc58fcc35b0bf80e785c22af2862c68ba3adc388 Mon Sep 17 00:00:00 2001 From: rxi Date: Fri, 29 May 2020 17:18:04 +0100 Subject: [PATCH 08/12] Changed summer color theme's caret color --- data/user/colors/summer.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/user/colors/summer.lua b/data/user/colors/summer.lua index 64c669a9..5e48cf75 100644 --- a/data/user/colors/summer.lua +++ b/data/user/colors/summer.lua @@ -5,7 +5,7 @@ style.background = { common.color "#fbfbfb" } style.background2 = { common.color "#f2f2f2" } style.background3 = { common.color "#f2f2f2" } style.text = { common.color "#404040" } -style.caret = { common.color "#181818" } +style.caret = { common.color "#fc1785" } style.accent = { common.color "#fc1785" } style.dim = { common.color "#b0b0b0" } style.divider = { common.color "#e8e8e8" } From 7fbefe40d527e3aa38e04ae084927a275d80fae0 Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 30 May 2020 08:53:48 +0100 Subject: [PATCH 09/12] Made `system.set_window_title` only be called on title change --- data/core/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 5ba0f005..a9aa6a0e 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -400,10 +400,10 @@ function core.step() -- update window title local name = core.active_view:get_name() - if name ~= "---" then - system.set_window_title(name .. " - lite") - else - system.set_window_title("lite") + local title = (name ~= "---") and (name .. " - lite") or "lite" + if title ~= core.window_title then + system.set_window_title(title) + core.window_title = title end -- draw From db8c5ea2aa7d48bf429e2d091b6ac85e1cb57938 Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 30 May 2020 09:11:42 +0100 Subject: [PATCH 10/12] Renamed core:command/file-finder => core:find-command/file --- data/core/commands/core.lua | 4 ++-- data/core/keymap.lua | 4 ++-- data/core/rootview.lua | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index e30fe90a..dbe08a41 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -35,7 +35,7 @@ command.add(nil, { end) end, - ["core:command-finder"] = function() + ["core:find-command"] = function() local commands = command.get_all_valid() core.command_view:enter("Do Command", function(text, item) if item then @@ -54,7 +54,7 @@ command.add(nil, { end) end, - ["core:file-finder"] = function() + ["core:find-file"] = function() core.command_view:enter("Open File From Project", function(text, item) text = item and item.text or text core.root_view:open_doc(core.open_doc(text)) diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 6b5180a1..19c2fdd8 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -84,8 +84,8 @@ end keymap.add { - ["ctrl+shift+p"] = "core:command-finder", - ["ctrl+p"] = "core:file-finder", + ["ctrl+shift+p"] = "core:find-command", + ["ctrl+p"] = "core:find-file", ["ctrl+o"] = "core:open-file", ["ctrl+n"] = "core:new-doc", ["alt+return"] = "core:toggle-fullscreen", diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 3266ace9..5a978695 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -15,8 +15,8 @@ function EmptyView:draw() local x, y, w, h = pos.x, pos.y, self.size.x, self.size.y local _, y = common.draw_text(style.big_font, style.dim, "lite", "center", x, y, w, h) local lines = { - { fmt = "%s to run a command", cmd = "core:command-finder" }, - { fmt = "%s to open a file from the project", cmd = "core:file-finder" }, + { fmt = "%s to run a command", cmd = "core:find-command" }, + { fmt = "%s to open a file from the project", cmd = "core:find-file" }, } local th = style.font:get_height() for _, line in ipairs(lines) do From 508b6fb73a356e83bf7f51bbe7ff982886286641 Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 30 May 2020 14:53:01 +0100 Subject: [PATCH 11/12] Improved RootView's EmptyView --- data/core/rootview.lua | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 5a978695..0b505663 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -9,22 +9,33 @@ local DocView = require "core.docview" local EmptyView = View:extend() -function EmptyView:draw() - self:draw_background(style.background) - local pos = self.position - local x, y, w, h = pos.x, pos.y, self.size.x, self.size.y - local _, y = common.draw_text(style.big_font, style.dim, "lite", "center", x, y, w, h) +local function draw_text(x, y, color) + local th = style.big_font:get_height() + local dh = th + style.padding.y * 2 + x = renderer.draw_text(style.big_font, "lite", x, y + (dh - th) / 2, color) + x = x + style.padding.x + renderer.draw_rect(x, y, math.ceil(1 * SCALE), dh, color) local lines = { { fmt = "%s to run a command", cmd = "core:find-command" }, { fmt = "%s to open a file from the project", cmd = "core:find-file" }, } - local th = style.font:get_height() + th = style.font:get_height() + y = y + (dh - th * 2 - style.padding.y) / 2 + local w = 0 for _, line in ipairs(lines) do local text = string.format(line.fmt, keymap.get_binding(line.cmd)) - y = y + style.padding.y - common.draw_text(style.font, style.dim, text, "center", x, y, w, th) - y = y + th + w = math.max(w, renderer.draw_text(style.font, text, x + style.padding.x, y, color)) + y = y + th + style.padding.y end + return w, dh +end + +function EmptyView:draw() + self:draw_background(style.background) + local w, h = draw_text(0, 0, { 0, 0, 0, 0 }) + local x = self.position.x + math.max(style.padding.x, (self.size.x - w) / 2) + local y = self.position.y + (self.size.y - h) / 2 + draw_text(x, y, style.dim) end From f00d5d55df4488d3c23e7cda478d207a561eba4a Mon Sep 17 00:00:00 2001 From: rxi Date: Sun, 31 May 2020 16:53:53 +0100 Subject: [PATCH 12/12] Version 1.06 --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 11331d1b..c739f5f9 100644 --- a/src/main.c +++ b/src/main.c @@ -98,7 +98,7 @@ int main(int argc, char **argv) { } lua_setglobal(L, "ARGS"); - lua_pushstring(L, "1.05"); + lua_pushstring(L, "1.06"); lua_setglobal(L, "VERSION"); lua_pushstring(L, SDL_GetPlatform());