diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index 18b76bc9..16f52a87 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -88,7 +88,8 @@ command.add(nil, { ["core:open-file"] = function() local view = core.active_view if view.doc and view.doc.abs_filename then - core.command_view:set_text(common.home_encode(view.doc.abs_filename)) + local dirname, filename = view.doc.abs_filename:match("(.*)[/\\](.+)$") + core.command_view:set_text(core.normalize_to_project_dir(dirname) .. PATHSEP) end core.command_view:enter("Open File", function(text) core.root_view:open_doc(core.open_doc(common.home_expand(text))) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 9b6ba9af..033055c5 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -45,15 +45,22 @@ local function insert_at_start_of_selected_lines(text, skip_empty) doc():set_selection(line1, col1 + #text, line2, col2 + #text, swap) end + -local function remove_from_start_of_selected_lines(text, skip_empty) +local function remove_from_start_of_selected_lines(text, skip_empty, remove_partial) local line1, col1, line2, col2, swap = doc_multiline_selection(true) for line = line1, line2 do local line_text = doc().lines[line] - if line_text:sub(1, #text) == text - and (not skip_empty or line_text:find("%S")) - then - doc():remove(line, 1, line, #text + 1) + for i = #text, 1, -1 do + if line_text:sub(1, i) == text:sub(1, i) + and (not skip_empty or line_text:find("%S")) + then + doc():remove(line, 1, line, i + 1) + break + end + if not remove_partial then + break + end end end doc():set_selection(line1, col1 - #text, line2, col2 - #text, swap) @@ -198,7 +205,7 @@ local commands = { ["doc:unindent"] = function() local text = get_indent_string() - remove_from_start_of_selected_lines(text) + remove_from_start_of_selected_lines(text, false, true) end, ["doc:duplicate-lines"] = function() @@ -304,6 +311,9 @@ local commands = { ["doc:save-as"] = function() if doc().filename then core.command_view:set_text(doc().filename) + elseif core.last_active_view then + local dirname, filename = core.last_active_view.doc.abs_filename:match("(.*)[/\\](.+)$") + core.command_view:set_text(core.normalize_to_project_dir(dirname) .. PATHSEP) end core.command_view:enter("Save As", function(filename) save(common.home_expand(filename)) diff --git a/data/core/common.lua b/data/core/common.lua index 016ba8c4..1d919bc2 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -58,10 +58,10 @@ local function compare_score(a, b) return a.score > b.score end -local function fuzzy_match_items(items, needle) +local function fuzzy_match_items(items, needle, files) local res = {} for _, item in ipairs(items) do - local score = system.fuzzy_match(tostring(item), needle) + local score = system.fuzzy_match(tostring(item), needle, files) if score then table.insert(res, { text = item, score = score }) end @@ -74,11 +74,11 @@ local function fuzzy_match_items(items, needle) end -function common.fuzzy_match(haystack, needle) +function common.fuzzy_match(haystack, needle, files) if type(haystack) == "table" then - return fuzzy_match_items(haystack, needle) + return fuzzy_match_items(haystack, needle, files) end - return system.fuzzy_match(haystack, needle) + return system.fuzzy_match(haystack, needle, files) end @@ -86,16 +86,16 @@ function common.fuzzy_match_with_recents(haystack, recents, needle) if needle == "" then local recents_ext = {} for i = 2, #recents do - table.insert(recents_ext, recents[i]) + table.insert(recents_ext, recents[i]) end table.insert(recents_ext, recents[1]) - local others = common.fuzzy_match(haystack, "") + local others = common.fuzzy_match(haystack, "", true) for i = 1, #others do table.insert(recents_ext, others[i]) end return recents_ext else - return fuzzy_match_items(haystack, needle) + return fuzzy_match_items(haystack, needle, true) end end diff --git a/data/core/config.lua b/data/core/config.lua index f9b4e87f..74ca3d2f 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -11,6 +11,7 @@ config.symbol_pattern = "[%a_][%w_]*" config.non_word_chars = " \t\n/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-" config.undo_merge_timeout = 0.3 config.max_undos = 10000 +config.max_tabs = 10 config.highlight_current_line = true config.line_height = 1.2 config.indent_size = 2 diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 5664c08f..7cdc78cb 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -1,5 +1,6 @@ local core = require "core" local common = require "core.common" +local config = require "core.config" local style = require "core.style" local keymap = require "core.keymap" local Object = require "core.object" @@ -57,7 +58,12 @@ function Node:new(type) if self.type == "leaf" then self:add_view(EmptyView()) end + self.hovered = {x = -1, y = -1 } self.hovered_close = 0 + self.tab_shift = 0 + self.tab_offset = 1 + self.tab_width = style.tab_width + self.move_towards = View.move_towards end @@ -68,9 +74,8 @@ end function Node:on_mouse_moved(x, y, ...) - self.hovered_tab = self:get_tab_overlapping_point(x, y) if self.type == "leaf" then - self:tab_mouse_moved(x, y) + self.hovered.x, self.hovered.y = x, y self.active_view:on_mouse_moved(x, y, ...) else self:propagate("on_mouse_moved", x, y, ...) @@ -219,6 +224,15 @@ function Node:get_children(t) end +-- return the width including the padding space and separately +-- the padding space itself +local function get_scroll_button_width() + local w = style.icon_font:get_width(">") + local pad = w + return w + 2 * pad, pad +end + + function Node:get_divider_overlapping_point(px, py) if self.type ~= "leaf" then local p = 6 @@ -234,11 +248,18 @@ function Node:get_divider_overlapping_point(px, py) end +function Node:get_visible_tabs_number() + return math.min(#self.views - self.tab_offset + 1, config.max_tabs) +end + + function Node:get_tab_overlapping_point(px, py) if #self.views == 1 then return nil end - local x, y, w, h = self:get_tab_rect(1) - if px >= x and py >= y and px < x + w * #self.views and py < y + h then - return math.floor((px - x) / w) + 1 + local tabs_number = self:get_visible_tabs_number() + local x1, y1, w, h = self:get_tab_rect(self.tab_offset) + local x2, y2 = self:get_tab_rect(self.tab_offset + tabs_number) + if px >= x1 and py >= y1 and px < x2 and py < y1 + h then + return math.floor((px - x1) / w) + self.tab_offset end end @@ -250,17 +271,30 @@ local function close_button_location(x, w) end -function Node:tab_mouse_moved(px, py) +function Node:get_scroll_button_index(px, py) + for i = 1, 2 do + local x, y, w, h = self:get_scroll_button_rect(i) + if px >= x and px < x + w and py >= y and py < y + h then + return i + end + end +end + + +function Node:tab_hovered_update(px, py) local tab_index = self:get_tab_overlapping_point(px, py) + self.hovered_tab = tab_index + self.hovered_close = 0 + self.hovered_scroll_button = 0 if tab_index then local x, y, w, h = self:get_tab_rect(tab_index) local cx, cw = close_button_location(x, w) if px >= cx and px < cx + cw and py >= y and py < y + h then self.hovered_close = tab_index - return end + else + self.hovered_scroll_button = self:get_scroll_button_index(px, py) or 0 end - self.hovered_close = 0 end @@ -277,10 +311,22 @@ function Node:get_child_overlapping_point(x, y) end -function Node:get_tab_rect(idx) - local tw = math.min(style.tab_width, math.ceil(self.size.x / #self.views)) +function Node:get_scroll_button_rect(index) + local w, pad = get_scroll_button_width() local h = style.font:get_height() + style.padding.y * 2 - return self.position.x + (idx-1) * tw, self.position.y, tw, h + local x = self.position.x + (index == 1 and 0 or self.size.x - w) + return x, self.position.y, w, h, pad +end + + +function Node:get_tab_rect(idx) + local sbw = get_scroll_button_width() + local maxw = self.size.x - 2 * sbw + local x0 = self.position.x + sbw + local x1 = x0 + common.clamp(self.tab_width * (idx - 1) - self.tab_shift, 0, maxw) + local x2 = x0 + common.clamp(self.tab_width * idx - self.tab_shift, 0, maxw) + local h = style.font:get_height() + style.padding.y * 2 + return x1, self.position.y, x2 - x1, h end @@ -381,11 +427,61 @@ function Node:update_layout() end +function Node:scroll_tabs_to_visible() + local index = self:get_view_idx(self.active_view) + if index then + local tabs_number = self:get_visible_tabs_number() + if self.tab_offset > index then + self.tab_offset = index + elseif self.tab_offset + tabs_number - 1 < index then + self.tab_offset = index - tabs_number + 1 + elseif tabs_number < config.max_tabs and self.tab_offset > 1 then + self.tab_offset = #self.views - config.max_tabs + 1 + end + end +end + + +function Node:scroll_tabs(dir) + local view_index = self:get_view_idx(self.active_view) + if dir == 1 then + if self.tab_offset > 1 then + self.tab_offset = self.tab_offset - 1 + local last_index = self.tab_offset + self:get_visible_tabs_number() - 1 + if view_index > last_index then + self:set_active_view(self.views[last_index]) + end + end + elseif dir == 2 then + local tabs_number = self:get_visible_tabs_number() + if self.tab_offset + tabs_number - 1 < #self.views then + self.tab_offset = self.tab_offset + 1 + local view_index = self:get_view_idx(self.active_view) + if view_index < self.tab_offset then + self:set_active_view(self.views[self.tab_offset]) + end + end + end +end + + +function Node:target_tab_width() + local n = self:get_visible_tabs_number() + local w = self.size.x - get_scroll_button_width() * 2 + return common.clamp(style.tab_width, w / config.max_tabs, w / n) +end + + function Node:update() if self.type == "leaf" then + self:scroll_tabs_to_visible() for _, view in ipairs(self.views) do view:update() end + self:tab_hovered_update(self.hovered.x, self.hovered.y) + local tab_width = self:target_tab_width() + self:move_towards("tab_shift", tab_width * (self.tab_offset - 1)) + self:move_towards("tab_width", tab_width) else self.a:update() self.b:update() @@ -394,13 +490,27 @@ end function Node:draw_tabs() - local x, y, _, h = self:get_tab_rect(1) + local x, y, w, h, scroll_padding = self:get_scroll_button_rect(1) local ds = style.divider_size + local dots_width = style.font:get_width("…") core.push_clip_rect(x, y, self.size.x, h) renderer.draw_rect(x, y, self.size.x, h, style.background2) renderer.draw_rect(x, y + h - ds, self.size.x, ds, style.divider) - for i, view in ipairs(self.views) do + if self.tab_offset > 1 then + local button_style = self.hovered_scroll_button == 1 and style.text or style.dim + common.draw_text(style.icon_font, button_style, "<", nil, x + scroll_padding, y, 0, h) + end + + local tabs_number = self:get_visible_tabs_number() + if #self.views > self.tab_offset + tabs_number - 1 then + local xrb, yrb, wrb = self:get_scroll_button_rect(2) + local button_style = self.hovered_scroll_button == 2 and style.text or style.dim + common.draw_text(style.icon_font, button_style, ">", nil, xrb + scroll_padding, yrb, 0, h) + end + + for i = self.tab_offset, self.tab_offset + tabs_number - 1 do + local view = self.views[i] local x, y, w, h = self:get_tab_rect(i) local text = view:get_name() local color = style.dim @@ -422,9 +532,25 @@ function Node:draw_tabs() color = style.text end local padx = style.padding.x - core.push_clip_rect(x, y, show_close_button and cx - x - cspace or w - padx, h) + -- Normally we should substract "cspace" from text_avail_width and from the + -- clipping width. It is the padding space we give to the left and right of the + -- close button. However, since we are using dots to terminate filenames, we + -- choose to ignore "cspace" accepting that the text can possibly "touch" the + -- close button. + local text_avail_width = cx - x - padx + core.push_clip_rect(x, y, cx - x, h) x, w = x + padx, w - padx * 2 - local align = style.font:get_width(text) > w and "left" or "center" + local align = "center" + if style.font:get_width(text) > text_avail_width then + align = "left" + for i = 1, #text do + local reduced_text = text:sub(1, #text - i) + if style.font:get_width(reduced_text) + dots_width <= text_avail_width then + text = reduced_text .. "…" + break + end + end + end common.draw_text(style.font, color, text, align, x, y, w, h) core.pop_clip_rect() end @@ -613,6 +739,10 @@ function RootView:on_mouse_pressed(button, x, y, clicks) return end local node = self.root_node:get_child_overlapping_point(x, y) + if node.hovered_scroll_button > 0 then + node:scroll_tabs(node.hovered_scroll_button) + return + end local idx = node:get_tab_overlapping_point(x, y) if idx then if button == "middle" or node.hovered_close == idx then @@ -676,7 +806,9 @@ function RootView:on_mouse_moved(x, y, dx, dy) local node = self.root_node:get_child_overlapping_point(x, y) local div = self.root_node:get_divider_overlapping_point(x, y) local tab_index = node and node:get_tab_overlapping_point(x, y) - if div then + if node and node:get_scroll_button_index(x, y) then + system.set_cursor("arrow") + elseif div then local axis = (div.type == "hsplit" and "x" or "y") if div.a:is_resizable(axis) and div.b:is_resizable(axis) then system.set_cursor(div.type == "hsplit" and "sizeh" or "sizev") diff --git a/data/core/tokenizer.lua b/data/core/tokenizer.lua index f3070995..6d51928c 100644 --- a/data/core/tokenizer.lua +++ b/data/core/tokenizer.lua @@ -15,6 +15,39 @@ local function push_token(t, type, text) end +local function push_tokens(t, syn, pattern, full_text, find_results) + if #find_results > 2 then + -- We do some manipulation with find_results so that it's arranged + -- like this: + -- { start, end, i_1, i_2, i_3, …, i_last } + -- Each position spans characters from i_n to ((i_n+1) - 1), to form + -- consecutive spans of text. + -- + -- If i_1 is not equal to start, start is automatically inserted at + -- that index. + if find_results[3] ~= find_results[1] then + table.insert(find_results, 3, find_results[1]) + end + -- Copy the ending index to the end of the table, so that an ending index + -- always follows a starting index after position 3 in the table. + table.insert(find_results, find_results[2] + 1) + -- Then, we just iterate over our modified table. + for i = 3, #find_results - 1 do + local start = find_results[i] + local fin = find_results[i + 1] - 1 + local type = pattern.type[i - 2] + -- ↑ (i - 2) to convert from [3; n] to [1; n] + local text = full_text:sub(start, fin) + push_token(t, syn.symbols[text] or type, text) + end + else + local start, fin = find_results[1], find_results[2] + local text = full_text:sub(start, fin) + push_token(t, syn.symbols[text] or pattern.type, text) + end +end + + local function is_escaped(text, idx, esc) local byte = esc:byte() local count = 0 @@ -38,23 +71,23 @@ local function find_non_escaped(text, pattern, offset, esc) end end --- State is a 32-bit number that is four separate bytes, illustrating how many --- differnet delimiters we have open, and which subsyntaxes we have active. --- At most, there are 3 subsyntaxes active at the same time. Beyond that, +-- State is a 32-bit number that is four separate bytes, illustrating how many +-- differnet delimiters we have open, and which subsyntaxes we have active. +-- At most, there are 3 subsyntaxes active at the same time. Beyond that, -- does not support further highlighting. local function retrieve_syntax_state(incoming_syntax, state) - local current_syntax, subsyntax_info, current_state, current_level = + local current_syntax, subsyntax_info, current_state, current_level = incoming_syntax, nil, state, 0 if state > 0 and (state > 255 or current_syntax.patterns[state].syntax) then - -- If we have higher bits, then decode them one at a time, and find which - -- syntax we're using. Rather than walking the bytes, and calling into + -- If we have higher bits, then decode them one at a time, and find which + -- syntax we're using. Rather than walking the bytes, and calling into -- `syntax` each time, we could probably cache this in a single table. - for i=0,2 do + for i = 0, 2 do local target = bit32.extract(state, i*8, 8) if target ~= 0 then if current_syntax.patterns[target].syntax then subsyntax_info = current_syntax.patterns[target] - current_syntax = type(subsyntax_info.syntax) == "table" and + current_syntax = type(subsyntax_info.syntax) == "table" and subsyntax_info.syntax or syntax.get(subsyntax_info.syntax) current_state = 0 current_level = i+1 @@ -62,7 +95,7 @@ local function retrieve_syntax_state(incoming_syntax, state) current_state = target break end - else + else break end end @@ -77,28 +110,28 @@ function tokenizer.tokenize(incoming_syntax, text, state) if #incoming_syntax.patterns == 0 then return { "normal", text } end - + state = state or 0 - local current_syntax, subsyntax_info, current_state, current_level = + local current_syntax, subsyntax_info, current_state, current_level = retrieve_syntax_state(incoming_syntax, state) while i <= #text do -- continue trying to match the end pattern of a pair if we have a state set if current_state > 0 then local p = current_syntax.patterns[current_state] local s, e = find_non_escaped(text, p.pattern[2], i, p.pattern[3]) - + local cont = true -- If we're in subsyntax mode, always check to see if we end our syntax -- first. if subsyntax_info then local ss, se = find_non_escaped( - text, - subsyntax_info.pattern[2], - i, - subsyntax_info.pattern[3] - ) + text, + subsyntax_info.pattern[2], + i, + subsyntax_info.pattern[3] + ) if ss and (s == nil or ss < s) then - push_token(res, p.type, text:sub(i, ss - 1)) + push_token(res, p.type, text:sub(i, ss - 1)) i = ss cont = false end @@ -118,17 +151,17 @@ function tokenizer.tokenize(incoming_syntax, text, state) -- Check for end of syntax. if subsyntax_info then local s, e = find_non_escaped( - text, - "^" .. subsyntax_info.pattern[2], - i, - nil + text, + "^" .. subsyntax_info.pattern[2], + i, + nil ) if s then push_token(res, subsyntax_info.type, text:sub(i, e)) current_level = current_level - 1 -- Zero out the state above us, as well as our new current state. state = bit32.replace(state, 0, current_level*8, 16) - current_syntax, subsyntax_info, current_state, current_level = + current_syntax, subsyntax_info, current_state, current_level = retrieve_syntax_state(incoming_syntax, state) i = e + 1 end @@ -138,31 +171,31 @@ function tokenizer.tokenize(incoming_syntax, text, state) local matched = false for n, p in ipairs(current_syntax.patterns) do local pattern = (type(p.pattern) == "table") and p.pattern[1] or p.pattern - local s, e = text:find("^" .. pattern, i) + local find_results = { text:find("^" .. pattern, i) } + local start, fin = find_results[1], find_results[2] + + if start then + -- matched pattern; make and add tokens + push_tokens(res, current_syntax, p, text, find_results) - if s then - -- matched pattern; make and add token - local t = text:sub(s, e) - - push_token(res, current_syntax.symbols[t] or p.type, t) -- update state if this was a start|end pattern pair if type(p.pattern) == "table" then state = bit32.replace(state, n, current_level*8, 8) - -- If we've found a new subsyntax, bump our level, and set the - -- appropriate variables. + -- If we've found a new subsyntax, bump our level, and set the + -- appropriate variables. if p.syntax then current_level = current_level + 1 subsyntax_info = p - current_syntax = type(p.syntax) == "table" and - p.syntax or syntax.get(p.syntax) + current_syntax = type(p.syntax) == "table" and + p.syntax or syntax.get(p.syntax) current_state = 0 - else + else current_state = n end end -- move cursor past this token - i = e + 1 + i = fin + 1 matched = true break end diff --git a/data/fonts/icons.ttf b/data/fonts/icons.ttf index 00b4cc3b..43ab3767 100644 Binary files a/data/fonts/icons.ttf and b/data/fonts/icons.ttf differ diff --git a/data/plugins/detectindent.lua b/data/plugins/detectindent.lua index 681dce26..63fe8a52 100644 --- a/data/plugins/detectindent.lua +++ b/data/plugins/detectindent.lua @@ -102,21 +102,28 @@ end local doc_on_text_change = Doc.on_text_change local adjust_threshold = 4 +local current_on_text_change = nil + local function update_cache(doc) local type, size, score = detect_indent_stat(doc) cache[doc] = { type = type, size = size, confirmed = (score >= adjust_threshold) } doc.indent_info = cache[doc] if score < adjust_threshold and doc_on_text_change then - Doc.on_text_change = function(self, ...) - doc_on_text_change(self, ...) + current_on_text_change = function(self, ...) update_cache(self) end elseif score >= adjust_threshold and doc_on_text_change then - Doc.on_text_change = doc_on_text_change - doc_on_text_change = nil + current_on_text_change = nil end end +function Doc.on_text_change(...) + if current_on_text_change then + current_on_text_change(...) + end + doc_on_text_change(...) +end + local new = Doc.new function Doc:new(...) diff --git a/data/plugins/language_c.lua b/data/plugins/language_c.lua index eb776a1b..c05d69e6 100644 --- a/data/plugins/language_c.lua +++ b/data/plugins/language_c.lua @@ -5,16 +5,20 @@ syntax.add { files = { "%.c$", "%.h$", "%.inl$", "%.cpp$", "%.hpp$" }, comment = "//", patterns = { - { pattern = "//.-\n", type = "comment" }, - { pattern = { "/%*", "%*/" }, type = "comment" }, - { pattern = { '"', '"', '\\' }, type = "string" }, - { pattern = { "'", "'", '\\' }, type = "string" }, - { pattern = "-?0x%x+", type = "number" }, - { pattern = "-?%d+[%d%.eE]*f?", type = "number" }, - { pattern = "-?%.?%d+f?", type = "number" }, - { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, - { pattern = "[%a_][%w_]*%f[(]", type = "function" }, - { pattern = "#?[%a_][%w_]*", type = "symbol" }, + { pattern = "//.-\n", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = "0x%x+", type = "number" }, + { pattern = "%d+[%d%.eE]*f?", type = "number" }, + { pattern = "%.?%d+f?", type = "number" }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "[%a_][%w_]*%f[(]", type = "function" }, + { pattern = "[%a_][%w_]*", type = "symbol" }, + { pattern = "#include%s()<.->", type = {"keyword", "string"} }, + { pattern = "#[%a_][%w_]*", type = "keyword" }, }, symbols = { ["if"] = "keyword", @@ -28,8 +32,6 @@ syntax.add { ["continue"] = "keyword", ["return"] = "keyword", ["goto"] = "keyword", - ["struct"] = "keyword2", - ["union"] = "keyword", ["typedef"] = "keyword", ["enum"] = "keyword", ["extern"] = "keyword", @@ -41,7 +43,6 @@ syntax.add { ["case"] = "keyword", ["default"] = "keyword", ["auto"] = "keyword", - ["const"] = "keyword", ["void"] = "keyword", ["int"] = "keyword2", ["short"] = "keyword2", diff --git a/data/plugins/language_js.lua b/data/plugins/language_js.lua index a258bb3c..671e1bd8 100644 --- a/data/plugins/language_js.lua +++ b/data/plugins/language_js.lua @@ -7,7 +7,7 @@ syntax.add { patterns = { { pattern = "//.-\n", type = "comment" }, { pattern = { "/%*", "%*/" }, type = "comment" }, - { pattern = { '/', '/', '\\' }, type = "string" }, + { pattern = { '/%g', '/', '\\' }, type = "string" }, { pattern = { '"', '"', '\\' }, type = "string" }, { pattern = { "'", "'", '\\' }, type = "string" }, { pattern = { "`", "`", '\\' }, type = "string" }, @@ -41,6 +41,7 @@ syntax.add { ["if"] = "keyword", ["import"] = "keyword", ["in"] = "keyword", + ["of"] = "keyword", ["instanceof"] = "keyword", ["let"] = "keyword", ["new"] = "keyword", diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index e4d10fb3..9b9c34b3 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -30,7 +30,10 @@ local function find_all_matches_in_file(t, filename, fn) for line in fp:lines() do local s = fn(line) if s then - table.insert(t, { file = filename, text = line, line = n, col = s }) + -- Insert maximum 256 characters. If we insert more, for compiled files, which can have very long lines + -- things tend to get sluggish. If our line is longer than 80 characters, begin to truncate the thing. + local start_index = math.max(s - 80, 1) + table.insert(t, { file = filename, text = (start_index > 1 and "..." or "") .. line:sub(start_index, 256 + start_index), line = n, col = s }) core.redraw = true end if n % 100 == 0 then coroutine.yield() end @@ -268,12 +271,38 @@ command.add(ResultsView, { ["project-search:refresh"] = function() core.active_view:refresh() end, + + ["project-search:move-to-previous-page"] = function() + local view = core.active_view + view.scroll.to.y = view.scroll.to.y - view.size.y + end, + + ["project-search:move-to-next-page"] = function() + local view = core.active_view + view.scroll.to.y = view.scroll.to.y + view.size.y + end, + + ["project-search:move-to-start-of-doc"] = function() + local view = core.active_view + view.scroll.to.y = 0 + end, + + ["project-search:move-to-end-of-doc"] = function() + local view = core.active_view + view.scroll.to.y = view:get_scrollable_size() + end }) keymap.add { - ["f5"] = "project-search:refresh", - ["ctrl+shift+f"] = "project-search:find", - ["up"] = "project-search:select-previous", - ["down"] = "project-search:select-next", - ["return"] = "project-search:open-selected", + ["f5"] = "project-search:refresh", + ["ctrl+shift+f"] = "project-search:find", + ["up"] = "project-search:select-previous", + ["down"] = "project-search:select-next", + ["return"] = "project-search:open-selected", + ["pageup"] = "project-search:move-to-previous-page", + ["pagedown"] = "project-search:move-to-next-page", + ["ctrl+home"] = "project-search:move-to-start-of-doc", + ["ctrl+end"] = "project-search:move-to-end-of-doc", + ["home"] = "project-search:move-to-start-of-doc", + ["end"] = "project-search:move-to-end-of-doc" } diff --git a/dev-utils/Info.plist b/dev-utils/Info.plist index 76c7efda..75591560 100644 --- a/dev-utils/Info.plist +++ b/dev-utils/Info.plist @@ -14,6 +14,7 @@ APPL NSHighResolutionCapable + MinimumOSVersion10.13 CFBundleShortVersionString 1.16.5 NSHumanReadableCopyright diff --git a/dev-utils/fontello-config-small.json b/dev-utils/fontello-config-small.json deleted file mode 100644 index 895de303..00000000 --- a/dev-utils/fontello-config-small.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "name": "icons", - "css_prefix_text": "icon-", - "css_use_suffix": false, - "hinting": true, - "units_per_em": 1000, - "ascent": 850, - "glyphs": [ - { - "uid": "9dd9e835aebe1060ba7190ad2b2ed951", - "css": "search-1", - "code": 76, - "src": "fontawesome" - }, - { - "uid": "c76b7947c957c9b78b11741173c8349b", - "css": "attention-1", - "code": 33, - "src": "fontawesome" - }, - { - "uid": "1b5a5d7b7e3c71437f5a26befdd045ed", - "css": "doc-1", - "code": 102, - "src": "fontawesome" - }, - { - "uid": "f8aa663c489bcbd6e68ec8147dca841e", - "css": "folder-1", - "code": 100, - "src": "fontawesome" - }, - { - "uid": "c95735c17a10af81448c7fed98a04546", - "css": "folder-open-1", - "code": 68, - "src": "fontawesome" - }, - { - "uid": "e99461abfef3923546da8d745372c995", - "css": "cog", - "code": 80, - "src": "fontawesome" - }, - { - "uid": "7bf14281af5633a597f85b061ef1cfb9", - "css": "angle-right", - "code": 43, - "src": "fontawesome" - }, - { - "uid": "e4dde1992f787163e2e2b534b8c8067d", - "css": "angle-down", - "code": 45, - "src": "fontawesome" - }, - { - "uid": "ea2d9a8c51ca42b38ef0d2a07f16d9a7", - "css": "chart-line", - "code": 103, - "src": "fontawesome" - }, - { - "uid": "f4445feb55521283572ee88bc304f928", - "css": "floppy", - "code": 83, - "src": "fontawesome" - }, - { - "uid": "9755f76110ae4d12ac5f9466c9152031", - "css": "book", - "code": 66, - "src": "fontawesome" - }, - { - "uid": "e82cedfa1d5f15b00c5a81c9bd731ea2", - "css": "info-circled-1", - "code": 105, - "src": "fontawesome" - }, - { - "uid": "5211af474d3a9848f67f945e2ccaf143", - "css": "cancel-1", - "code": 67, - "src": "fontawesome" - }, - { - "uid": "04f022b8bd044d4ccfffd3887ff72088", - "css": "window-minimize", - "code": 95, - "src": "fontawesome" - }, - { - "uid": "d0e62145dbf40f30e47b3819b8b43a8f", - "css": "window-restore", - "code": 119, - "src": "fontawesome" - }, - { - "uid": "7394501fc0b17cb7bda99538f92e26d6", - "css": "window-close", - "code": 88, - "src": "fontawesome" - }, - { - "uid": "559647a6f430b3aeadbecd67194451dd", - "css": "menu-1", - "code": 77, - "src": "fontawesome" - }, - { - "uid": "07f0832c07f3d9713fffb06c8bffa027", - "css": "window-maximize", - "code": 87, - "src": "fontawesome" - } - ] -} \ No newline at end of file diff --git a/dev-utils/fontello-config.json b/dev-utils/fontello-config.json index 9dd4681d..42334c2f 100644 --- a/dev-utils/fontello-config.json +++ b/dev-utils/fontello-config.json @@ -1,5 +1,5 @@ { - "name": "", + "name": "icons", "css_prefix_text": "icon-", "css_use_suffix": false, "hinting": true, @@ -12,234 +12,18 @@ "code": 76, "src": "fontawesome" }, - { - "uid": "12f4ece88e46abd864e40b35e05b11cd", - "css": "ok-1", - "code": 59402, - "src": "fontawesome" - }, - { - "uid": "43ab845088317bd348dee1d975700c48", - "css": "ok-circled-1", - "code": 59403, - "src": "fontawesome" - }, - { - "uid": "ad33e708f4d2e25c5056c931da1528d6", - "css": "ok-circled2", - "code": 59405, - "src": "fontawesome" - }, - { - "uid": "1400d5103edd2fa6d2d61688fee79a5a", - "css": "ok-squared", - "code": 61770, - "src": "fontawesome" - }, - { - "uid": "5211af474d3a9848f67f945e2ccaf143", - "css": "cancel-1", - "code": 67, - "src": "fontawesome" - }, - { - "uid": "0f4cae16f34ae243a6144c18a003f2d8", - "css": "cancel-circled-1", - "code": 99, - "src": "fontawesome" - }, - { - "uid": "d7271d490b71df4311e32cdacae8b331", - "css": "home-1", - "code": 59407, - "src": "fontawesome" - }, - { - "uid": "3d4ea8a78dc34efe891f3a0f3d961274", - "css": "info", - "code": 61737, - "src": "fontawesome" - }, - { - "uid": "ce3cf091d6ebd004dd0b52d24074e6e3", - "css": "help", - "code": 61736, - "src": "fontawesome" - }, - { - "uid": "17ebadd1e3f274ff0205601eef7b9cc4", - "css": "help-circled-1", - "code": 59408, - "src": "fontawesome" - }, - { - "uid": "e82cedfa1d5f15b00c5a81c9bd731ea2", - "css": "info-circled-1", - "code": 59409, - "src": "fontawesome" - }, - { - "uid": "c1f1975c885aa9f3dad7810c53b82074", - "css": "lock", - "code": 59410, - "src": "fontawesome" - }, - { - "uid": "657ab647f6248a6b57a5b893beaf35a9", - "css": "lock-open-1", - "code": 59411, - "src": "fontawesome" - }, - { - "uid": "05376be04a27d5a46e855a233d6e8508", - "css": "lock-open-alt-1", - "code": 61758, - "src": "fontawesome" - }, - { - "uid": "3db5347bd219f3bce6025780f5d9ef45", - "css": "tag", - "code": 59412, - "src": "fontawesome" - }, - { - "uid": "a3f89e106175a5c5c4e9738870b12e55", - "css": "tags", - "code": 59413, - "src": "fontawesome" - }, - { - "uid": "7034e4d22866af82bef811f52fb1ba46", - "css": "code", - "code": 61729, - "src": "fontawesome" - }, - { - "uid": "d35a1d35efeb784d1dc9ac18b9b6c2b6", - "css": "pencil-1", - "code": 59414, - "src": "fontawesome" - }, - { - "uid": "44fae3bfdd54754dc68ec50d37efea37", - "css": "pencil-squared", - "code": 61771, - "src": "fontawesome" - }, - { - "uid": "41087bc74d4b20b55059c60a33bf4008", - "css": "edit", - "code": 59415, - "src": "fontawesome" - }, - { - "uid": "ecb97add13804c190456025e43ec003b", - "css": "keyboard", - "code": 61724, - "src": "fontawesome" - }, { "uid": "c76b7947c957c9b78b11741173c8349b", "css": "attention-1", "code": 33, "src": "fontawesome" }, - { - "uid": "00391fac5d419345ffcccd95b6f76263", - "css": "attention-alt-1", - "code": 61738, - "src": "fontawesome" - }, - { - "uid": "b035c28eba2b35c6ffe92aee8b0df507", - "css": "attention-circled", - "code": 59417, - "src": "fontawesome" - }, - { - "uid": "f48ae54adfb27d8ada53d0fd9e34ee10", - "css": "trash-empty", - "code": 59418, - "src": "fontawesome" - }, { "uid": "1b5a5d7b7e3c71437f5a26befdd045ed", "css": "doc-1", "code": 102, "src": "fontawesome" }, - { - "uid": "c8585e1e5b0467f28b70bce765d5840c", - "css": "docs", - "code": 61637, - "src": "fontawesome" - }, - { - "uid": "5408be43f7c42bccee419c6be53fdef5", - "css": "doc-text", - "code": 61686, - "src": "fontawesome" - }, - { - "uid": "178053298e3e5b03551d754d4b9acd8b", - "css": "doc-inv", - "code": 61787, - "src": "fontawesome" - }, - { - "uid": "c08a1cde48d96cba21d8c05fa7d7feb1", - "css": "doc-text-inv", - "code": 61788, - "src": "fontawesome" - }, - { - "uid": "9daa1fdf0838118518a7e22715e83abc", - "css": "file-pdf", - "code": 61889, - "src": "fontawesome" - }, - { - "uid": "310ffd629da85142bc8669f010556f2d", - "css": "file-word", - "code": 61890, - "src": "fontawesome" - }, - { - "uid": "edcd4022de8d8df266ef7c42d2658ca5", - "css": "file-powerpoint", - "code": 61892, - "src": "fontawesome" - }, - { - "uid": "3c961c1a8d874815856fc6637dc5a13c", - "css": "file-image", - "code": 61893, - "src": "fontawesome" - }, - { - "uid": "e80ae555c1413a4ec18b33fb348b4049", - "css": "file-archive", - "code": 61894, - "src": "fontawesome" - }, - { - "uid": "81db033e704eb7c586a365559d7c0f36", - "css": "file-audio", - "code": 61895, - "src": "fontawesome" - }, - { - "uid": "dd69d9aa589ea7bc0a82a3fe67039f4b", - "css": "file-video", - "code": 61896, - "src": "fontawesome" - }, - { - "uid": "26613a2e6bc41593c54bead46f8c8ee3", - "css": "file-code", - "code": 61897, - "src": "fontawesome" - }, { "uid": "f8aa663c489bcbd6e68ec8147dca841e", "css": "folder-1", @@ -252,58 +36,10 @@ "code": 68, "src": "fontawesome" }, - { - "uid": "b091a8bd0fdade174951f17d936f51e4", - "css": "folder-empty-1", - "code": 61716, - "src": "fontawesome" - }, - { - "uid": "6533bdc16ab201eb3f3b27ce989cab33", - "css": "folder-open-empty-1", - "code": 61717, - "src": "fontawesome" - }, - { - "uid": "559647a6f430b3aeadbecd67194451dd", - "css": "menu-1", - "code": 61641, - "src": "fontawesome" - }, { "uid": "e99461abfef3923546da8d745372c995", "css": "cog", - "code": 59422, - "src": "fontawesome" - }, - { - "uid": "98687378abd1faf8f6af97c254eb6cd6", - "css": "cog-alt", - "code": 59423, - "src": "fontawesome" - }, - { - "uid": "5bb103cd29de77e0e06a52638527b575", - "css": "wrench", - "code": 59424, - "src": "fontawesome" - }, - { - "uid": "0b2b66e526028a6972d51a6f10281b4b", - "css": "zoom-in", - "code": 59425, - "src": "fontawesome" - }, - { - "uid": "d25d10efa900f529ad1d275657cfd30e", - "css": "zoom-out", - "code": 59426, - "src": "fontawesome" - }, - { - "uid": "f3f90c8c89795da30f7444634476ea4f", - "css": "angle-left", - "code": 61700, + "code": 80, "src": "fontawesome" }, { @@ -312,24 +48,12 @@ "code": 43, "src": "fontawesome" }, - { - "uid": "5de9370846a26947e03f63142a3f1c07", - "css": "angle-up", - "code": 61701, - "src": "fontawesome" - }, { "uid": "e4dde1992f787163e2e2b534b8c8067d", "css": "angle-down", "code": 45, "src": "fontawesome" }, - { - "uid": "bbfb51903f40597f0b70fd75bc7b5cac", - "css": "trash", - "code": 61944, - "src": "fontawesome" - }, { "uid": "ea2d9a8c51ca42b38ef0d2a07f16d9a7", "css": "chart-line", @@ -342,106 +66,64 @@ "code": 83, "src": "fontawesome" }, - { - "uid": "b429436ec5a518c78479d44ef18dbd60", - "css": "paste", - "code": 61674, - "src": "fontawesome" - }, - { - "uid": "8772331a9fec983cdb5d72902a6f9e0e", - "css": "scissors", - "code": 59428, - "src": "fontawesome" - }, { "uid": "9755f76110ae4d12ac5f9466c9152031", "css": "book", - "code": 59429, + "code": 66, "src": "fontawesome" }, { - "uid": "f9cbf7508cd04145ade2800169959eef", - "css": "font", - "code": 59430, + "uid": "e82cedfa1d5f15b00c5a81c9bd731ea2", + "css": "info-circled-1", + "code": 105, "src": "fontawesome" }, { - "uid": "d3b3f17bc3eb7cd809a07bbd4d178bee", - "css": "resize-vertical", - "code": 59431, + "uid": "5211af474d3a9848f67f945e2ccaf143", + "css": "cancel-1", + "code": 67, "src": "fontawesome" }, { - "uid": "3c73d058e4589b65a8d959c0fc8f153d", - "css": "resize-horizontal", - "code": 59432, + "uid": "04f022b8bd044d4ccfffd3887ff72088", + "css": "window-minimize", + "code": 95, "src": "fontawesome" }, { - "uid": "e594fc6e5870b4ab7e49f52571d52577", - "css": "resize-full", - "code": 59433, + "uid": "d0e62145dbf40f30e47b3819b8b43a8f", + "css": "window-restore", + "code": 119, "src": "fontawesome" }, { - "uid": "5278ef7773e948d56c4d442c8c8c98cf", - "css": "lightbulb", - "code": 61675, + "uid": "7394501fc0b17cb7bda99538f92e26d6", + "css": "window-close", + "code": 88, "src": "fontawesome" }, { - "uid": "598a5f2bcf3521d1615de8e1881ccd17", - "css": "clock", - "code": 59434, + "uid": "559647a6f430b3aeadbecd67194451dd", + "css": "menu-1", + "code": 77, "src": "fontawesome" }, { - "uid": "1c4068ed75209e21af36017df8871802", - "css": "down-big", - "code": 59435, + "uid": "07f0832c07f3d9713fffb06c8bffa027", + "css": "window-maximize", + "code": 87, "src": "fontawesome" }, { - "uid": "555ef8c86832e686fef85f7af2eb7cde", - "css": "left-big", - "code": 59436, + "uid": "d870630ff8f81e6de3958ecaeac532f2", + "css": "left-open", + "code": 60, "src": "fontawesome" }, { - "uid": "ad6b3fbb5324abe71a9c0b6609cbb9f1", - "css": "right-big", - "code": 59437, - "src": "fontawesome" - }, - { - "uid": "95376bf082bfec6ce06ea1cda7bd7ead", - "css": "up-big", - "code": 59438, - "src": "fontawesome" - }, - { - "uid": "107ce08c7231097c7447d8f4d059b55f", - "css": "ellipsis", - "code": 61761, - "src": "fontawesome" - }, - { - "uid": "750058837a91edae64b03d60fc7e81a7", - "css": "ellipsis-vert", - "code": 61762, - "src": "fontawesome" - }, - { - "uid": "8fb55fd696d9a0f58f3b27c1d8633750", - "css": "table", - "code": 61646, - "src": "fontawesome" - }, - { - "uid": "53dd31a6cc6438192b2d7b09b1c1dd45", - "css": "columns", - "code": 61659, + "uid": "399ef63b1e23ab1b761dfbb5591fa4da", + "css": "right-open", + "code": 62, "src": "fontawesome" } ] diff --git a/src/api/system.c b/src/api/system.c index 1b15a2ec..89c037c2 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -517,27 +517,54 @@ static int f_exec(lua_State *L) { static int f_fuzzy_match(lua_State *L) { - const char *str = luaL_checkstring(L, 1); - const char *ptn = luaL_checkstring(L, 2); + size_t strLen, ptnLen; + const char *str = luaL_checklstring(L, 1, &strLen); + const char *ptn = luaL_checklstring(L, 2, &ptnLen); + bool files = false; + if (lua_gettop(L) > 2 && lua_isboolean(L,3)) + files = lua_toboolean(L, 3); + int score = 0; int run = 0; - - while (*str && *ptn) { - while (*str == ' ') { str++; } - while (*ptn == ' ') { ptn++; } - if (tolower(*str) == tolower(*ptn)) { - score += run * 10 - (*str != *ptn); - run++; - ptn++; - } else { - score -= 10; - run = 0; + + // Match things *backwards*. This allows for better matching on filenames than the above + // function. For example, in the lite project, opening "renderer" has lib/font_render/build.sh + // as the first result, rather than src/renderer.c. Clearly that's wrong. + if (files) { + const char* strEnd = str + strLen - 1; + const char* ptnEnd = ptn + ptnLen - 1; + while (strEnd >= str && ptnEnd >= ptn) { + while (*strEnd == ' ') { strEnd--; } + while (*ptnEnd == ' ') { ptnEnd--; } + if (tolower(*strEnd) == tolower(*ptnEnd)) { + score += run * 10 - (*strEnd != *ptnEnd); + run++; + ptnEnd--; + } else { + score -= 10; + run = 0; + } + strEnd--; } - str++; + if (ptnEnd >= ptn) { return 0; } + } else { + while (*str && *ptn) { + while (*str == ' ') { str++; } + while (*ptn == ' ') { ptn++; } + if (tolower(*str) == tolower(*ptn)) { + score += run * 10 - (*str != *ptn); + run++; + ptn++; + } else { + score -= 10; + run = 0; + } + str++; + } + if (*ptn) { return 0; } } - if (*ptn) { return 0; } - lua_pushnumber(L, score - (int) strlen(str)); + lua_pushnumber(L, score - (int)strLen); return 1; }