Fixed screen buffer overlap for syntax highlighting

This commit is contained in:
Igor Timofeev 2019-02-09 13:23:37 +03:00
parent 5b2e4b2a11
commit 628e9f4012
3 changed files with 18 additions and 14 deletions

View File

@ -28,7 +28,7 @@ module.onTouch = function()
if text == placeholder then if text == placeholder then
screen.drawText(x, y, color, text) screen.drawText(x, y, color, text)
else else
GUI.highlightString(x, y, input.width - 2, 1, 2, GUI.LUA_SYNTAX_PATTERNS, GUI.LUA_SYNTAX_COLOR_SCHEME, text) GUI.highlightString(x, y, 1, 2, GUI.LUA_SYNTAX_PATTERNS, GUI.LUA_SYNTAX_COLOR_SCHEME, text)
end end
end end

View File

@ -31,7 +31,7 @@ input.historyEnabled = true
-- if text == input.placeholderText then -- if text == input.placeholderText then
-- screen.drawText(x, y, color, text) -- screen.drawText(x, y, color, text)
-- else -- else
-- GUI.highlightString(x, y, input.width - 2, 1, 2, GUI.LUA_SYNTAX_PATTERNS, GUI.LUA_SYNTAX_COLOR_SCHEME, text) -- GUI.highlightString(x, y, 1, 2, GUI.LUA_SYNTAX_PATTERNS, GUI.LUA_SYNTAX_COLOR_SCHEME, text)
-- end -- end
-- end -- end

View File

@ -1024,9 +1024,6 @@ local function codeViewDraw(codeView)
) )
end end
local oldDrawLimitX1, oldDrawLimitY1, oldDrawLimitX2, oldDrawLimitY2 = screen.getDrawLimit()
screen.setDrawLimit(codeView.codeAreaPosition, codeView.y, codeView.codeAreaPosition + codeView.codeAreaWidth - 1, codeView.y + codeView.height - 1)
if #codeView.selections > 0 then if #codeView.selections > 0 then
for selectionIndex = 1, #codeView.selections do for selectionIndex = 1, #codeView.selections do
y = codeView.y y = codeView.y
@ -1055,14 +1052,13 @@ local function codeViewDraw(codeView)
-- Code strings -- Code strings
y = codeView.y y = codeView.y
screen.setDrawLimit(codeView.codeAreaPosition + 1, y, codeView.codeAreaPosition + codeView.codeAreaWidth - 2, y + codeView.height - 1)
for i = codeView.fromLine, toLine do for i = codeView.fromLine, toLine do
if codeView.lines[i] then if codeView.lines[i] then
if codeView.syntaxHighlight then if codeView.syntaxHighlight then
GUI.highlightString(codeView.codeAreaPosition + 1, GUI.highlightString(
codeView.codeAreaPosition + 1,
y, y,
codeView.codeAreaWidth - 2,
codeView.fromSymbol, codeView.fromSymbol,
codeView.indentationWidth, codeView.indentationWidth,
patterns, patterns,
@ -1079,8 +1075,6 @@ local function codeViewDraw(codeView)
end end
end end
screen.setDrawLimit(oldDrawLimitX1, oldDrawLimitY1, oldDrawLimitX2, oldDrawLimitY2)
if #codeView.lines > codeView.height then if #codeView.lines > codeView.height then
codeView.verticalScrollBar.colors.background, codeView.verticalScrollBar.colors.foreground = colorScheme.scrollBarBackground, colorScheme.scrollBarForeground codeView.verticalScrollBar.colors.background, codeView.verticalScrollBar.colors.foreground = colorScheme.scrollBarBackground, colorScheme.scrollBarForeground
codeView.verticalScrollBar.minimumValue, codeView.verticalScrollBar.maximumValue, codeView.verticalScrollBar.value, codeView.verticalScrollBar.shownValueCount = 1, #codeView.lines, codeView.fromLine, codeView.height codeView.verticalScrollBar.minimumValue, codeView.verticalScrollBar.maximumValue, codeView.verticalScrollBar.value, codeView.verticalScrollBar.shownValueCount = 1, #codeView.lines, codeView.fromLine, codeView.height
@ -3687,11 +3681,21 @@ end
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
function GUI.highlightString(x, y, width, fromChar, indentationWidth, patterns, colorScheme, s) function GUI.highlightString(x, y, fromChar, indentationWidth, patterns, colorScheme, s)
fromChar = fromChar or 1 local stringLength, x1, y1, x2, y2 = unicode.len(s), screen.getDrawLimit()
local counter, symbols, colors, stringLength, bufferIndex, newFrameBackgrounds, newFrameForegrounds, newFrameSymbols, searchFrom, starting, ending = indentationWidth, {}, {}, unicode.len(s), screen.getIndex(x, y), screen.getNewFrameTables() fromChar = fromChar or 1
local toChar = math.min(stringLength, fromChar + width - 1) if x < x1 then
fromChar = fromChar + x1 - x
x = x1
end
local toChar, endX = stringLength, x + stringLength - 1
if endX > x2 then
toChar = toChar - endX + x2
end
local counter, symbols, colors, bufferIndex, newFrameBackgrounds, newFrameForegrounds, newFrameSymbols, searchFrom, starting, ending = indentationWidth, {}, {}, screen.getIndex(x, y), screen.getNewFrameTables()
-- Пидорасим на символы -- Пидорасим на символы
for i = fromChar, toChar do for i = fromChar, toChar do