Added in a hash check to the system clipboard.
This commit is contained in:
parent
3c8da0fc3f
commit
71e62ce84f
|
@ -53,6 +53,18 @@ local function save(filename)
|
||||||
core.log("Saved \"%s\"", saved_filename)
|
core.log("Saved \"%s\"", saved_filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function split_cursor(direction)
|
||||||
|
local new_cursors = {}
|
||||||
|
for _, line1, col1 in doc():get_selections() do
|
||||||
|
if line1 > 1 and line1 < #doc().lines then
|
||||||
|
table.insert(new_cursors, { line1 + direction, col1 })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i,v in ipairs(new_cursors) do doc():add_selection(v[1], v[2]) end
|
||||||
|
core.blink_reset()
|
||||||
|
end
|
||||||
|
|
||||||
local function cut_or_copy(delete)
|
local function cut_or_copy(delete)
|
||||||
local full_text = ""
|
local full_text = ""
|
||||||
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
||||||
|
@ -67,20 +79,12 @@ local function cut_or_copy(delete)
|
||||||
doc().cursor_clipboard[idx] = ""
|
doc().cursor_clipboard[idx] = ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if #doc().cursor_clipboard > 1 then
|
||||||
|
doc().cursor_clipboard["hash"] = system.hash(system.get_clipboard())
|
||||||
|
end
|
||||||
system.set_clipboard(full_text)
|
system.set_clipboard(full_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function split_cursor(direction)
|
|
||||||
local new_cursors = {}
|
|
||||||
for _, line1, col1 in doc():get_selections() do
|
|
||||||
if line1 > 1 and line1 < #doc().lines then
|
|
||||||
table.insert(new_cursors, { line1 + direction, col1 })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i,v in ipairs(new_cursors) do doc():add_selection(v[1], v[2]) end
|
|
||||||
core.blink_reset()
|
|
||||||
end
|
|
||||||
|
|
||||||
local commands = {
|
local commands = {
|
||||||
["doc:undo"] = function()
|
["doc:undo"] = function()
|
||||||
doc():undo()
|
doc():undo()
|
||||||
|
@ -99,8 +103,13 @@ local commands = {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:paste"] = function()
|
["doc:paste"] = function()
|
||||||
|
local clipboard = system.get_clipboard()
|
||||||
|
-- If the clipboard has changed since our last look, use that instead
|
||||||
|
if doc().cursor_clipboard["hash"] ~= system.hash(clipboard) then
|
||||||
|
doc().cursor_clipboard = {}
|
||||||
|
end
|
||||||
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
||||||
local value = doc().cursor_clipboard[idx] or system.get_clipboard()
|
local value = doc().cursor_clipboard[idx] or clipboard
|
||||||
doc():text_input(value:gsub("\r", ""), idx)
|
doc():text_input(value:gsub("\r", ""), idx)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -173,6 +173,7 @@ function Doc:merge_cursors(idx)
|
||||||
if self.selections[i] == self.selections[j] and
|
if self.selections[i] == self.selections[j] and
|
||||||
self.selections[i+1] == self.selections[j+1] then
|
self.selections[i+1] == self.selections[j+1] then
|
||||||
common.splice(self.selections, i, 4)
|
common.splice(self.selections, i, 4)
|
||||||
|
common.splice(self.cursor_clipboard, i, 1)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -637,6 +637,14 @@ static int f_set_window_opacity(lua_State *L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int f_hash(lua_State* L) {
|
||||||
|
unsigned i = RENCACHE_HASH_INITIAL;
|
||||||
|
size_t strLen;
|
||||||
|
const char *str = luaL_checklstring(L, 1, &strLen);
|
||||||
|
rencache_hash(&i, str, strLen) ;
|
||||||
|
lua_pushnumber(L, i);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static const luaL_Reg lib[] = {
|
static const luaL_Reg lib[] = {
|
||||||
{ "poll_event", f_poll_event },
|
{ "poll_event", f_poll_event },
|
||||||
|
@ -664,6 +672,7 @@ static const luaL_Reg lib[] = {
|
||||||
{ "exec", f_exec },
|
{ "exec", f_exec },
|
||||||
{ "fuzzy_match", f_fuzzy_match },
|
{ "fuzzy_match", f_fuzzy_match },
|
||||||
{ "set_window_opacity", f_set_window_opacity },
|
{ "set_window_opacity", f_set_window_opacity },
|
||||||
|
{ "hash", f_hash },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -83,10 +83,7 @@ static void font_refs_clear(lua_State *L) {
|
||||||
font_refs_len = 0;
|
font_refs_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 32bit fnv-1a hash */
|
void rencache_hash(unsigned *h, const void *data, int size) {
|
||||||
#define HASH_INITIAL 2166136261
|
|
||||||
|
|
||||||
static void hash(unsigned *h, const void *data, int size) {
|
|
||||||
const unsigned char *p = data;
|
const unsigned char *p = data;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
*h = (*h ^ *p++) * 16777619;
|
*h = (*h ^ *p++) * 16777619;
|
||||||
|
@ -227,7 +224,7 @@ static void update_overlapping_cells(RenRect r, unsigned h) {
|
||||||
for (int y = y1; y <= y2; y++) {
|
for (int y = y1; y <= y2; y++) {
|
||||||
for (int x = x1; x <= x2; x++) {
|
for (int x = x1; x <= x2; x++) {
|
||||||
int idx = cell_idx(x, y);
|
int idx = cell_idx(x, y);
|
||||||
hash(&cells[idx], &h, sizeof(h));
|
rencache_hash(&cells[idx], &h, sizeof(h));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,8 +252,8 @@ void rencache_end_frame(lua_State *L) {
|
||||||
if (cmd->type == SET_CLIP) { cr = cmd->rect; }
|
if (cmd->type == SET_CLIP) { cr = cmd->rect; }
|
||||||
RenRect r = intersect_rects(cmd->rect, cr);
|
RenRect r = intersect_rects(cmd->rect, cr);
|
||||||
if (r.width == 0 || r.height == 0) { continue; }
|
if (r.width == 0 || r.height == 0) { continue; }
|
||||||
unsigned h = HASH_INITIAL;
|
unsigned h = RENCACHE_HASH_INITIAL;
|
||||||
hash(&h, cmd, cmd->size);
|
rencache_hash(&h, cmd, cmd->size);
|
||||||
update_overlapping_cells(r, h);
|
update_overlapping_cells(r, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +268,7 @@ void rencache_end_frame(lua_State *L) {
|
||||||
if (cells[idx] != cells_prev[idx]) {
|
if (cells[idx] != cells_prev[idx]) {
|
||||||
push_rect((RenRect) { x, y, 1, 1 }, &rect_count);
|
push_rect((RenRect) { x, y, 1, 1 }, &rect_count);
|
||||||
}
|
}
|
||||||
cells_prev[idx] = HASH_INITIAL;
|
cells_prev[idx] = RENCACHE_HASH_INITIAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,12 @@
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
|
/* 32bit fnv-1a hash */
|
||||||
|
#define RENCACHE_HASH_INITIAL 2166136261
|
||||||
|
|
||||||
void rencache_show_debug(bool enable);
|
void rencache_show_debug(bool enable);
|
||||||
void rencache_set_clip_rect(RenRect rect);
|
void rencache_set_clip_rect(RenRect rect);
|
||||||
|
void rencache_hash(unsigned *h, const void *data, int size);
|
||||||
void rencache_draw_rect(RenRect rect, RenColor color);
|
void rencache_draw_rect(RenRect rect, RenColor color);
|
||||||
int rencache_draw_text(lua_State *L, FontDesc *font_desc, int font_index, const char *text, int x, int y, RenColor color,
|
int rencache_draw_text(lua_State *L, FontDesc *font_desc, int font_index, const char *text, int x, int y, RenColor color,
|
||||||
bool draw_subpixel, CPReplaceTable *replacements, RenColor replace_color);
|
bool draw_subpixel, CPReplaceTable *replacements, RenColor replace_color);
|
||||||
|
|
Loading…
Reference in New Issue