-- TIME_STAMP 2013-05-27 18:02:39 v 0.2 -- by BugFix EditKey = EventClass:new(Common) ------------------------------------------------------------------------- local fOwnMode = false ------------------------------------------------------------------------- ------------------------------------------------------------------------- local Clock = function() local datetable = os.date("*t", os.time()) return string.format('%02d:%02d:%02d', datetable.hour, datetable.min, datetable.sec) end ------------------------------------------------------------------------- ------------------------------------------------------------------------- local SelectionMoveH = function(_fLeft) local moveText = function(_s, _a, _e, _val) editor:SetSelection(_a, _e) editor:Clear() if _val == -1 then editor:CharLeft() else editor:CharRight() end editor:InsertText(editor.CurrentPos, _s) editor:SetSelection(_a +(_val), _e +(_val)) end output:ClearAll() local sErr = "!>> "..Clock().." [Error SelectionMoveH] >> " local caret = editor.CurrentPos local line = editor:LineFromPosition(caret) local selText, selLen = editor:GetSelText() local selStart, selEnd = editor:GetLineSelStartPosition(line), editor:GetLineSelEndPosition(line) editor:SetSelection(selStart, selEnd) -- now the cursor is on left side of selection if selLen == 0 then print(sErr..'Nothing selected!') return end local lineStart = editor:PositionFromLine(line) editor:LineEnd() local lineEnd = editor.CurrentPos if _fLeft then if caret > lineStart then moveText(selText, selStart, selEnd, -1) else print(sErr..'First position was already reached!') editor:SetSelection(selStart, selEnd) end else if selStart +selLen -1 < lineEnd then moveText(selText, selStart, selEnd, 1) else print(sErr..'Last position was already reached!') editor:SetSelection(selStart, selEnd) end end end --> SelectionMoveH ------------------------------------------------------------------------- ------------------------------------------------------------------------- local SelectionMoveV = function(_fUp) local moveText = function(_i, _txt, _len, _line) editor:Clear() local lineNext = _line +(_i) local lenNext = editor:LineLength(lineNext) local lineNextStart = editor:PositionFromLine(lineNext) local insertPos = lineNextStart + editor.Column[editor.CurrentPos] if lenNext < editor.Column[editor.CurrentPos] then insertPos = lineNextStart end editor:InsertText(insertPos, _txt) editor:SetSelection(insertPos, insertPos +_len-1) editor:EnsureVisible(lineNext) end output:ClearAll() local sErr = "!>> "..Clock().." [Error SelectionMoveV] >> " local line = editor:LineFromPosition(editor.CurrentPos) local lineLast = editor.LineCount -1 local selStart, selEnd = editor:GetLineSelStartPosition(line), editor:GetLineSelEndPosition(line) local selText, selLen = editor:GetSelText() editor:SetSelection(selStart, selEnd) -- now the cursor is on left side of selection if selLen == 0 then print(sErr..'Nothing selected!') return end if _fUp then if line == 0 then print(sErr..'No line before this!') return else moveText(-1, selText, selLen, line) end else if line == lineLast then print(sErr..'No line after this!') return else moveText(1, selText, selLen, line) end end end --> SelectionMoveV ------------------------------------------------------------------------- ------------------------------------------------------------------------- local SkipToComment = function() local IsComment = function(_pos) local tComment = {1,2} if tComment[editor.StyleAt[_pos]] == nil then return false else return true end end output:ClearAll() local caret = editor.CurrentPos local iStart = caret local iLine = editor:LineFromPosition(iStart) local iLineStart = editor:PositionFromLine(iLine) if IsComment(iStart) then while (iStart-1 >= iLineStart) and IsComment(iStart-1) do iStart = iStart-1 end else while (iStart+1 < iLineStart +editor:LineLength(iLine)) and not IsComment(iStart+1) do iStart = iStart+1 end iStart = iStart+1 end if not IsComment(iStart) then editor.CurrentPos = caret print("!>> "..Clock().." [Error SkipToComment] >> No comment in this line!") return end editor:SetSelection(iStart, iStart) end --> SkipToComment ------------------------------------------------------------------------- ------------------------------------------------------------------------- local SetSelection = function(_part) local isWordChar = function(_char) if string.char(_char):find('[a-zA-Z0-9_]') then return true end return false end local iStart = editor.CurrentPos local iEnd = iStart while isWordChar(editor.CharAt[iStart-1]) do iStart = iStart - 1 end if not _part and string.char(editor.CharAt[iStart-1]) == "$" then iStart = iStart - 1 end while isWordChar(editor.CharAt[iEnd]) do iEnd = iEnd + 1 end if iStart ~= iEnd then editor:SetSelection(iStart, iEnd) end end --> SetSelection ------------------------------------------------------------------------- ------------------------------------------------------------------------- local RunSelectedCode = function() local writeTmpFile = function(_path, _s) local file = io.open(_path, 'w+') file:write(_s) file:close() end output:ClearAll() local sErr = "!>> "..Clock().." [Error RunSelectedCode] >> " local fileExt = props["FileExt"] if fileExt:upper() ~= 'AU3' then output:ClearAll() print(sErr..'Attempting to run code from a non-au3 file!') return end local fileDir = props["FileDir"] local sSel = editor:GetSelText() if sSel == '' then print(sErr..'No code selected!') return end local text = editor:GetText() local sWrite = '' for incl in text:gmatch("[\n]?(#[iI][nN][cC][lL][uU][dD][eE]%s-<[%w%s_.]+>)") do sWrite = sWrite..incl..'\n' end for incl in text:gmatch("[\n]?(#[iI][nN][cC][lL][uU][dD][eE]%s-([\"'])[%w%s_.:\\]+%2)") do sWrite = sWrite..incl..'\n' end local newPath = fileDir..'\\'..'__TMP__RunSelected.au3' writeTmpFile(newPath, sWrite..'\n'..sSel) scite.Open(newPath) scite.MenuCommand(IDM_GO) end --> RunSelectedCode ------------------------------------------------------------------------- ------------------------------------------------------------------------- local GetHotkeyList = function() local tKeys = {} tKeys['Ctrl+Win, Ctrl+C'] = ' Skip to |C|omment in line if any' tKeys['Ctrl+Win, Ctrl+F'] = ' |F|ull selection, expand selection to full word with Wordcharacters and leading "$"' tKeys['Ctrl+Win, Ctrl+L'] = ' |L|ine selection' tKeys['Ctrl+Win, Ctrl+P'] = ' |P|artial selection, expand selection to full word with only Wordcharacters' tKeys['Ctrl+Win, Ctrl+R'] = ' |R|un Selected Code' tKeys['Ctrl+Win, Ctrl+S'] = ' Reload SciTE |S|tartup script' tKeys['Ctrl+Win, Ctrl+T'] = ' |T|oggle adjacent characters' tKeys['Ctrl+Win, Ctrl+U'] = ' |U|nselect any selections' tKeys['Ctrl+Win, Ctrl+Z'] = ' Run Testscript "LUA_TEST.lua"' tKeys['Ctrl+Win, Ctrl+0'] = ' Print HotkeyList to console' tKeys['Ctrl+Alt+ArrowLeft'] = ' Move selection in line to Left' tKeys['Ctrl+Alt+ArrowRight'] = ' Move selection in line to Right' tKeys['Ctrl+Alt+ArrowUp'] = ' Move selection in line Up' tKeys['Ctrl+Alt+ArrowDown'] = ' Move selection in line Down' tKeys['Ctrl+Shift+ArrowDown'] = ' Move line/selected-lines Down' tKeys['Ctrl+Shift+ArrowUp'] = ' Move line/selected-lines Up' local pairsSortByKeys = function(t, f) local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f) local i = 0 local iter = function () i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iter end local lenMax, s = 0, '.' for k, _ in pairs(tKeys) do if k:len() > lenMax then lenMax = k:len() end end lenMax = lenMax +4 output:ClearAll() print('--> KeyList in alphabetical order') for k, v in pairsSortByKeys(tKeys) do print('+-> '..k..s:rep(lenMax-k:len())..v) end end --> GetHotkeyList ------------------------------------------------------------------------- --- Event: OnKey -------------------------------------------------------- function EditKey:OnKey(_keycode, _shift, _ctrl, _alt) --~ print('_keycode: '..tostring(_keycode)..', _shift: '..tostring(_shift)..', _ctrl: '..tostring(_ctrl)..', _alt: '..tostring(_alt)) -- DebugToConsole if not fOwnMode and _ctrl and not _shift and not _alt and _keycode == 91 then --- Ctrl+Win activates OwnMode fOwnMode = true return true end if fOwnMode then --- processing own commands -- Ctrl+Win, Ctrl+A --~ if _ctrl and not _shift and not _alt and _keycode == 65 then -- Ctrl+Win, Ctrl+B --~ if _ctrl and not _shift and not _alt and _keycode == 66 then -- Ctrl+Win, Ctrl+C ##== Skip to |C|omment in line if any ==## if _ctrl and not _shift and not _alt and _keycode == 67 then SkipToComment() end -- Ctrl+Win, Ctrl+D --~ if _ctrl and not _shift and not _alt and _keycode == 68 then -- Ctrl+Win, Ctrl+E --~ if _ctrl and not _shift and not _alt and _keycode == 69 then -- Ctrl+Win, Ctrl+F ##== |F|ull selection, expand selection to full word with Wordcharacters and leading "$" ==## if _ctrl and not _shift and not _alt and _keycode == 70 then SetSelection(false) end -- Ctrl+Win, Ctrl+G --~ if _ctrl and not _shift and not _alt and _keycode == 71 then -- Ctrl+Win, Ctrl+H --~ if _ctrl and not _shift and not _alt and _keycode == 72 then -- Ctrl+Win, Ctrl+I --~ if _ctrl and not _shift and not _alt and _keycode == 73 then -- Ctrl+Win, Ctrl+J --~ if _ctrl and not _shift and not _alt and _keycode == 74 then -- Ctrl+Win, Ctrl+K --~ if _ctrl and not _shift and not _alt and _keycode == 75 then -- Ctrl+Win, Ctrl+L ##== |L|ine selection ==## if _ctrl and not _shift and not _alt and _keycode == 76 then editor:Home() editor:LineEndExtend() end -- Ctrl+Win, Ctrl+M --~ if _ctrl and not _shift and not _alt and _keycode == 77 then -- Ctrl+Win, Ctrl+N --~ if _ctrl and not _shift and not _alt and _keycode == 78 then -- Ctrl+Win, Ctrl+O --~ if _ctrl and not _shift and not _alt and _keycode == 79 then -- Ctrl+Win, Ctrl+P ##== |P|artial selection, expand selection to full word with only Wordcharacters ==## if _ctrl and not _shift and not _alt and _keycode == 80 then SetSelection(true) end -- Ctrl+Win, Ctrl+Q --~ if _ctrl and not _shift and not _alt and _keycode == 81 then -- Ctrl+Win, Ctrl+R ##== |R|un Selected Code ==## if _ctrl and not _shift and not _alt and _keycode == 82 then RunSelectedCode() end -- Ctrl+Win, Ctrl+S ##== Reload SciTE |S|tartup script ==## if _ctrl and not _shift and not _alt and _keycode == 83 then dofile( props["SciteDefaultHome"] .. "\\Lua\\SciTEStartup.lua" ) output:ClearAll() print('++> '..Clock()..' SciTE StartUp script reloaded.') end -- Ctrl+Win, Ctrl+T ##== |T|oggle adjacent characters ==## if _ctrl and not _shift and not _alt and _keycode == 84 then caret = editor.CurrentPos editor:SetSel(caret-1, caret) charLeft = editor:GetSelText() editor:SetSel(caret, caret+1) charRight = editor:GetSelText() editor:ReplaceSel(charLeft) editor:SetSel(caret-1, caret) editor:ReplaceSel(charRight) editor.CurrentPos = caret end -- Ctrl+Win, Ctrl+U ##== |U|nselect any selections ==## if _ctrl and not _shift and not _alt and _keycode == 85 then caret = editor.CurrentPos editor:SetSel(caret, caret) end -- Ctrl+Win, Ctrl+V --~ if _ctrl and not _shift and not _alt and _keycode == 86 then -- Ctrl+Win, Ctrl+W --~ if _ctrl and not _shift and not _alt and _keycode == 87 then -- Ctrl+Win, Ctrl+X --~ if _ctrl and not _shift and not _alt and _keycode == 88 then -- Ctrl+Win, Ctrl+Y --~ if _ctrl and not _shift and not _alt and _keycode == 89 then -- Ctrl+Win, Ctrl+Z ##== Run Testscript "LUA_TEST.lua" ==## Hiermit starte ich immer mein Lua-Testscript, da mit "Run" eine Ausführung nicht möglich ist if _ctrl and not _shift and not _alt and _keycode == 90 then dofile( props["Lua.User.Scripts.Path"] .. "\\LUA_TEST.lua" ) -- ich habe eine eigene Propertie definiert mit dem Pfad meiner Skripte end -- Ctrl+Win, Ctrl+0 ##== Print HotkeyList to console ==## if _ctrl and not _shift and not _alt and _keycode == 48 then GetHotkeyList() end -- Ctrl+Win, Ctrl+1 --~ if _ctrl and not _shift and not _alt and _keycode == 49 then -- Ctrl+Win, Ctrl+2 --~ if _ctrl and not _shift and not _alt and _keycode == 50 then -- Ctrl+Win, Ctrl+3 --~ if _ctrl and not _shift and not _alt and _keycode == 51 then -- Ctrl+Win, Ctrl+4 --~ if _ctrl and not _shift and not _alt and _keycode == 52 then -- Ctrl+Win, Ctrl+5 --~ if _ctrl and not _shift and not _alt and _keycode == 53 then -- Ctrl+Win, Ctrl+6 --~ if _ctrl and not _shift and not _alt and _keycode == 54 then -- Ctrl+Win, Ctrl+7 --~ if _ctrl and not _shift and not _alt and _keycode == 55 then -- Ctrl+Win, Ctrl+8 --~ if _ctrl and not _shift and not _alt and _keycode == 56 then -- Ctrl+Win, Ctrl+9 --~ if _ctrl and not _shift and not _alt and _keycode == 57 then -- Ctrl+Win, Ctrl+Backspace --~ if _ctrl and not _shift and not _alt and _keycode == 8 then -- ##== N U M P A D ==## -- Ctrl+Win, Ctrl+NUMPAD_0 --~ if _ctrl and not _shift and not _alt and _keycode == 96 then -- Ctrl+Win, Ctrl+NUMPAD_1 --~ if _ctrl and not _shift and not _alt and _keycode == 97 then -- Ctrl+Win, Ctrl+NUMPAD_2 --~ if _ctrl and not _shift and not _alt and _keycode == 98 then -- Ctrl+Win, Ctrl+NUMPAD_3 --~ if _ctrl and not _shift and not _alt and _keycode == 99 then -- Ctrl+Win, Ctrl+NUMPAD_4 --~ if _ctrl and not _shift and not _alt and _keycode == 100 then -- Ctrl+Win, Ctrl+NUMPAD_5 --~ if _ctrl and not _shift and not _alt and _keycode == 101 then -- Ctrl+Win, Ctrl+NUMPAD_6 --~ if _ctrl and not _shift and not _alt and _keycode == 102 then -- Ctrl+Win, Ctrl+NUMPAD_7 --~ if _ctrl and not _shift and not _alt and _keycode == 103 then -- Ctrl+Win, Ctrl+NUMPAD_8 --~ if _ctrl and not _shift and not _alt and _keycode == 104 then -- Ctrl+Win, Ctrl+NUMPAD_9 --~ if _ctrl and not _shift and not _alt and _keycode == 105 then -- Ctrl+Win, Ctrl+NUMPAD_Dot --~ if _ctrl and not _shift and not _alt and _keycode == 110 then -- Ctrl+Win, Ctrl+NUMPAD_Add --~ if _ctrl and not _shift and not _alt and _keycode == 107 then -- Ctrl+Win, Ctrl+NUMPAD_Sub --~ if _ctrl and not _shift and not _alt and _keycode == 109 then -- Ctrl+Win, Ctrl+NUMPAD_Mul --~ if _ctrl and not _shift and not _alt and _keycode == 106 then -- Ctrl+Win, Ctrl+NUMPAD_Div --~ if _ctrl and not _shift and not _alt and _keycode == 111 then -- ##== F - K e y s ==## -- Ctrl+Win, Ctrl+F1 --~ if _ctrl and not _shift and not _alt and _keycode == 112 then -- Ctrl+Win, Ctrl+F2 --~ if _ctrl and not _shift and not _alt and _keycode == 113 then -- Ctrl+Win, Ctrl+F3 --~ if _ctrl and not _shift and not _alt and _keycode == 114 then -- Ctrl+Win, Ctrl+F4 --~ if _ctrl and not _shift and not _alt and _keycode == 115 then -- Ctrl+Win, Ctrl+F5 --~ if _ctrl and not _shift and not _alt and _keycode == 116 then -- Ctrl+Win, Ctrl+F6 --~ if _ctrl and not _shift and not _alt and _keycode == 117 then -- Ctrl+Win, Ctrl+F7 --~ if _ctrl and not _shift and not _alt and _keycode == 118 then -- Ctrl+Win, Ctrl+F8 --~ if _ctrl and not _shift and not _alt and _keycode == 119 then -- Ctrl+Win, Ctrl+F9 --~ if _ctrl and not _shift and not _alt and _keycode == 120 then -- Ctrl+Win, Ctrl+F10 --~ if _ctrl and not _shift and not _alt and _keycode == 121 then -- Ctrl+Win, Ctrl+F11 --~ if _ctrl and not _shift and not _alt and _keycode == 122 then -- Ctrl+Win, Ctrl+F12 --~ if _ctrl and not _shift and not _alt and _keycode == 123 then fOwnMode = false -- avoids default processing return true end fOwnMode = false -- ##== MOVE LINES ==## -- Ctrl+Shift+ArrowUp ##== Move line/selected-lines Up ==## if _ctrl and _shift and not _alt and _keycode == 38 then editor:MoveSelectedLinesUp() end -- Ctrl+Shift+ArrowDown ##== Move line/selected-lines Down ==## if _ctrl and _shift and not _alt and _keycode == 40 then editor:MoveSelectedLinesDown() end -- ##== MOVE SELECTIONS IN LINE ==## -- Ctrl+Alt+ArrowUp ##== Move selection in line Up ==## if _ctrl and not _shift and _alt and _keycode == 38 then SelectionMoveV(true) end -- Ctrl+Alt+ArrowDown ##== Move selection in line Down ==## if _ctrl and not _shift and _alt and _keycode == 40 then SelectionMoveV(false) end -- Ctrl+Alt+ArrowLeft ##== Move selection in line to Left ==## if _ctrl and not _shift and _alt and _keycode == 37 then SelectionMoveH(true) end -- Ctrl+Alt+ArrowRight ##== Move selection in line to Right ==## if _ctrl and not _shift and _alt and _keycode == 39 then SelectionMoveH(false) end return nil end --> EditKey -------------------------------------------------------------------------