From 5c975fb1c6af897d389d6c8c219592e8ff6a55d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Thu, 12 Dec 2013 15:45:37 +0100 Subject: [PATCH] added support for setting cursor position in edit by clicking --- assets/opencomputers/lua/rom/bin/edit.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/assets/opencomputers/lua/rom/bin/edit.lua b/assets/opencomputers/lua/rom/bin/edit.lua index f3c43c9e5..87f3b6e96 100644 --- a/assets/opencomputers/lua/rom/bin/edit.lua +++ b/assets/opencomputers/lua/rom/bin/edit.lua @@ -297,6 +297,16 @@ local function onClipboard(value) term.setCursorBlink(true) -- force toggle to caret end +local function onClick(x, y) + local w, h = getSize() + x = math.max(1, math.min(w, x)) + y = math.max(1, math.min(h, #buffer, y)) + setCursor(x, y) + if getCursor() > unicode.len(line()) then + ende() + end +end + ------------------------------------------------------------------------------- do @@ -327,12 +337,14 @@ do end while running do - local event, address, charOrValue, code = event.pull() + local event, address, arg1, arg2 = event.pull() if type(address) == "string" and component.isPrimary(address) then if event == "key_down" then - onKeyDown(charOrValue, code) + onKeyDown(arg1, arg2) elseif event == "clipboard" then - onClipboard(charOrValue) + onClipboard(arg1) + elseif event == "click" then + onClick(arg1, arg2) end end end