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,
["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))

View File

@ -320,10 +320,10 @@ 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-start-of-block"] = translate.previous_start_of_block,
["next-start-of-block"] = translate.next_start_of_block,
["previous-word-start"] = translate.previous_word_start,
["next-word-end"] = translate.next_word_end,
["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,

View File

@ -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
@ -86,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

View File

@ -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,25 +116,38 @@ 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
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
function core.quit(force)
if force then
delete_temp_files()
os.exit()
end
local dirty_count = 0
@ -374,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

View File

@ -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",
@ -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,10 +155,10 @@ 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+["] = "doc:move-to-previous-start-of-block",
["ctrl+]"] = "doc:move-to-next-start-of-block",
["ctrl+left"] = "doc:move-to-previous-word-start",
["ctrl+right"] = "doc:move-to-next-word-end",
["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",
@ -170,10 +170,10 @@ 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+["] = "doc:select-to-previous-start-of-block",
["ctrl+shift+]"] = "doc:select-to-next-start-of-block",
["ctrl+shift+left"] = "doc:select-to-previous-word-start",
["ctrl+shift+right"] = "doc:select-to-next-word-end",
["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",

View File

@ -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, "empty", "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: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()
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

View File

@ -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" }

View File

@ -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
@ -100,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());