50 lines
1.4 KiB
Plaintext
50 lines
1.4 KiB
Plaintext
on.mouse_press = function(x,y, mouse_button)
|
|
if Global_state.thread == nil then
|
|
-- we're rendering the file picker
|
|
-- check for any button clicks
|
|
for _,button in ipairs(Global_state.file_picker) do
|
|
-- do nothing; everything happens on release
|
|
-- (to avoid changing the surface between press and release)
|
|
if in_rect(button, x,y) then
|
|
return
|
|
end
|
|
end
|
|
-- no button clicked; pan surface
|
|
Pan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom}
|
|
return
|
|
end
|
|
print('mouse press', x,y)
|
|
if Cursor_node then
|
|
Cursor_node.show_cursor = nil
|
|
Cursor_node = nil
|
|
end
|
|
if mouse_press_consumed_by_any_button(HUD, x,y, mouse_button) then
|
|
B()
|
|
return
|
|
end
|
|
local node = on_text(x,y)
|
|
if node then
|
|
-- position cursor in node
|
|
Cursor_node = node
|
|
print('within node')
|
|
edit.mouse_press(node.editor, x,y, mouse_button)
|
|
print('cursor at', node.editor.cursor_x, node.editor.cursor_y)
|
|
return
|
|
end
|
|
local button = on_button(x,y)
|
|
if button then
|
|
local n, id = new_comment(button.target_id, button.depth)
|
|
local parent = find_node(Global_state.thread, button.target_id)
|
|
assert(parent)
|
|
table.insert(parent.metadata.replies, id)
|
|
save_metadata(parent)
|
|
local item_index = find_comment_index(button.target_id)
|
|
table.insert(Global_state.thread.data,
|
|
item_index+1,
|
|
n)
|
|
A()
|
|
end
|
|
-- pan surface
|
|
Pan = {x=Viewport.x+x/Viewport.zoom, y=Viewport.y+y/Viewport.zoom}
|
|
end
|