redo input translation -round 2
This commit is contained in:
@@ -126,7 +126,7 @@ Event.addRoutine(function()
|
|||||||
p4 = e[5],
|
p4 = e[5],
|
||||||
p5 = e[6],
|
p5 = e[6],
|
||||||
})
|
})
|
||||||
if #page.grid.values > page.grid.height - 1 then
|
if #page.grid.values > page.grid.height then
|
||||||
table.remove(page.grid.values, #page.grid.values)
|
table.remove(page.grid.values, #page.grid.values)
|
||||||
end
|
end
|
||||||
page.grid:update()
|
page.grid:update()
|
||||||
|
|||||||
116
apps/edit.lua
116
apps/edit.lua
@@ -35,6 +35,7 @@ local scrollX = 0
|
|||||||
local scrollY = 0
|
local scrollY = 0
|
||||||
local lastPos = { x = 1, y = 1 }
|
local lastPos = { x = 1, y = 1 }
|
||||||
local tLines = { }
|
local tLines = { }
|
||||||
|
local input = { pressed = { } }
|
||||||
local bRunning = true
|
local bRunning = true
|
||||||
local sStatus = ""
|
local sStatus = ""
|
||||||
local isError
|
local isError
|
||||||
@@ -43,7 +44,6 @@ local lastAction
|
|||||||
|
|
||||||
local dirty = { y = 1, ey = h }
|
local dirty = { y = 1, ey = h }
|
||||||
local mark = { }
|
local mark = { }
|
||||||
--local input
|
|
||||||
local searchPattern
|
local searchPattern
|
||||||
local undo = { chain = { }, pointer = 0 }
|
local undo = { chain = { }, pointer = 0 }
|
||||||
local complete = { }
|
local complete = { }
|
||||||
@@ -158,7 +158,7 @@ local keyMapping = {
|
|||||||
-- misc
|
-- misc
|
||||||
[ 'control-g' ] = 'status',
|
[ 'control-g' ] = 'status',
|
||||||
[ 'control-r' ] = 'refresh',
|
[ 'control-r' ] = 'refresh',
|
||||||
[ 'leftCtrl' ] = 'menu',
|
[ 'control' ] = 'menu',
|
||||||
}
|
}
|
||||||
|
|
||||||
local messages = {
|
local messages = {
|
||||||
@@ -463,7 +463,7 @@ local __actions = {
|
|||||||
term.write(prompt)
|
term.write(prompt)
|
||||||
local str = hacky_read()
|
local str = hacky_read()
|
||||||
term.setCursorBlink(true)
|
term.setCursorBlink(true)
|
||||||
--keyboard.shift, keyboard.control = false, false
|
input:reset()
|
||||||
term.setCursorPos(x - scrollX, y - scrollY)
|
term.setCursorPos(x - scrollX, y - scrollY)
|
||||||
actions.dirty_line(scrollY + h)
|
actions.dirty_line(scrollY + h)
|
||||||
return str
|
return str
|
||||||
@@ -1100,25 +1100,25 @@ term.setCursorBlink(true)
|
|||||||
redraw()
|
redraw()
|
||||||
|
|
||||||
local modifiers = {
|
local modifiers = {
|
||||||
[1] = keys.leftCtrl,
|
[ keys.leftCtrl ] = true,
|
||||||
[2] = keys.rightCtrl,
|
[ keys.rightCtrl ] = true,
|
||||||
[3] = keys.leftShift,
|
[ keys.leftShift ] = true,
|
||||||
[4] = keys.rightShift,
|
[ keys.rightShift ] = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local input = {
|
function input:toCode(code, ch)
|
||||||
pressed = { },
|
|
||||||
}
|
|
||||||
|
|
||||||
function input:toCode(code)
|
ch = ch or keys.getName(code)
|
||||||
|
|
||||||
local ch = self.ch or keys.getName(code)
|
|
||||||
local result = { }
|
local result = { }
|
||||||
|
|
||||||
if self.pressed[keys.leftCtrl] or self.pressed[keys.rightCtrl] then
|
if self.pressed[keys.leftCtrl] or self.pressed[keys.rightCtrl] then
|
||||||
table.insert(result, 'control')
|
table.insert(result, 'control')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--if self.pressed[keys.leftAlt] or self.pressed[keys.rightAlt] then
|
||||||
|
-- table.insert(result, 'alt')
|
||||||
|
--end
|
||||||
|
|
||||||
if self.pressed[keys.leftShift] or self.pressed[keys.rightShift] then
|
if self.pressed[keys.leftShift] or self.pressed[keys.rightShift] then
|
||||||
if modifiers[code] or #ch > 1 then
|
if modifiers[code] or #ch > 1 then
|
||||||
table.insert(result, 'shift')
|
table.insert(result, 'shift')
|
||||||
@@ -1134,11 +1134,21 @@ function input:toCode(code)
|
|||||||
return table.concat(result, '-')
|
return table.concat(result, '-')
|
||||||
end
|
end
|
||||||
|
|
||||||
function input:translate(event, code, heldDown)
|
function input:reset()
|
||||||
|
self.pressed = { }
|
||||||
|
self.ch = nil
|
||||||
|
self.fired = nil
|
||||||
|
|
||||||
|
self.timer = nil
|
||||||
|
self.mch = nil
|
||||||
|
self.mfired = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function input:translate(event, code, p1, p2)
|
||||||
if event == 'key' then
|
if event == 'key' then
|
||||||
if heldDown then
|
if p1 then -- key is held down
|
||||||
if not modifiers[code] then
|
if not modifiers[code] then
|
||||||
self.fired = input:toCode(code)
|
self.fired = input:toCode(code, self.ch)
|
||||||
return self.fired
|
return self.fired
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -1153,30 +1163,13 @@ function input:translate(event, code, heldDown)
|
|||||||
elseif event == 'key_up' then
|
elseif event == 'key_up' then
|
||||||
if not self.fired then
|
if not self.fired then
|
||||||
if self.pressed[code] then
|
if self.pressed[code] then
|
||||||
self.fired = input:toCode(code)
|
self.fired = input:toCode(code, self.ch)
|
||||||
self.pressed[code] = nil
|
self.pressed[code] = nil
|
||||||
return self.fired
|
return self.fired
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.pressed[code] = nil
|
self.pressed[code] = nil
|
||||||
|
|
||||||
elseif event == 'mouse_click' then
|
|
||||||
|
|
||||||
local buttons = { 'mouse_click', 'mouse_rightclick', 'mouse_doubleclick' }
|
|
||||||
self.ch = buttons[code]
|
|
||||||
self.fired = input:toCode(0)
|
|
||||||
return self.fired
|
|
||||||
|
|
||||||
elseif event == "mouse_scroll" then
|
|
||||||
local directions = {
|
|
||||||
[ -1 ] = 'scrollUp',
|
|
||||||
[ 1 ] = 'scrollDown'
|
|
||||||
}
|
|
||||||
self.ch = directions[code]
|
|
||||||
self.fired = input:toCode(0)
|
|
||||||
return self.fired
|
|
||||||
|
|
||||||
elseif event == 'paste' then
|
elseif event == 'paste' then
|
||||||
self.ch = 'paste'
|
self.ch = 'paste'
|
||||||
self.pressed[keys.leftCtrl] = nil
|
self.pressed[keys.leftCtrl] = nil
|
||||||
@@ -1188,10 +1181,44 @@ function input:translate(event, code, heldDown)
|
|||||||
end
|
end
|
||||||
return self.fired
|
return self.fired
|
||||||
|
|
||||||
|
elseif event == 'mouse_click' then
|
||||||
|
local buttons = { 'mouse_click', 'mouse_rightclick' }
|
||||||
|
self.mch = buttons[code]
|
||||||
|
self.mfired = nil
|
||||||
|
|
||||||
elseif event == 'mouse_drag' then
|
elseif event == 'mouse_drag' then
|
||||||
self.ch = 'mouse_drag'
|
self.mch = 'mouse_drag'
|
||||||
self.fired = input:toCode(0)
|
self.mfired = input:toCode(0, self.mch)
|
||||||
return self.fired
|
return self.mfired
|
||||||
|
|
||||||
|
elseif event == 'mouse_up' then
|
||||||
|
if not self.mfired then
|
||||||
|
local clock = os.clock()
|
||||||
|
if self.timer and
|
||||||
|
p1 == self.x and p2 == self.y and
|
||||||
|
(clock - self.timer < .5) then
|
||||||
|
|
||||||
|
self.mch = 'mouse_doubleclick'
|
||||||
|
self.timer = nil
|
||||||
|
else
|
||||||
|
self.timer = os.clock()
|
||||||
|
self.x = p1
|
||||||
|
self.y = p2
|
||||||
|
end
|
||||||
|
self.mfired = input:toCode(0, self.mch)
|
||||||
|
else
|
||||||
|
self.mch = 'mouse_up'
|
||||||
|
self.mfired = input:toCode(0, self.mch)
|
||||||
|
end
|
||||||
|
return self.mfired
|
||||||
|
|
||||||
|
elseif event == "mouse_scroll" then
|
||||||
|
local directions = {
|
||||||
|
[ -1 ] = 'scrollUp',
|
||||||
|
[ 1 ] = 'scrollDown'
|
||||||
|
}
|
||||||
|
self.mch = directions[code]
|
||||||
|
return input:toCode(0, self.mch)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1201,9 +1228,11 @@ while bRunning do
|
|||||||
|
|
||||||
if sEvent == 'terminate' then
|
if sEvent == 'terminate' then
|
||||||
action = 'exit'
|
action = 'exit'
|
||||||
elseif sEvent == "mouse_click" or sEvent == 'mouse_drag' then
|
elseif sEvent == 'multishell_focus' then -- opus only event
|
||||||
|
input:reset()
|
||||||
|
elseif sEvent == "mouse_click" or sEvent == 'mouse_drag' or sEvent == 'mouse_up' then
|
||||||
|
local ch = input:translate(sEvent, param, param2, param3)
|
||||||
if param3 < h or sEvent == 'mouse_drag' then
|
if param3 < h or sEvent == 'mouse_drag' then
|
||||||
local ch = input:translate(sEvent, param)
|
|
||||||
if ch then
|
if ch then
|
||||||
action = keyMapping[ch]
|
action = keyMapping[ch]
|
||||||
param = param2 + scrollX
|
param = param2 + scrollX
|
||||||
@@ -1211,9 +1240,14 @@ while bRunning do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local ch = input:translate(sEvent, param)
|
local ch = input:translate(sEvent, param, param2)
|
||||||
if ch then
|
if ch then
|
||||||
action = keyMapping[ch]
|
if #ch == 1 then
|
||||||
|
action = keyMapping.char
|
||||||
|
param = ch
|
||||||
|
else
|
||||||
|
action = keyMapping[ch]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user