mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Update syntax highlighting
This commit is contained in:
parent
57972d07cb
commit
699f5a4843
1 changed files with 23 additions and 20 deletions
|
@ -728,33 +728,36 @@ await Task.Run(() =>
|
|||
|
||||
private void CustomUploaderSyntaxHighlight(RichTextBox rtb)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(rtb.Text))
|
||||
string text = rtb.Text;
|
||||
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
CustomUploaderParser parser = new CustomUploaderParser();
|
||||
parser.SkipSyntaxParse = true;
|
||||
parser.Parse(rtb.Text);
|
||||
int start = rtb.SelectionStart;
|
||||
int length = rtb.SelectionLength;
|
||||
rtb.BeginUpdate();
|
||||
|
||||
if (parser.SyntaxInfoList != null)
|
||||
rtb.SelectionStart = 0;
|
||||
rtb.SelectionLength = rtb.TextLength;
|
||||
rtb.SelectionColor = rtb.ForeColor;
|
||||
|
||||
CustomUploaderSyntaxParser parser = new CustomUploaderSyntaxParser();
|
||||
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
int start = rtb.SelectionStart;
|
||||
int length = rtb.SelectionLength;
|
||||
rtb.BeginUpdate();
|
||||
char c = text[i];
|
||||
|
||||
rtb.SelectionStart = 0;
|
||||
rtb.SelectionLength = rtb.TextLength;
|
||||
rtb.SetFontRegular();
|
||||
|
||||
foreach (CustomUploaderSyntaxInfo syntaxInfo in parser.SyntaxInfoList)
|
||||
if (c == parser.SyntaxStart || c == parser.SyntaxEnd || c == parser.SyntaxParameterStart ||
|
||||
c == parser.SyntaxParameterDelimiter || c == parser.SyntaxEscape)
|
||||
{
|
||||
rtb.SelectionStart = syntaxInfo.StartPosition;
|
||||
rtb.SelectionLength = syntaxInfo.Length;
|
||||
rtb.SetFontBold();
|
||||
rtb.SelectionStart = i;
|
||||
rtb.SelectionLength = 1;
|
||||
rtb.SelectionColor = Color.FromArgb(0, 255, 0);
|
||||
}
|
||||
|
||||
rtb.SelectionStart = start;
|
||||
rtb.SelectionLength = length;
|
||||
rtb.EndUpdate();
|
||||
}
|
||||
|
||||
rtb.SelectionStart = start;
|
||||
rtb.SelectionLength = length;
|
||||
rtb.EndUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue