WordsToHighlight = B4XCollections.CreateSet2(Array("AAAA", "eflkw"))
BBCodeView1.Text = $"fk we;lfk ;lwe kf;lw elk;fw ef
wefjlk wejflkw ejlkfwj [plain]eflkw[/plain] efjlkwe fjklwe f
fjskldfj sldkfj slkdf jslkdf jlksdjf lksdjf lksd fjlskd fjlksdf jlskdf sdf sdlkfj skldf [plain]AAAA[/plain] sdf sd
fsd
fs
dfs jdklflsj dlfkjs dlfk sjdlfk "$
AddBackgroundPanels
End Sub
Sub MainForm_Resize (Width As Double, Height As Double)
AddBackgroundPanels
End Sub
Private Sub AddBackgroundPanels
For Each x As B4XView In BBCodeView1.sv.ScrollViewInnerPanel.GetAllViewsRecursive
If x.Tag = "background" Then
x.RemoveViewFromParent
End If
Next
Dim scale As Float = TextEngine.mScale
For Each line As BCTextLine In BBCodeView1.Paragraph.TextLines
For Each un As BCUnbreakableText In line.Unbreakables
For Each s As BCSingleStyleSection In un.SingleStyleSections
If WordsToHighlight.Contains(s.Run.Text) Then
Dim pnl As B4XView = xui.CreatePanel("")
pnl.Color = 0xFF00D2FF
pnl.Tag = "background"
BBCodeView1.sv.ScrollViewInnerPanel.AddView(pnl, BBCodeView1.Padding.Left + s.AbsoluteStartX / scale - 2dip, _
BBCodeView1.Padding.Top + (line.BaselineY - s.MaxHeightAboveBaseLine) / scale - 2dip, _
s.Width / scale + 4dip, (s.MaxHeightBelowBaseLine + s.MaxHeightAboveBaseLine) / scale + 4dip)
pnl.SendToBack
End If
Next
Next
Next
End Sub