Merge branch 'master-2.0' into master-luajit-2.0
This commit is contained in:
commit
f18c6ac790
|
@ -6,6 +6,7 @@ local LogView = require "core.logview"
|
|||
|
||||
|
||||
local fullscreen = false
|
||||
local restore_title_view = false
|
||||
|
||||
local function suggest_directory(text)
|
||||
text = common.home_expand(text)
|
||||
|
@ -28,9 +29,12 @@ command.add(nil, {
|
|||
|
||||
["core:toggle-fullscreen"] = function()
|
||||
fullscreen = not fullscreen
|
||||
if fullscreen then
|
||||
restore_title_view = core.title_view.visible
|
||||
end
|
||||
system.set_window_mode(fullscreen and "fullscreen" or "normal")
|
||||
core.show_title_bar(not fullscreen)
|
||||
core.title_view:configure_hit_test(not fullscreen)
|
||||
core.show_title_bar(not fullscreen and restore_title_view)
|
||||
core.title_view:configure_hit_test(not fullscreen and restore_title_view)
|
||||
end,
|
||||
|
||||
["core:reload-module"] = function()
|
||||
|
@ -160,7 +164,10 @@ command.add(nil, {
|
|||
core.error("Cannot open folder %q", text)
|
||||
return
|
||||
end
|
||||
core.confirm_close_docs(core.docs, core.open_folder_project, text)
|
||||
core.confirm_close_docs(core.docs, function(dirpath)
|
||||
core.close_current_project()
|
||||
core.open_folder_project(dirpath)
|
||||
end, text)
|
||||
end, suggest_directory)
|
||||
end,
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
local core = require "core"
|
||||
local common = require "core.common"
|
||||
local config = require "core.config"
|
||||
local tokenizer = require "core.tokenizer"
|
||||
local Object = require "core.object"
|
||||
|
@ -40,6 +41,13 @@ end
|
|||
|
||||
function Highlighter:reset()
|
||||
self.lines = {}
|
||||
self:soft_reset()
|
||||
end
|
||||
|
||||
function Highlighter:soft_reset()
|
||||
for i=1,#self.lines do
|
||||
self.lines[i] = false
|
||||
end
|
||||
self.first_invalid_line = 1
|
||||
self.max_wanted_line = 0
|
||||
end
|
||||
|
@ -51,16 +59,16 @@ end
|
|||
|
||||
function Highlighter:insert_notify(line, n)
|
||||
self:invalidate(line)
|
||||
local blanks = { }
|
||||
for i = 1, n do
|
||||
table.insert(self.lines, line, false)
|
||||
blanks[i] = false
|
||||
end
|
||||
common.splice(self.lines, line, 0, blanks)
|
||||
end
|
||||
|
||||
function Highlighter:remove_notify(line, n)
|
||||
self:invalidate(line)
|
||||
for i = 1, n do
|
||||
table.remove(self.lines, line)
|
||||
end
|
||||
common.splice(self.lines, line, n)
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ function Doc:reset_syntax()
|
|||
local syn = syntax.get(self.filename or "", header)
|
||||
if self.syntax ~= syn then
|
||||
self.syntax = syn
|
||||
self.highlighter:reset()
|
||||
self.highlighter:soft_reset()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -62,12 +62,15 @@ function Doc:load(filename)
|
|||
local fp = assert( io.open(filename, "rb") )
|
||||
self:reset()
|
||||
self.lines = {}
|
||||
local i = 1
|
||||
for line in fp:lines() do
|
||||
if line:byte(-1) == 13 then
|
||||
line = line:sub(1, -2)
|
||||
self.crlf = true
|
||||
end
|
||||
table.insert(self.lines, line .. "\n")
|
||||
self.highlighter.lines[i] = false
|
||||
i = i + 1
|
||||
end
|
||||
if #self.lines == 0 then
|
||||
table.insert(self.lines, "\n")
|
||||
|
|
|
@ -65,6 +65,22 @@ function core.set_project_dir(new_dir, change_project_fn)
|
|||
return false
|
||||
end
|
||||
|
||||
function core.close_current_project()
|
||||
-- When using system.unwatch_dir we need to pass the watch_id provided by dmon.
|
||||
-- In reality when unwatching a directory the dmon library shifts the other watch_id
|
||||
-- values so the actual watch_id changes. To workaround this problem we assume the
|
||||
-- first watch_id is always 1 and the watch_id are continguous and we unwatch the
|
||||
-- first watch_id repeateadly up to the number of watch_ids.
|
||||
local watch_id_max = 0
|
||||
for _, project_dir in ipairs(core.project_directories) do
|
||||
if project_dir.watch_id and project_dir.watch_id > watch_id_max then
|
||||
watch_id_max = project_dir.watch_id
|
||||
end
|
||||
end
|
||||
for i = 1, watch_id_max do
|
||||
system.unwatch_dir(1)
|
||||
end
|
||||
end
|
||||
|
||||
function core.open_folder_project(dir_path_abs)
|
||||
if core.set_project_dir(dir_path_abs, core.on_quit_project) then
|
||||
|
@ -200,12 +216,12 @@ local function file_search(files, info)
|
|||
inf = curr
|
||||
end
|
||||
end
|
||||
repeat
|
||||
while inf <= sup and not system.path_compare(filename, type, files[inf].filename, files[inf].type) do
|
||||
if files[inf].filename == filename then
|
||||
return inf, true
|
||||
end
|
||||
inf = inf + 1
|
||||
until inf > sup or system.path_compare(filename, type, files[inf].filename, files[inf].type)
|
||||
end
|
||||
return inf, false
|
||||
end
|
||||
|
||||
|
@ -1165,8 +1181,8 @@ end
|
|||
|
||||
|
||||
-- no-op but can be overrided by plugins
|
||||
function core.on_dirmonitor_modify()
|
||||
end
|
||||
function core.on_dirmonitor_modify() end
|
||||
function core.on_dirmonitor_delete() end
|
||||
|
||||
|
||||
function core.on_dir_change(watch_id, action, filepath)
|
||||
|
@ -1175,6 +1191,7 @@ function core.on_dir_change(watch_id, action, filepath)
|
|||
core.dir_rescan_add_job(dir, filepath)
|
||||
if action == "delete" then
|
||||
project_scan_remove_file(dir, filepath)
|
||||
core.on_dirmonitor_delete(dir, filepath)
|
||||
elseif action == "create" then
|
||||
project_scan_add_file(dir, filepath)
|
||||
core.on_dirmonitor_modify(dir, filepath);
|
||||
|
|
|
@ -237,8 +237,13 @@ function tokenizer.tokenize(incoming_syntax, text, state)
|
|||
|
||||
-- consume character if we didn't match
|
||||
if not matched then
|
||||
push_token(res, "normal", text:sub(i, i))
|
||||
i = i + 1
|
||||
local n = 0
|
||||
-- reach the next character
|
||||
while text:byte(i + n + 1) and common.is_utf8_cont(text, i + n + 1) do
|
||||
n = n + 1
|
||||
end
|
||||
push_token(res, "normal", text:sub(i, i + n))
|
||||
i = i + n + 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
local syntax = require "core.syntax"
|
||||
|
||||
syntax.add {
|
||||
name = "C",
|
||||
files = { "%.c$", "%.h$", "%.inl$" },
|
||||
comment = "//",
|
||||
patterns = {
|
||||
|
|
|
@ -4,6 +4,7 @@ pcall(require, "plugins.language_c")
|
|||
local syntax = require "core.syntax"
|
||||
|
||||
syntax.add {
|
||||
name = "C++",
|
||||
files = {
|
||||
"%.h$", "%.inl$", "%.cpp$", "%.cc$", "%.C$", "%.cxx$",
|
||||
"%.c++$", "%.hh$", "%.H$", "%.hxx$", "%.hpp$", "%.h++$"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
local syntax = require "core.syntax"
|
||||
|
||||
syntax.add {
|
||||
name = "CSS",
|
||||
files = { "%.css$" },
|
||||
patterns = {
|
||||
{ pattern = "\\.", type = "normal" },
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
local syntax = require "core.syntax"
|
||||
|
||||
syntax.add {
|
||||
name = "HTML",
|
||||
files = { "%.html?$" },
|
||||
patterns = {
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
local syntax = require "core.syntax"
|
||||
|
||||
syntax.add {
|
||||
name = "JavaScript",
|
||||
files = { "%.js$", "%.json$", "%.cson$" },
|
||||
comment = "//",
|
||||
patterns = {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
local syntax = require "core.syntax"
|
||||
|
||||
syntax.add {
|
||||
name = "Lua",
|
||||
files = "%.lua$",
|
||||
headers = "^#!.*[ /]lua",
|
||||
comment = "--",
|
||||
|
|
|
@ -4,6 +4,7 @@ local syntax = require "core.syntax"
|
|||
|
||||
|
||||
syntax.add {
|
||||
name = "Markdown",
|
||||
files = { "%.md$", "%.markdown$" },
|
||||
patterns = {
|
||||
{ pattern = "\\.", type = "normal" },
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
local syntax = require "core.syntax"
|
||||
|
||||
syntax.add {
|
||||
name = "Python",
|
||||
files = { "%.py$", "%.pyw$" },
|
||||
headers = "^#!.*[ /]python",
|
||||
comment = "#",
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
local syntax = require "core.syntax"
|
||||
|
||||
syntax.add {
|
||||
name = "XML",
|
||||
files = { "%.xml$" },
|
||||
headers = "<%?xml",
|
||||
patterns = {
|
||||
|
|
|
@ -2,20 +2,22 @@
|
|||
local config = require "core.config"
|
||||
local style = require "core.style"
|
||||
local DocView = require "core.docview"
|
||||
local CommandView = require "core.commandview"
|
||||
|
||||
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 x = self:get_line_screen_position(1) + offset
|
||||
local y = self.position.y
|
||||
local w = math.ceil(SCALE * 1)
|
||||
local h = self.size.y
|
||||
|
||||
local color = style.guide or style.selection
|
||||
renderer.draw_rect(x, y, w, h, color)
|
||||
if not self:is(CommandView) then
|
||||
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 x = self:get_line_screen_position(1) + offset
|
||||
local y = self.position.y
|
||||
local w = math.ceil(SCALE * 1)
|
||||
local h = self.size.y
|
||||
|
||||
local color = style.guide or style.selection
|
||||
renderer.draw_rect(x, y, w, h, color)
|
||||
end
|
||||
draw_overlay(self, ...)
|
||||
end
|
||||
|
|
|
@ -42,6 +42,19 @@ function TreeView:new()
|
|||
self.target_size = default_treeview_size
|
||||
self.cache = {}
|
||||
self.tooltip = { x = 0, y = 0, begin = 0, alpha = 0 }
|
||||
self:add_core_hooks()
|
||||
end
|
||||
|
||||
|
||||
function TreeView:add_core_hooks()
|
||||
-- When a file or directory is deleted we delete the corresponding cache entry
|
||||
-- because if the entry is recreated we may use wrong information from cache.
|
||||
local on_delete = core.on_dirmonitor_delete
|
||||
core.on_dirmonitor_delete = function(dir, filepath)
|
||||
local cache = self.cache[dir.name]
|
||||
if cache then cache[filepath] = nil end
|
||||
on_delete(dir, filepath)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -723,6 +723,13 @@ static int f_watch_dir(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int f_unwatch_dir(lua_State *L) {
|
||||
dmon_watch_id watch_id;
|
||||
watch_id.id = luaL_checkinteger(L, 1);
|
||||
dmon_unwatch(watch_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if __linux__
|
||||
static int f_watch_dir_add(lua_State *L) {
|
||||
dmon_watch_id watch_id;
|
||||
|
@ -826,6 +833,7 @@ static const luaL_Reg lib[] = {
|
|||
{ "fuzzy_match", f_fuzzy_match },
|
||||
{ "set_window_opacity", f_set_window_opacity },
|
||||
{ "watch_dir", f_watch_dir },
|
||||
{ "unwatch_dir", f_unwatch_dir },
|
||||
{ "path_compare", f_path_compare },
|
||||
#if __linux__
|
||||
{ "watch_dir_add", f_watch_dir_add },
|
||||
|
|
Loading…
Reference in New Issue