-- TIME_STAMP 2016-01-25 22:32:53 ConvertTabHit = EventClass:new(Common) local iTabsize = tonumber(props['tabsize']) local tDiff = {} for i = iTabsize, 1, -1 do table.insert(tDiff, i) end function ConvertTabHit:OnKey(_keycode, _shift, _ctrl, _alt) if not (tonumber(props['convert.tabs.to.spaces']) == 1) and (_keycode ~= 8 or _keycode ~= 9) then return nil end if not _shift and not _ctrl and not _alt then local iPosCurrent = editor.CurrentPos local iCol = editor.Column[iPosCurrent] if _keycode == 8 then -- Backspace local iPosLeft = iPosCurrent - (iCol % iTabsize) if iPosLeft == iPosCurrent then iPosLeft = iPosCurrent - iTabsize end editor:SetSelection(iPosLeft, iPosCurrent) if editor:GetSelText():gsub('[%s%t]*', '') == '' then editor:BeginUndoAction() editor:ReplaceSel('') editor:EndUndoAction() return true end editor.CurrentPos = iPosCurrent return nil end if _keycode == 9 then -- Tab editor:BeginUndoAction() editor:insert(iPosCurrent, (' '):rep(tDiff[(iCol % iTabsize)+1])) editor:LineEnd() editor:EndUndoAction() return true end end end