From 252617baeff005f8fe4913516aa2899dd9d35b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Fri, 3 Nov 2023 01:21:44 +0100 Subject: [PATCH] Fix 'gambas' highlighting when 'CanRewrite' is FALSE. Fix highlighting recursion when 'CanRewrite' is TRUE. [GB.HIGHLIGHT] * BUG: Fix 'gambas' highlighting when 'CanRewrite' is FALSE. * BUG: Fix highlighting recursion when 'CanRewrite' is TRUE. * NEW: TextHighlighter: 'ToHTML()', 'ToANSI()' and 'Paint()' now take the 'CanRewrite' property into account. * NEW: Raise an error if we try to load 'gb.highlight' whereas 'gb.eval.highlight' is already loaded. --- comp/src/gb.highlight/.src/Main.module | 6 ++++-- comp/src/gb.highlight/.src/TextHighlighter.class | 10 +++++++--- comp/src/gb.highlight/.src/TextHighlighterTheme.class | 4 ++++ .../gb.highlight/.src/_TextHighlighter_Gambas.class | 2 ++ comp/src/gb.highlight/custom/CustomHighlighter.class | 1 + 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/comp/src/gb.highlight/.src/Main.module b/comp/src/gb.highlight/.src/Main.module index 6d82feb0c..f3bfbd65a 100644 --- a/comp/src/gb.highlight/.src/Main.module +++ b/comp/src/gb.highlight/.src/Main.module @@ -22,11 +22,13 @@ Public Sub Main() 'File.Save("~/test.html", TextHighlighter["sh"].ToHTML(File.Load("~/gambas/git/master/acinclude.m4"))) 'Print TextHighlighter["javascript"].ToANSI(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/javascript/selectr.js")) - With TextHighlighter["gambas"] + With TextHighlighter["webpage"] Print .Colors.Join() .CanRewrite = True 'Print .ToANSI(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/style/style-modern.css")) - Print .ToANSI(File.Load("~/gambas/git/master/comp/src/gb.desktop/.src/Desktop.class")) + 'Print .ToANSI(File.Load("~/gambas/git/master/comp/src/gb.desktop/.src/Desktop.class")) + 'Print .ToANSI(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/.src/Site/Dialog.webpage")) + File.Save("~/test.html", .ToHTML(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/.src/Site/Dialog.webpage"))) End With End diff --git a/comp/src/gb.highlight/.src/TextHighlighter.class b/comp/src/gb.highlight/.src/TextHighlighter.class index 39c544218..9e97ef7b8 100644 --- a/comp/src/gb.highlight/.src/TextHighlighter.class +++ b/comp/src/gb.highlight/.src/TextHighlighter.class @@ -65,7 +65,7 @@ Static Public Sub _init() Case "webpage" sName = ("Gambas Web Page") Case Else - sName = String.UCaseFirst(sKey) + sName = sKey End Select Register(sKey, sName) Next @@ -431,7 +431,11 @@ Private Sub HighlightLine(sLine As String) 'bCanRewrite = Me.CanRewrite 'Me.CanRewrite = False $aHighlight = Me.Run(sLine & "\n", $aState) - $sLine = sLine + If Me.CanRewrite Then + $sLine = Me.TextAfter + Else + $sLine = sLine + Endif 'Me.CanRewrite = bCanRewrite $aStyles = $hTheme._GetStyles() $iPos = 1 @@ -565,7 +569,7 @@ Public Sub ToHTML(Text As String, Optional Theme As TextHighlighterTheme) As Str Next - Return "" & aResult.Join("
\n") & "
" + Return "" & aResult.Join("
\n") & "
" End diff --git a/comp/src/gb.highlight/.src/TextHighlighterTheme.class b/comp/src/gb.highlight/.src/TextHighlighterTheme.class index b687c8bb6..b38b7c6ef 100644 --- a/comp/src/gb.highlight/.src/TextHighlighterTheme.class +++ b/comp/src/gb.highlight/.src/TextHighlighterTheme.class @@ -67,6 +67,10 @@ Static Public Sub _init() Dim sColor As String + If Component.IsLoaded("gb.eval.highlight") Then + Error.Raise("'gb.highlight' component is not compatible with 'gb.eval.highlight'.") + Endif + For Each sColor In ["Background", "Selection", "Current", "Breakpoint", "Highlight", "Normal", "Added", "Removed", "Error", "Comment", "Documentation", "Keyword", "Function", "Operator", "Symbol", "Number", "String", "Datatype", "Preprocessor", "Escape", "Constant"] _RegisterColor(sColor, "*") Next diff --git a/comp/src/gb.highlight/.src/_TextHighlighter_Gambas.class b/comp/src/gb.highlight/.src/_TextHighlighter_Gambas.class index 964831c9c..2228fa704 100644 --- a/comp/src/gb.highlight/.src/_TextHighlighter_Gambas.class +++ b/comp/src/gb.highlight/.src/_TextHighlighter_Gambas.class @@ -106,6 +106,8 @@ Public Sub _Analyze(Text As String, (State) As Byte[], Optional (MatchLimit) As bNewLine = False bGotLimit = True sTextAfter = Left(sTextAfter, -2) + Text = String.Left(Text, iPos) + iLenText = iPos Break Endif diff --git a/comp/src/gb.highlight/custom/CustomHighlighter.class b/comp/src/gb.highlight/custom/CustomHighlighter.class index 205521231..15581c6b5 100644 --- a/comp/src/gb.highlight/custom/CustomHighlighter.class +++ b/comp/src/gb.highlight/custom/CustomHighlighter.class @@ -175,6 +175,7 @@ Private Sub Include(iHighlight As Byte, sHighlight As String, bMatch As Boolean, hHighlight = TextHighlighter._Create(sHighlight) hHighlight.TextAfter = "" + hHighlight.CanRewrite = Me.CanRewrite iPosBefore = $iPos aHighlight = hHighlight._Analyze($sText, aState, bMatch, sLimit, ByRef $iPos)