Fix background highlighting of included highlighters.
[GB.HIGHLIGHT] * BUG: Fix background highlighting of included highlighters.
This commit is contained in:
parent
173e9a699d
commit
a1db0cf233
7 changed files with 69 additions and 50 deletions
|
@ -38,16 +38,14 @@ Public Sub Compile(hState As CState)
|
|||
|
||||
CState.Print("sWord = Match(" & Quote($sFrom) & ")")
|
||||
CState.Print("If Not sWord Then Goto " & hState.GetNextLabel())
|
||||
CState.Print("Imbricate(" & CStr($iInclude) & ")")
|
||||
CState.Print("SetIncludeHighlight(" & CStr($iInclude) & ")")
|
||||
hState.Forward("String.Len(sWord)")
|
||||
CState.Print("Imbricate(0)")
|
||||
|
||||
Else
|
||||
|
||||
CState.IfStartWith($sFrom, hState.GetNextLabel())
|
||||
CState.Print("Imbricate(" & CStr($iInclude) & ")")
|
||||
CState.Print("SetIncludeHighlight(" & CStr($iInclude) & ")")
|
||||
hState.Forward(String.Len($sFrom))
|
||||
CState.Print("Imbricate(0)")
|
||||
|
||||
Endif
|
||||
|
||||
|
@ -56,16 +54,16 @@ Public Sub Compile(hState As CState)
|
|||
If CState.IsRegExp(ByRef $sTo) Then
|
||||
|
||||
CState.Print("If Include(" & CStr($iInclude) & ", " & Quote($sInclude) & ", True, " & Quote($sTo) & ", aState) Then Return")
|
||||
CState.Print("Imbricate(" & CStr($iInclude) & ")")
|
||||
CState.Print("SetIncludeHighlight(" & CStr($iInclude) & ")")
|
||||
hState.Forward("String.Len(Match(" & Quote($sTo) & "))")
|
||||
CState.Print("Imbricate(0)")
|
||||
CState.Print("SetIncludeHighlight(Me._IncludeHighlight)")
|
||||
|
||||
Else
|
||||
|
||||
CState.Print("If Include(" & CStr($iInclude) & ", " & Quote($sInclude) & ", False, " & Quote($sTo) & ", aState) Then Return")
|
||||
CState.Print("Imbricate(" & CStr($iInclude) & ")")
|
||||
CState.Print("SetIncludeHighlight(" & CStr($iInclude) & ")")
|
||||
hState.Forward(String.Len($sTo))
|
||||
CState.Print("Imbricate(0)")
|
||||
CState.Print("SetIncludeHighlight(Me._IncludeHighlight)")
|
||||
|
||||
Endif
|
||||
|
||||
|
|
|
@ -430,6 +430,12 @@ Static Public Sub GetKeywords() As String
|
|||
|
||||
End
|
||||
|
||||
Static Public Sub GetInclude(sInclude As String) As Integer
|
||||
|
||||
Try Return $cInclude[sInclude]
|
||||
|
||||
End
|
||||
|
||||
Static Public Sub AddInclude(sInclude As String) As Integer
|
||||
|
||||
Dim iInclude As Integer
|
||||
|
|
|
@ -17,6 +17,7 @@ Public TextAfter As String
|
|||
Public LengthAdded As Integer
|
||||
Public Limit As Boolean
|
||||
Public Comment As Boolean
|
||||
Public _IncludeHighlight As Integer
|
||||
|
||||
Property Read Key As String
|
||||
Property Read Name As String
|
||||
|
@ -24,8 +25,6 @@ Property Read Keywords As String[]
|
|||
Property Read Colors As String[]
|
||||
|
||||
Private $iPos As Integer
|
||||
Private $iLevel As Integer
|
||||
Private $aInclude As Byte[]
|
||||
Private $iInclude As Integer
|
||||
Private $iIndex As Integer
|
||||
Private $hStyle As TextHighlighterStyle
|
||||
|
@ -185,7 +184,7 @@ Public Sub _Analyze((Text) As String, (State) As Byte[], Optional (MatchLimit) A
|
|||
|
||||
End
|
||||
|
||||
Static Public Sub _Add(aHighlight As Byte[], iState As Byte, iCount As Integer)
|
||||
Public Sub _Add(aHighlight As Byte[], iState As Byte, iCount As Integer)
|
||||
|
||||
Dim iMax As Integer
|
||||
|
||||
|
@ -403,21 +402,10 @@ Catch
|
|||
|
||||
End
|
||||
|
||||
Private Sub GetIncludeColor(iInclude As Integer) As Integer
|
||||
|
||||
Dim iHue As Integer
|
||||
|
||||
iHue = [60, 0, 210, 120, 30, 270][iInclude Mod 6]
|
||||
Return Color.HSV(iHue, 32, 255)
|
||||
|
||||
End
|
||||
|
||||
Private Sub HighlightStart(hTheme As TextHighlighterTheme)
|
||||
|
||||
$hTheme = hTheme
|
||||
If Not $hTheme Then $hTheme = New TextHighlighterTheme
|
||||
$iLevel = 0
|
||||
$aInclude = New Byte[]
|
||||
$iInclude = 0
|
||||
$iBackground = Color.Default
|
||||
$aState = New Byte[]
|
||||
|
@ -464,15 +452,15 @@ TRY_AGAIN:
|
|||
$iIndex += 2
|
||||
|
||||
If iLen = 0 Then
|
||||
If iState Then
|
||||
$aInclude.Push($iInclude)
|
||||
$iInclude = iState
|
||||
Inc $iLevel
|
||||
Else
|
||||
$iInclude = $aInclude.Pop()
|
||||
Dec $iLevel
|
||||
Endif
|
||||
$iBackground = GetIncludeColor($iInclude)
|
||||
' If iState Then
|
||||
' $aInclude.Push($iInclude)
|
||||
' $iInclude = iState
|
||||
' Inc $iLevel
|
||||
' Else
|
||||
' $iInclude = $aInclude.Pop()
|
||||
' Dec $iLevel
|
||||
' Endif
|
||||
$iBackground = $hTheme.GetIncludeColor(iState)
|
||||
Goto TRY_AGAIN
|
||||
Endif
|
||||
|
||||
|
@ -541,7 +529,7 @@ Public Sub ToHTML(Text As String, Optional Theme As TextHighlighterTheme) As Str
|
|||
Endif
|
||||
|
||||
sStyle = ""
|
||||
If $iLevel Then sStyle &= "background-color:" & Color.ToHTML($iBackground) & ";"
|
||||
If $iBackground <> Color.Default Then sStyle &= "background-color:" & Color.ToHTML($iBackground) & ";"
|
||||
If $hStyle.Color Then sStyle &= "color:" & Color.ToHTML($hStyle.Color) & ";"
|
||||
If $hStyle.Dotted Then sStyle &= "text-decoration:underline dotted;"
|
||||
|
||||
|
|
|
@ -11,8 +11,10 @@ Static Private $cColorIndex As New Collection
|
|||
Static Private $cColorsByHighlighter As New Collection
|
||||
|
||||
Property Settings As String
|
||||
Property Read Dark As Boolean
|
||||
|
||||
Private $cStyles As New Collection
|
||||
Private $aStyles As TextHighlighterStyle[]
|
||||
|
||||
Static Private $cDefault As New Collection
|
||||
|
||||
|
@ -322,25 +324,23 @@ End
|
|||
|
||||
Public Sub _GetStyles() As TextHighlighterStyle[]
|
||||
|
||||
Static aStyles As TextHighlighterStyle[]
|
||||
|
||||
Dim hStyle As TextHighlighterStyle
|
||||
|
||||
If $bStylesModified Or If Not aStyles Then
|
||||
If $bStylesModified Or If Not $aStyles Then
|
||||
|
||||
aStyles = New TextHighlighterStyle[]
|
||||
aStyles.Add($cStyles["Normal"])
|
||||
$aStyles = New TextHighlighterStyle[]
|
||||
$aStyles.Add($cStyles["Normal"])
|
||||
For Each $cColorIndex
|
||||
hStyle = $cStyles[$cColorIndex.Key]
|
||||
If Not hStyle Then hStyle = New TextHighlighterStyle
|
||||
aStyles.Add(hStyle)
|
||||
$aStyles.Add(hStyle)
|
||||
Next
|
||||
|
||||
$bStylesModified = False
|
||||
|
||||
Endif
|
||||
|
||||
Return aStyles
|
||||
Return $aStyles
|
||||
|
||||
End
|
||||
|
||||
|
@ -359,3 +359,28 @@ Static Public Sub _GetColorName(sKey As String) As String
|
|||
Return sName
|
||||
|
||||
End
|
||||
|
||||
Public Sub GetIncludeColor(Include As Integer) As Integer
|
||||
|
||||
Dim iHue As Integer
|
||||
Dim iColor As Integer
|
||||
|
||||
If Include = 0 Then Return Color.Default
|
||||
iHue = [60, 30, 0, 45, 15][(Include - 1) Mod 5]
|
||||
If Me.Dark Then
|
||||
iColor = Color.HSV(iHue, 240, 128)
|
||||
Else
|
||||
iColor = Color.HSV(iHue, 32, 255)
|
||||
Endif
|
||||
Return iColor
|
||||
|
||||
End
|
||||
|
||||
Private Function Dark_Read() As Boolean
|
||||
|
||||
Dim iBg As Integer
|
||||
|
||||
iBg = Me["Background"].Color
|
||||
If Color[iBg].Value < 128 Then Return True
|
||||
|
||||
End
|
||||
|
|
|
@ -105,7 +105,7 @@ Public Sub _Analyze(Text As String, (State) As Byte[], Optional (MatchLimit) As
|
|||
If Limit And If sSym Begins Limit Then
|
||||
If Not bRewrite Then
|
||||
If iPos < Highlight.Positions[I] Then
|
||||
TextHighlighter._Add(aHighlight, 0, Highlight.Positions[I] - iPos)
|
||||
Me._Add(aHighlight, 0, Highlight.Positions[I] - iPos)
|
||||
iPos = Highlight.Positions[I]
|
||||
Endif
|
||||
Endif
|
||||
|
@ -118,12 +118,12 @@ Public Sub _Analyze(Text As String, (State) As Byte[], Optional (MatchLimit) As
|
|||
Endif
|
||||
|
||||
If iPos < Highlight.Positions[I] Then
|
||||
TextHighlighter._Add(aHighlight, 0, Highlight.Positions[I] - iPos)
|
||||
Me._Add(aHighlight, 0, Highlight.Positions[I] - iPos)
|
||||
iPos = Highlight.Positions[I]
|
||||
Endif
|
||||
|
||||
iLen = String.Len(sSym)
|
||||
TextHighlighter._Add(aHighlight, $cState[Highlight.Types[I]], iLen)
|
||||
Me._Add(aHighlight, $cState[Highlight.Types[I]], iLen)
|
||||
iPos += iLen
|
||||
|
||||
Next
|
||||
|
@ -135,7 +135,7 @@ Public Sub _Analyze(Text As String, (State) As Byte[], Optional (MatchLimit) As
|
|||
Endif
|
||||
|
||||
If iPos < iLen Then
|
||||
TextHighlighter._Add(aHighlight, 0, iLen - iPos)
|
||||
Me._Add(aHighlight, 0, iLen - iPos)
|
||||
iPos = iLen
|
||||
Endif
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ Private Sub Init(sText As String)
|
|||
|
||||
End
|
||||
|
||||
Private Sub Imbricate(iType As Byte)
|
||||
Private Sub SetIncludeHighlight(iType As Byte)
|
||||
|
||||
$aHighlight.Add(iType)
|
||||
$aHighlight.Add(0)
|
||||
|
@ -51,7 +51,7 @@ End
|
|||
Private Sub Forward(iState As Byte, Optional N As Integer = 1)
|
||||
|
||||
If $bEof Then Error.Raise("End of file")
|
||||
TextHighlighter._Add($aHighlight, iState, N)
|
||||
Me._Add($aHighlight, iState, N)
|
||||
$iPos += N
|
||||
$bEof = $iPos > $iLen
|
||||
|
||||
|
@ -167,15 +167,15 @@ Private Sub Include(iHighlight As Byte, sHighlight As String, bMatch As Boolean,
|
|||
aState.Remove(0)
|
||||
|
||||
' We enter a new imbricated state
|
||||
SetIncludeHighlight(iHighlight)
|
||||
If aState.Count = 0 Then
|
||||
aState.Add(0)
|
||||
$aHighlight.Add(iHighlight)
|
||||
$aHighlight.Add(0)
|
||||
Endif
|
||||
|
||||
hHighlight = TextHighlighter._Create(sHighlight)
|
||||
hHighlight.TextAfter = ""
|
||||
hHighlight.CanRewrite = Me.CanRewrite
|
||||
hHighlight._IncludeHighlight = iHighlight
|
||||
iPosBefore = $iPos
|
||||
|
||||
aHighlight = hHighlight._Analyze($sText, aState, bMatch, sLimit, ByRef $iPos)
|
||||
|
@ -197,10 +197,12 @@ Private Sub Include(iHighlight As Byte, sHighlight As String, bMatch As Boolean,
|
|||
If $bEof Then Return True
|
||||
|
||||
' We left the imbricated state
|
||||
$aHighlight.Add(0)
|
||||
$aHighlight.Add(0)
|
||||
'$aHighlight.Add(0)
|
||||
'$aHighlight.Add(0)
|
||||
aState.Pop()
|
||||
|
||||
SetIncludeHighlight(Me._IncludeHighlight)
|
||||
|
||||
End
|
||||
|
||||
Public Sub _Analyze(Text As String, State As Byte[], Optional MatchLimit As Boolean, Limit As String, ByRef iPos As Integer) As Byte[]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
root{Preprocessor}:
|
||||
match "<%/%>"
|
||||
comment.webpage{Preprocessor}:
|
||||
comment.webpage{Documentation}:
|
||||
from <%-- to --%>
|
||||
webpage{Preprocessor}:
|
||||
from << to >>
|
||||
|
|
Loading…
Reference in a new issue