diff --git a/0002-vx b/0002-vx index 15f794b..065d2c5 100644 --- a/0002-vx +++ b/0002-vx @@ -1,3 +1,4 @@ -vx = function(x) - return scale(x-Viewport.x) -end \ No newline at end of file +vx = function(sx) + -- turn surface coordinates into viewport coordinates + return scale(sx-Viewport.x) +end diff --git a/0004-vy b/0004-vy index 5fb9f8c..8e4e23e 100644 --- a/0004-vy +++ b/0004-vy @@ -1,3 +1,4 @@ -vy = function(y) - return scale(y-Viewport.y) -end \ No newline at end of file +vy = function(sy) + -- turn surface coordinates into viewport coordinates + return scale(sy-Viewport.y) +end diff --git a/0006-on.mouse_press b/0006-on.mouse_press index 52a00c6..faa26bf 100644 --- a/0006-on.mouse_press +++ b/0006-on.mouse_press @@ -5,9 +5,11 @@ on.mouse_press = function(x,y, mouse_button) end local node = to_text(x,y) if node then + -- position cursor in node Cursor_node = node edit.mouse_press(node.editor, x,y, mouse_button) - else - Pan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom} + return end + -- pan surface + Pan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom} end diff --git a/0011-box_height b/0011-box_height index 8ecf97b..ca50708 100644 --- a/0011-box_height +++ b/0011-box_height @@ -1,16 +1,16 @@ box_height = function(node) - -- return the height of a node. The result is scaled. - local y = 0 - for i=1,#node.editor.lines do - local line = node.editor.lines[i] - if node.editor.line_cache[i] == nil then - node.editor.line_cache[i] = {} - end - node.editor.line_cache[i].fragments = nil - node.editor.line_cache[i].screen_line_starting_pos = nil - Text.populate_screen_line_starting_pos(node.editor, i) - y = y + node.editor.line_height*#node.editor.line_cache[i].screen_line_starting_pos - Text.clear_screen_line_cache(node.editor, i) - end - return y + -- return the height of a text editor node (explicit width). The result is unscaled. + local y = 0 + for i=1,#node.editor.lines do + local line = node.editor.lines[i] + if node.editor.line_cache[i] == nil then + node.editor.line_cache[i] = {} + end + node.editor.line_cache[i].fragments = nil + node.editor.line_cache[i].screen_line_starting_pos = nil + Text.populate_screen_line_starting_pos(node.editor, i) + y = y + 20*1.3*#node.editor.line_cache[i].screen_line_starting_pos + Text.clear_screen_line_cache(node.editor, i) + end + return y end diff --git a/0017-on.mouse_release b/0017-on.mouse_release index 0a14bf4..5c987a0 100644 --- a/0017-on.mouse_release +++ b/0017-on.mouse_release @@ -1,8 +1,9 @@ on.mouse_release = function(x,y, mouse_button) if Pan then Pan = nil + A() elseif Cursor_node then Cursor_node.show_cursor = true edit.mouse_release(Cursor_node.editor, x,y, mouse_button) end -end \ No newline at end of file +end