From 628e9f401262b163c2adbb0986a4bc31aeb2cadf Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Sat, 9 Feb 2019 13:23:37 +0300 Subject: [PATCH] Fixed screen buffer overlap for syntax highlighting --- Applications/Control.app/Modules/1.lua | 2 +- Applications/Lua.app/Main.lua | 2 +- Libraries/GUI.lua | 28 +++++++++++++++----------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Applications/Control.app/Modules/1.lua b/Applications/Control.app/Modules/1.lua index aa169762..ba0c3dd6 100644 --- a/Applications/Control.app/Modules/1.lua +++ b/Applications/Control.app/Modules/1.lua @@ -28,7 +28,7 @@ module.onTouch = function() if text == placeholder then screen.drawText(x, y, color, text) 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 diff --git a/Applications/Lua.app/Main.lua b/Applications/Lua.app/Main.lua index d95a4407..bb3d5e26 100644 --- a/Applications/Lua.app/Main.lua +++ b/Applications/Lua.app/Main.lua @@ -31,7 +31,7 @@ input.historyEnabled = true -- if text == input.placeholderText then -- screen.drawText(x, y, color, text) -- 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 diff --git a/Libraries/GUI.lua b/Libraries/GUI.lua index 01dfadbb..4973e636 100755 --- a/Libraries/GUI.lua +++ b/Libraries/GUI.lua @@ -1024,9 +1024,6 @@ local function codeViewDraw(codeView) ) 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 for selectionIndex = 1, #codeView.selections do y = codeView.y @@ -1055,14 +1052,13 @@ local function codeViewDraw(codeView) -- Code strings y = codeView.y - screen.setDrawLimit(codeView.codeAreaPosition + 1, y, codeView.codeAreaPosition + codeView.codeAreaWidth - 2, y + codeView.height - 1) for i = codeView.fromLine, toLine do if codeView.lines[i] then if codeView.syntaxHighlight then - GUI.highlightString(codeView.codeAreaPosition + 1, + GUI.highlightString( + codeView.codeAreaPosition + 1, y, - codeView.codeAreaWidth - 2, codeView.fromSymbol, codeView.indentationWidth, patterns, @@ -1079,8 +1075,6 @@ local function codeViewDraw(codeView) end end - screen.setDrawLimit(oldDrawLimitX1, oldDrawLimitY1, oldDrawLimitX2, oldDrawLimitY2) - if #codeView.lines > codeView.height then 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 @@ -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) + local stringLength, x1, y1, x2, y2 = unicode.len(s), screen.getDrawLimit() + fromChar = fromChar or 1 - - local counter, symbols, colors, stringLength, bufferIndex, newFrameBackgrounds, newFrameForegrounds, newFrameSymbols, searchFrom, starting, ending = indentationWidth, {}, {}, unicode.len(s), screen.getIndex(x, y), screen.getNewFrameTables() - 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