Тока вот одно не пойму - editor.RealToTab() получает и возвращает 0 или 1 бэйс индексы?
Code: Select all
local Indent = function (IndentByTabSize, Forward)
local ei = editor.GetInfo(nil);
local IndentSize = IndentByTabSize and ei.TabSize or 1
local IndentStr = IndentByTabSize and "\t" or " "
local line = ei.CurLine;
local loop = false;
if ei.BlockType ~= "BTYPE_NONE" then
local s = editor.GetString()
if s.SelStart ~= -1 then
loop = true;
line = ei.BlockStartLine;
end
end
editor.UndoRedo(nil, "EUR_BEGIN")
repeat
editor.SetPosition(nil, line, 0, -1, -1, 0, ei.Overtype)
local s = editor.GetString(nil, -1, 1)
if not s or (loop and ((s.SelStart == -1) or (s.SelStart == s.SelEnd))) then
break
end
local j = 1
while (string.sub(s.StringText, j, j)=="\t" or string.sub(s.StringText, j, j)==" ") and (j <= s.StringLength) do
j = j + 1
end
if (j>1 or Forward) and (j <= s.StringLength) then
local TabPos = editor.RealToTab(nil, -1, j) - 1
local x = math.floor(TabPos/IndentSize)
if ((TabPos%IndentSize) == 0) and not Forward then
x = x - 1
end
x = Forward and x + 1 or x
editor.SetString(nil, -1, string.sub(s.StringText, j), s.StringEOL)
if x then for i=0,x-1,1 do editor.InsertText(nil,IndentStr) end end
end
line = line + 1
until not loop
editor.SetPosition(nil, ei.CurLine, ei.CurPos, -1, ei.TopScreenLine, ei.LeftPos, ei.Overtype)
editor.UndoRedo(nil, "EUR_END")
end
Macro {
area="Editor"; key="ShiftTab"; flags="DisableOutput"; description="Indent right by tab size"; action = function()
Indent(true, true)
end;
}
Macro {
area="Editor"; key="ShiftBS"; flags="DisableOutput"; description="Indent left by tab size"; action = function()
Indent(true, false)
end;
}
И ещё вопрос, если поменять:
Code: Select all
editor.SetPosition(nil, line, 0, -1, -1, 0, ei.Overtype)
local s = editor.GetString(nil, -1, 0)
на
Code: Select all
local s = editor.GetString(nil, line, 1)
То editor.InsertText() будет вставлять текст не в начале строки а "где попало".
Т.е. логично бы было чтоб fast режим editor.GetString() выставлял бы и CurPos в 0.