altgr combos
This commit is contained in:
162
common/edit.lua
162
common/edit.lua
@@ -1,3 +1,5 @@
|
|||||||
|
local input = require('input')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
local keys = _G.keys
|
local keys = _G.keys
|
||||||
@@ -35,7 +37,6 @@ 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
|
||||||
@@ -110,9 +111,9 @@ local keyMapping = {
|
|||||||
[ 'control-end' ] = 'bottom',
|
[ 'control-end' ] = 'bottom',
|
||||||
[ 'control-right' ] = 'word',
|
[ 'control-right' ] = 'word',
|
||||||
[ 'control-left' ] = 'backword',
|
[ 'control-left' ] = 'backword',
|
||||||
[ 'scrollUp' ] = 'scroll_up',
|
[ 'scroll_up' ] = 'scroll_up',
|
||||||
[ 'control-up' ] = 'scroll_up',
|
[ 'control-up' ] = 'scroll_up',
|
||||||
[ 'scrollDown' ] = 'scroll_down',
|
[ 'scroll_down' ] = 'scroll_down',
|
||||||
[ 'control-down' ] = 'scroll_down',
|
[ 'control-down' ] = 'scroll_down',
|
||||||
[ 'mouse_click' ] = 'go_to',
|
[ 'mouse_click' ] = 'go_to',
|
||||||
[ 'control-l' ] = 'goto_line',
|
[ 'control-l' ] = 'goto_line',
|
||||||
@@ -1102,144 +1103,6 @@ local __actions = {
|
|||||||
|
|
||||||
actions = __actions
|
actions = __actions
|
||||||
|
|
||||||
local modifiers = {
|
|
||||||
[ keys.leftCtrl ] = true,
|
|
||||||
[ keys.rightCtrl ] = true,
|
|
||||||
[ keys.leftShift ] = true,
|
|
||||||
[ keys.rightShift ] = true,
|
|
||||||
[ keys.leftAlt ] = true,
|
|
||||||
[ keys.rightAlt ] = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
function input:modifierPressed()
|
|
||||||
return self.pressed[keys.leftCtrl] or
|
|
||||||
self.pressed[keys.rightCtrl] or
|
|
||||||
self.pressed[keys.leftAlt] or
|
|
||||||
self.pressed[keys.rightAlt]
|
|
||||||
end
|
|
||||||
|
|
||||||
function input:toCode(ch, code)
|
|
||||||
local result = { }
|
|
||||||
|
|
||||||
if self.pressed[keys.leftCtrl] or self.pressed[keys.rightCtrl] then
|
|
||||||
table.insert(result, 'control')
|
|
||||||
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 code and modifiers[code] then
|
|
||||||
table.insert(result, 'shift')
|
|
||||||
elseif #ch == 1 then
|
|
||||||
table.insert(result, ch:upper())
|
|
||||||
else
|
|
||||||
table.insert(result, 'shift')
|
|
||||||
table.insert(result, ch)
|
|
||||||
end
|
|
||||||
elseif not code or not modifiers[code] then
|
|
||||||
table.insert(result, ch)
|
|
||||||
end
|
|
||||||
|
|
||||||
return table.concat(result, '-')
|
|
||||||
end
|
|
||||||
|
|
||||||
function input:reset()
|
|
||||||
self.pressed = { }
|
|
||||||
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 p1 then -- key is held down
|
|
||||||
if not modifiers[code] then
|
|
||||||
self.fired = true
|
|
||||||
return input:toCode(keys.getName(code), code)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self.pressed[code] = true
|
|
||||||
if self:modifierPressed() and not modifiers[code] or code == 57 then
|
|
||||||
--self.fired = true
|
|
||||||
--return input:toCode(keys.getName(code), code)
|
|
||||||
else
|
|
||||||
self.fired = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event == 'char' then
|
|
||||||
if not self.fired then
|
|
||||||
self.fired = true
|
|
||||||
return code -- input:toCode(code)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event == 'key_up' then
|
|
||||||
if not self.fired then
|
|
||||||
if self.pressed[code] then
|
|
||||||
self.fired = true
|
|
||||||
local ch = input:toCode(keys.getName(code), code)
|
|
||||||
self.pressed[code] = nil
|
|
||||||
return ch
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.pressed[code] = nil
|
|
||||||
|
|
||||||
elseif event == 'paste' then
|
|
||||||
self.pressed[keys.leftCtrl] = nil
|
|
||||||
self.pressed[keys.rightCtrl] = nil
|
|
||||||
self.fired = true
|
|
||||||
if self.pressed[keys.leftShift] or self.pressed[keys.rightShift] then
|
|
||||||
return 'control-shift-paste'
|
|
||||||
end
|
|
||||||
return 'paste'
|
|
||||||
|
|
||||||
elseif event == 'mouse_click' then
|
|
||||||
local buttons = { 'mouse_click', 'mouse_rightclick' }
|
|
||||||
self.mch = buttons[code]
|
|
||||||
self.mfired = nil
|
|
||||||
return input:toCode('mouse_down', 255)
|
|
||||||
|
|
||||||
elseif event == 'mouse_drag' then
|
|
||||||
self.mfired = true
|
|
||||||
self.fired = true
|
|
||||||
return input:toCode('mouse_drag', 255)
|
|
||||||
|
|
||||||
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(self.mch, 255)
|
|
||||||
else
|
|
||||||
self.mch = 'mouse_up'
|
|
||||||
self.mfired = input:toCode(self.mch, 255)
|
|
||||||
end
|
|
||||||
self.fired = true
|
|
||||||
return self.mfired
|
|
||||||
|
|
||||||
elseif event == "mouse_scroll" then
|
|
||||||
local directions = {
|
|
||||||
[ -1 ] = 'scrollUp',
|
|
||||||
[ 1 ] = 'scrollDown'
|
|
||||||
}
|
|
||||||
self.fired = true
|
|
||||||
return input:toCode(directions[code], 255)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
load(sPath)
|
load(sPath)
|
||||||
term.setCursorBlink(true)
|
term.setCursorBlink(true)
|
||||||
redraw()
|
redraw()
|
||||||
@@ -1256,22 +1119,23 @@ while bRunning do
|
|||||||
sEvent == 'mouse_drag' or
|
sEvent == 'mouse_drag' or
|
||||||
sEvent == 'mouse_up' or
|
sEvent == 'mouse_up' or
|
||||||
sEvent == 'mouse_down' then
|
sEvent == 'mouse_down' then
|
||||||
local ch = input:translate(sEvent, param, param2, param3)
|
local ie = input:translate(sEvent, param, param2, param3)
|
||||||
if param3 < h or sEvent == 'mouse_drag' then
|
if param3 < h or sEvent == 'mouse_drag' then
|
||||||
if ch then
|
if ie.code then
|
||||||
action = keyMapping[ch]
|
action = keyMapping[ie.code]
|
||||||
param = param2 + scrollX
|
param = param2 + scrollX
|
||||||
param2 = param3 + scrollY
|
param2 = param3 + scrollY
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local ch = input:translate(sEvent, param, param2)
|
local ie = input:translate(sEvent, param, param2)
|
||||||
if ch then
|
if ie then
|
||||||
if #ch == 1 then
|
if ie.ch and #ie.ch == 1 then
|
||||||
action = keyMapping.char
|
action = keyMapping.char
|
||||||
param = ch
|
param = ie.ch
|
||||||
else
|
else
|
||||||
action = keyMapping[ch]
|
_debug(ie.code)
|
||||||
|
action = keyMapping[ie.code]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user