--- luacheck_editor.lua Mon Jul 13 22:37:20 2015
+++ luacheck_editor.lua Tue Jul 14 19:25:43 2015
@@ -3,7 +3,7 @@
-- list options
local MaxHeight = 10
-local ListPos = "Bottom" --Top,Bottom,Max or nil
+local InitListPos = "Bottom" --Top,Bottom,Center
local AutoPos = true
local ConvertToAnsi = true
@@ -140,6 +140,32 @@
return newBreakKeysArr
end
+local function maximizable(list)
+ return list.nItems>list.nLines and list.nLines<list.MaxItems
+end
+local ListState = {
+ currPos = InitListPos;
+ prevPos = nil;
+ maxHght = false;
+ jump = function( self, to )
+ assert( self.currPos ~= self.prevPos )
+ if to == nil then -- ping-pong
+ local opposite = { ["Top"] = "Bottom", ["Bottom"] = "Top" }
+ to = ( self.currPos == "Center" ) and opposite[ self.prevPos ] or "Center"
+ end
+ if to ~= self.currPos then
+ self.prevPos = self.currPos
+ end
+ self.currPos = to
+ assert( self.currPos ~= self.prevPos )
+ end;
+ zoom = function( self, list )
+ if maximizable(list) then
+ self.maxHght = not self.maxHght
+ end
+ end;
+}
+
local function setPos(info) editor.SetPosition(nil,info); editor.Redraw() end
local function scrollEditor(dir)
local ei = editor.GetInfo()
@@ -169,9 +195,9 @@
local ei = editor.GetInfo()
local y = w.line-ei.TopScreenLine --calculated screen line of warning
local a,b = 0,ei.WindowSizeY --valid screen lines (a..b)
- if ListPos=="Top" then
- a = a+nLines+1
- elseif ListPos=="Bottom" then
+ if ListState.currPos=="Top" then
+ a = a+nLines+3
+ elseif ListState.currPos=="Bottom" then
b = b-nLines-3
end
TopScreenLine = (y<a or force_top) and math.max(w.line-a,1)
@@ -187,9 +213,6 @@
setPos(bak_pos)
end
end
-local function maximizable(list)
- return list.nItems>list.nLines and list.nLines<list.MaxItems
-end
local bKeys = expandBreakKeys {
{BreakKey="C+UP C+NUMPAD8",action=function() scrollEditor(-1) end},
{BreakKey="C+DOWN C+NUMPAD2",action=function() scrollEditor(1) end},
@@ -203,15 +226,11 @@
{BreakKey="C+PRIOR C+NUMPAD9",action=function(w,list)
if w.prev_line then gotoWarning({line=w.prev_line,column=w.prev_column,name=w.name},list.nLines) end
end},
- {BreakKey="C+HOME NUMPAD7", action=function() ListPos = "Top" end},
- {BreakKey="C+END NUMPAD1", action=function() ListPos = "Bottom" end},
- {BreakKey="NUMPAD4", action=function(_,list)
- ListPos = not ListPos and (maximizable(list) and "Max" or ListPos)
- end},
- {BreakKey="F5 CLEAR", action=function(_,list)
- local next = {["Top"]="Bottom",["Bottom"]=false,[false]=maximizable(list) and "Max" or "Top",["Max"]="Top"}
- ListPos = next[ListPos]
- end},
+ {BreakKey="C+HOME NUMPAD7", action=function() ListState:jump( "Top" ) end},
+ {BreakKey="C+END NUMPAD1", action=function() ListState:jump( "Bottom" ) end},
+ {BreakKey=" NUMPAD4", action=function() ListState:jump( "Center" ) end},
+ {BreakKey=" CLEAR", action=function() ListState:jump(--[[auto]]) end},
+ {BreakKey="F5" , action=function(_,list) ListState:zoom(list) end},
{BreakKey="ADD", action=function() editor.AddSessionBookmark() end},
{BreakKey="CS+1 CS+2 CS+3 CS+4 CS+5 CS+6 CS+7 CS+8 CS+9 CS+0 C+1 C+2 C+3 C+4 C+5 C+6 C+7 C+8 C+9 C+0",keys=true},
{BreakKey="F1", action=showHelp},
@@ -265,14 +284,14 @@
Props.X = maxlen<xSize-4 and (xSize-maxlen)/2-2 or -1
local nItems = #Items
local nLines = math.min(nItems,MaxHeight,MaxItems)
- if not ListPos or ListPos=="Max" or nLines==MaxItems then
+ if ListState.currPos=="Center" or ListState.maxHght or nLines==MaxItems then
Props.X,Props.Y = -1,-1
- elseif ListPos=="Top" then
- Props.Y = -2
- elseif ListPos=="Bottom" then
+ elseif ListState.currPos=="Top" then
+ Props.Y = 0
+ elseif ListState.currPos=="Bottom" then
Props.Y = MaxItems-nLines>0 and MaxItems-nLines+2 or -1
end
- Props.MaxHeight = ListPos=="Max" and 0 or MaxHeight
+ Props.MaxHeight = ListState.maxHght and 0 or MaxHeight
-- show list
Props.SelectIndex = pos
local item