Merge remote-tracking branch 'rxi/master' into font-rendering-tests

This commit is contained in:
Francesco Abbate 2020-06-02 23:28:52 +02:00
commit 9bd4a8b9de
8 changed files with 109 additions and 75 deletions

View File

@ -35,7 +35,7 @@ command.add(nil, {
end) end)
end, end,
["core:command-finder"] = function() ["core:find-command"] = function()
local commands = command.get_all_valid() local commands = command.get_all_valid()
core.command_view:enter("Do Command", function(text, item) core.command_view:enter("Do Command", function(text, item)
if item then if item then
@ -54,7 +54,7 @@ command.add(nil, {
end) end)
end, end,
["core:file-finder"] = function() ["core:find-file"] = function()
core.command_view:enter("Open File From Project", function(text, item) core.command_view:enter("Open File From Project", function(text, item)
text = item and item.text or text text = item and item.text or text
core.root_view:open_doc(core.open_doc(text)) core.root_view:open_doc(core.open_doc(text))

View File

@ -320,10 +320,10 @@ local commands = {
local translations = { local translations = {
["previous-char"] = translate.previous_char, ["previous-char"] = translate.previous_char,
["next-char"] = translate.next_char, ["next-char"] = translate.next_char,
["previous-word-boundary"] = translate.previous_word_boundary, ["previous-word-start"] = translate.previous_word_start,
["next-word-boundary"] = translate.next_word_boundary, ["next-word-end"] = translate.next_word_end,
["previous-start-of-block"] = translate.previous_start_of_block, ["previous-block-start"] = translate.previous_block_start,
["next-start-of-block"] = translate.next_start_of_block, ["next-block-end"] = translate.next_block_end,
["start-of-doc"] = translate.start_of_doc, ["start-of-doc"] = translate.start_of_doc,
["end-of-doc"] = translate.end_of_doc, ["end-of-doc"] = translate.end_of_doc,
["start-of-line"] = translate.start_of_line, ["start-of-line"] = translate.start_of_line,

View File

@ -28,33 +28,32 @@ function translate.next_char(doc, line, col)
end end
function translate.previous_word_boundary(doc, line, col) function translate.previous_word_start(doc, line, col)
local char = doc:get_char(doc:position_offset(line, col, -1)) local prev
local inword = not is_non_word(char) while line > 1 or col > 1 do
repeat local l, c = doc:position_offset(line, col, -1)
local line2, col2 = line, col local char = doc:get_char(l, c)
line, col = doc:position_offset(line, col, -1) if prev and prev ~= char or not is_non_word(char) then
if line == line2 and col == col2 then
break break
end end
local c = doc:get_char(doc:position_offset(line, col, -1)) prev, line, col = char, l, c
until inword and is_non_word(c) or not inword and c ~= char end
return line, col return translate.start_of_word(doc, line, col)
end end
function translate.next_word_boundary(doc, line, col) function translate.next_word_end(doc, line, col)
local char = doc:get_char(line, col) local prev
local inword = not is_non_word(char) local end_line, end_col = translate.end_of_doc(doc, line, col)
repeat while line < end_line or col < end_col do
local line2, col2 = line, col local char = doc:get_char(line, col)
line, col = doc:position_offset(line, col, 1) if prev and prev ~= char or not is_non_word(char) then
if line == line2 and col == col2 then
break break
end end
local c = doc:get_char(line, col) line, col = doc:position_offset(line, col, 1)
until inword and is_non_word(c) or not inword and c ~= char prev = char
return line, col end
return translate.end_of_word(doc, line, col)
end end
@ -86,30 +85,30 @@ function translate.end_of_word(doc, line, col)
end end
function translate.previous_start_of_block(doc, line, col) function translate.previous_block_start(doc, line, col)
while true do while true do
line = line - 1 line = line - 1
if line <= 1 then if line <= 1 then
return 1, 1 return 1, 1
end end
if doc.lines[line-1]:match("^%s*$") if doc.lines[line-1]:find("^%s*$")
and not doc.lines[line]:match("^%s*$") then and not doc.lines[line]:find("^%s*$") then
return line, (doc.lines[line]:find("%S")) return line, (doc.lines[line]:find("%S"))
end end
end end
end end
function translate.next_start_of_block(doc, line, col) function translate.next_block_end(doc, line, col)
while true do while true do
line = line + 1
if line >= #doc.lines then if line >= #doc.lines then
return #doc.lines, 1 return #doc.lines, 1
end end
if doc.lines[line-1]:match("^%s*$") if doc.lines[line+1]:find("^%s*$")
and not doc.lines[line]:match("^%s*$") then and not doc.lines[line]:find("^%s*$") then
return line, (doc.lines[line]:find("%S")) return line+1, #doc.lines[line+1]
end end
line = line + 1
end end
end end

View File

@ -82,6 +82,19 @@ function core.init()
CommandView = require "core.commandview" CommandView = require "core.commandview"
Doc = require "core.doc" 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.frame_start = 0
core.clip_rect_stack = {{ 0,0,0,0 }} core.clip_rect_stack = {{ 0,0,0,0 }}
core.log_items = {} core.log_items = {}
@ -103,25 +116,38 @@ function core.init()
local got_user_error = not core.try(require, "user") local got_user_error = not core.try(require, "user")
local got_project_error = not core.load_project_module() local got_project_error = not core.load_project_module()
for i = 2, #ARGS do for _, filename in ipairs(files) do
local filename = ARGS[i] core.root_view:open_doc(core.open_doc(filename))
local info = system.get_file_info(filename)
if info and info.type == "file" then
core.root_view:open_doc(core.open_doc(filename))
end
end end
if got_plugin_error or got_user_error or got_project_error then if got_plugin_error or got_user_error or got_project_error then
command.perform("core:open-log") command.perform("core:open-log")
end end
end
local info = ARGS[2] and system.get_file_info(ARGS[2])
system.chdir(info and info.type == "dir" and ARGS[2] or ".") 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
if filename:find(temp_file_prefix, 1, true) == 1 then
os.remove(EXEDIR .. PATHSEP .. filename)
end
end
end
function core.temp_filename(ext)
temp_file_counter = temp_file_counter + 1
return EXEDIR .. PATHSEP .. temp_file_prefix
.. string.format("%06x", temp_file_counter) .. (ext or "")
end end
function core.quit(force) function core.quit(force)
if force then if force then
delete_temp_files()
os.exit() os.exit()
end end
local dirty_count = 0 local dirty_count = 0
@ -374,10 +400,10 @@ function core.step()
-- update window title -- update window title
local name = core.active_view:get_name() local name = core.active_view:get_name()
if name ~= "---" then local title = (name ~= "---") and (name .. " - lite") or "lite"
system.set_window_title(name .. " - lite") if title ~= core.window_title then
else system.set_window_title(title)
system.set_window_title("lite") core.window_title = title
end end
-- draw -- draw

View File

@ -84,8 +84,8 @@ end
keymap.add { keymap.add {
["ctrl+shift+p"] = "core:command-finder", ["ctrl+shift+p"] = "core:find-command",
["ctrl+p"] = "core:file-finder", ["ctrl+p"] = "core:find-file",
["ctrl+o"] = "core:open-file", ["ctrl+o"] = "core:open-file",
["ctrl+n"] = "core:new-doc", ["ctrl+n"] = "core:new-doc",
["alt+return"] = "core:toggle-fullscreen", ["alt+return"] = "core:toggle-fullscreen",
@ -132,12 +132,12 @@ keymap.add {
["shift+tab"] = "doc:unindent", ["shift+tab"] = "doc:unindent",
["backspace"] = "doc:backspace", ["backspace"] = "doc:backspace",
["shift+backspace"] = "doc:backspace", ["shift+backspace"] = "doc:backspace",
["ctrl+backspace"] = "doc:delete-to-previous-word-boundary", ["ctrl+backspace"] = "doc:delete-to-previous-word-start",
["ctrl+shift+backspace"] = "doc:delete-to-previous-word-boundary", ["ctrl+shift+backspace"] = "doc:delete-to-previous-word-start",
["delete"] = "doc:delete", ["delete"] = "doc:delete",
["shift+delete"] = "doc:delete", ["shift+delete"] = "doc:delete",
["ctrl+delete"] = "doc:delete-to-next-word-boundary", ["ctrl+delete"] = "doc:delete-to-next-word-end",
["ctrl+shift+delete"] = "doc:delete-to-next-word-boundary", ["ctrl+shift+delete"] = "doc:delete-to-next-word-end",
["return"] = { "command:submit", "doc:newline" }, ["return"] = { "command:submit", "doc:newline" },
["ctrl+return"] = "doc:newline-below", ["ctrl+return"] = "doc:newline-below",
["ctrl+shift+return"] = "doc:newline-above", ["ctrl+shift+return"] = "doc:newline-above",
@ -155,10 +155,10 @@ keymap.add {
["right"] = "doc:move-to-next-char", ["right"] = "doc:move-to-next-char",
["up"] = { "command:select-previous", "doc:move-to-previous-line" }, ["up"] = { "command:select-previous", "doc:move-to-previous-line" },
["down"] = { "command:select-next", "doc:move-to-next-line" }, ["down"] = { "command:select-next", "doc:move-to-next-line" },
["ctrl+left"] = "doc:move-to-previous-word-boundary", ["ctrl+left"] = "doc:move-to-previous-word-start",
["ctrl+right"] = "doc:move-to-next-word-boundary", ["ctrl+right"] = "doc:move-to-next-word-end",
["ctrl+["] = "doc:move-to-previous-start-of-block", ["ctrl+["] = "doc:move-to-previous-block-start",
["ctrl+]"] = "doc:move-to-next-start-of-block", ["ctrl+]"] = "doc:move-to-next-block-end",
["home"] = "doc:move-to-start-of-line", ["home"] = "doc:move-to-start-of-line",
["end"] = "doc:move-to-end-of-line", ["end"] = "doc:move-to-end-of-line",
["ctrl+home"] = "doc:move-to-start-of-doc", ["ctrl+home"] = "doc:move-to-start-of-doc",
@ -170,10 +170,10 @@ keymap.add {
["shift+right"] = "doc:select-to-next-char", ["shift+right"] = "doc:select-to-next-char",
["shift+up"] = "doc:select-to-previous-line", ["shift+up"] = "doc:select-to-previous-line",
["shift+down"] = "doc:select-to-next-line", ["shift+down"] = "doc:select-to-next-line",
["ctrl+shift+left"] = "doc:select-to-previous-word-boundary", ["ctrl+shift+left"] = "doc:select-to-previous-word-start",
["ctrl+shift+right"] = "doc:select-to-next-word-boundary", ["ctrl+shift+right"] = "doc:select-to-next-word-end",
["ctrl+shift+["] = "doc:select-to-previous-start-of-block", ["ctrl+shift+["] = "doc:select-to-previous-block-start",
["ctrl+shift+]"] = "doc:select-to-next-start-of-block", ["ctrl+shift+]"] = "doc:select-to-next-block-end",
["shift+home"] = "doc:select-to-start-of-line", ["shift+home"] = "doc:select-to-start-of-line",
["shift+end"] = "doc:select-to-end-of-line", ["shift+end"] = "doc:select-to-end-of-line",
["ctrl+shift+home"] = "doc:select-to-start-of-doc", ["ctrl+shift+home"] = "doc:select-to-start-of-doc",

View File

@ -9,22 +9,33 @@ local DocView = require "core.docview"
local EmptyView = View:extend() local EmptyView = View:extend()
function EmptyView:draw() local function draw_text(x, y, color)
self:draw_background(style.background) local th = style.big_font:get_height()
local pos = self.position local dh = th + style.padding.y * 2
local x, y, w, h = pos.x, pos.y, self.size.x, self.size.y x = renderer.draw_text(style.big_font, "lite", x, y + (dh - th) / 2, color)
local _, y = common.draw_text(style.big_font, style.dim, "empty", "center", x, y, w, h) x = x + style.padding.x
renderer.draw_rect(x, y, math.ceil(1 * SCALE), dh, color)
local lines = { local lines = {
{ fmt = "%s to run a command", cmd = "core:command-finder" }, { fmt = "%s to run a command", cmd = "core:find-command" },
{ fmt = "%s to open a file from the project", cmd = "core:file-finder" }, { 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 for _, line in ipairs(lines) do
local text = string.format(line.fmt, keymap.get_binding(line.cmd)) local text = string.format(line.fmt, keymap.get_binding(line.cmd))
y = y + style.padding.y w = math.max(w, renderer.draw_text(style.font, text, x + style.padding.x, y, color))
common.draw_text(style.font, style.dim, text, "center", x, y, w, th) y = y + th + style.padding.y
y = y + th
end 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 end

View File

@ -5,7 +5,7 @@ style.background = { common.color "#fbfbfb" }
style.background2 = { common.color "#f2f2f2" } style.background2 = { common.color "#f2f2f2" }
style.background3 = { common.color "#f2f2f2" } style.background3 = { common.color "#f2f2f2" }
style.text = { common.color "#404040" } style.text = { common.color "#404040" }
style.caret = { common.color "#181818" } style.caret = { common.color "#fc1785" }
style.accent = { common.color "#fc1785" } style.accent = { common.color "#fc1785" }
style.dim = { common.color "#b0b0b0" } style.dim = { common.color "#b0b0b0" }
style.divider = { common.color "#e8e8e8" } style.divider = { common.color "#e8e8e8" }

View File

@ -20,8 +20,6 @@ static double get_scale(void) {
SDL_GetDisplayDPI(0, NULL, &dpi, NULL); SDL_GetDisplayDPI(0, NULL, &dpi, NULL);
#if _WIN32 #if _WIN32
return dpi / 96.0; return dpi / 96.0;
#elif __APPLE__
return 1.0; /* dpi / 72.0; */
#else #else
return 1.0; return 1.0;
#endif #endif
@ -100,7 +98,7 @@ int main(int argc, char **argv) {
} }
lua_setglobal(L, "ARGS"); lua_setglobal(L, "ARGS");
lua_pushstring(L, "1.05"); lua_pushstring(L, "1.06");
lua_setglobal(L, "VERSION"); lua_setglobal(L, "VERSION");
lua_pushstring(L, SDL_GetPlatform()); lua_pushstring(L, SDL_GetPlatform());