Merge branch 'master' into dev

This commit is contained in:
jgmdev 2021-06-12 23:11:35 -04:00
commit 5d95d604a9
5 changed files with 71 additions and 53 deletions

View File

@ -982,26 +982,18 @@ end
function core.step() function core.step()
-- handle events -- handle events
local did_keymap = false local did_keymap = false
local mouse_moved = false
local mouse = { x = 0, y = 0, dx = 0, dy = 0 }
for type, a,b,c,d in system.poll_event do for type, a,b,c,d in system.poll_event do
if type == "mousemoved" then if type == "textinput" and did_keymap then
mouse_moved = true
mouse.x, mouse.y = a, b
mouse.dx, mouse.dy = mouse.dx + c, mouse.dy + d
elseif type == "textinput" and did_keymap then
did_keymap = false did_keymap = false
elseif type == "mousemoved" then
core.try(core.on_event, type, a, b, c, d)
else else
local _, res = core.try(core.on_event, type, a, b, c, d) local _, res = core.try(core.on_event, type, a, b, c, d)
did_keymap = res or did_keymap did_keymap = res or did_keymap
end end
core.redraw = true core.redraw = true
end end
if mouse_moved then
core.try(core.on_event, "mousemoved", mouse.x, mouse.y, mouse.dx, mouse.dy)
end
local width, height = renderer.get_size() local width, height = renderer.get_size()

View File

@ -129,14 +129,14 @@ function Node:split(dir, view, locked, resizable)
return self.b return self.b
end end
function Node:remove_view(root, view)
function Node:close_view(root, view)
local new_active_view = view == self.active_view
local do_close = function()
if #self.views > 1 then if #self.views > 1 then
local idx = self:get_view_idx(view) local idx = self:get_view_idx(view)
if idx < self.tab_offset then
self.tab_offset = self.tab_offset - 1
end
table.remove(self.views, idx) table.remove(self.views, idx)
if new_active_view then if self.active_view == view then
self:set_active_view(self.views[idx] or self.views[#self.views]) self:set_active_view(self.views[idx] or self.views[#self.views])
end end
else else
@ -160,6 +160,11 @@ function Node:close_view(root, view)
end end
core.last_active_view = nil core.last_active_view = nil
end end
function Node:close_view(root, view)
local do_close = function()
self:remove_view(root, view)
end
view:try_close(do_close) view:try_close(do_close)
end end
@ -169,13 +174,13 @@ function Node:close_active_view(root)
end end
function Node:add_view(view) function Node:add_view(view, idx)
assert(self.type == "leaf", "Tried to add view to non-leaf node") assert(self.type == "leaf", "Tried to add view to non-leaf node")
assert(not self.locked, "Tried to add view to locked node") assert(not self.locked, "Tried to add view to locked node")
if self.views[1] and self.views[1]:is(EmptyView) then if self.views[1] and self.views[1]:is(EmptyView) then
table.remove(self.views) table.remove(self.views)
end end
table.insert(self.views, view) table.insert(self.views, idx or (#self.views + 1), view)
self:set_active_view(view) self:set_active_view(view)
end end
@ -749,7 +754,7 @@ function RootView:on_mouse_pressed(button, x, y, clicks)
if button == "middle" or node.hovered_close == idx then if button == "middle" or node.hovered_close == idx then
node:close_view(self.root_node, node.views[idx]) node:close_view(self.root_node, node.views[idx])
else else
self.dragged_node = idx self.dragged_node = { node, idx }
node:set_active_view(node.views[idx]) node:set_active_view(node.views[idx])
end end
else else
@ -816,14 +821,26 @@ function RootView:on_mouse_moved(x, y, dx, dy)
end end
elseif tab_index then elseif tab_index then
core.request_cursor("arrow") core.request_cursor("arrow")
if self.dragged_node and self.dragged_node ~= tab_index then elseif node then
local tab = node.views[self.dragged_node] core.request_cursor(node.active_view.cursor)
table.remove(node.views, self.dragged_node) end
table.insert(node.views, tab_index, tab) if node and self.dragged_node and (self.dragged_node[1] ~= node or (tab_index and self.dragged_node[2] ~= tab_index))
self.dragged_node = tab_index and node.type == "leaf" and #node.views > 0 and node.views[1]:is(DocView) then
local tab = self.dragged_node[1].views[self.dragged_node[2]]
if self.dragged_node[1] ~= node then
for i, v in ipairs(node.views) do if v.doc == tab.doc then tab = nil break end end
if tab then
self.dragged_node[1]:remove_view(self.root_node, tab)
node:add_view(tab, tab_index)
self.root_node:update_layout()
self.dragged_node = { node, tab_index or #node.views }
core.redraw = true
end end
else else
core.request_cursor(node.active_view.cursor) table.remove(self.dragged_node[1].views, self.dragged_node[2])
table.insert(node.views, tab_index, tab)
self.dragged_node = { node, tab_index }
end
end end
end end

View File

@ -33,7 +33,7 @@ if get_option('portable')
lite_docdir = 'doc' lite_docdir = 'doc'
lite_datadir = 'data' lite_datadir = 'data'
else else
lite_docdir = 'share/doc' lite_docdir = 'share/doc/lite-xl'
lite_datadir = 'share/lite-xl' lite_datadir = 'share/lite-xl'
endif endif

View File

@ -201,6 +201,14 @@ top:
return 4; return 4;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
SDL_PumpEvents();
SDL_Event event_plus;
while (SDL_PeepEvents(&event_plus, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) {
e.motion.x = event_plus.motion.x;
e.motion.y = event_plus.motion.y;
e.motion.xrel += event_plus.motion.xrel;
e.motion.yrel += event_plus.motion.yrel;
}
lua_pushstring(L, "mousemoved"); lua_pushstring(L, "mousemoved");
lua_pushnumber(L, e.motion.x); lua_pushnumber(L, e.motion.x);
lua_pushnumber(L, e.motion.y); lua_pushnumber(L, e.motion.y);

View File

@ -309,7 +309,8 @@ void ren_draw_rect(RenRect rect, RenColor color) {
int dr = surface->w - (x2 - x1); int dr = surface->w - (x2 - x1);
if (color.a == 0xff) { if (color.a == 0xff) {
rect_draw_loop(color); SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 };
SDL_FillRect(surface, &rect, SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a));
} else { } else {
rect_draw_loop(blend_pixel(*d, color)); rect_draw_loop(blend_pixel(*d, color));
} }