LuaWriter. Made ColorComments, ColorStrings and ColorLongStrings (wich is now called AddComments, AddStrings and AddLongStrings respectively) will no longer search symbols in the textbox, instead on a copy of it that is saved in a string variable.
This commit is contained in:
parent
38723f8786
commit
05b107ed49
|
@ -89,9 +89,9 @@ namespace BizHawk.MultiClient
|
||||||
AddKeyWords();
|
AddKeyWords();
|
||||||
AddLibraries();
|
AddLibraries();
|
||||||
AddSymbols();
|
AddSymbols();
|
||||||
ColorComments();
|
AddComments();
|
||||||
ColorStrings();
|
AddStrings();
|
||||||
ColorLongStrings();
|
AddLongStrings();
|
||||||
|
|
||||||
ColorText();
|
ColorText();
|
||||||
|
|
||||||
|
@ -99,51 +99,48 @@ namespace BizHawk.MultiClient
|
||||||
ProcessingText = false;
|
ProcessingText = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ColorLongStrings()
|
private void AddLongStrings()
|
||||||
{
|
{
|
||||||
int firstBracket = LuaText.Find("["), secondBracket, ending;
|
string temp = LuaText.Text;
|
||||||
|
int firstBracket = temp.IndexOf("["), secondBracket, ending;
|
||||||
while (firstBracket >= 0)
|
while (firstBracket >= 0)
|
||||||
{
|
{
|
||||||
ending = 0;
|
ending = 0;
|
||||||
if (firstBracket > 1 && LuaText.Text.Substring(firstBracket - 2, 2) == "--")
|
if (firstBracket > 1 && temp.Substring(firstBracket - 2, 2) == "--")
|
||||||
{
|
{
|
||||||
firstBracket = LuaText.Find("[", firstBracket + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
firstBracket = temp.IndexOf("[", firstBracket + 1, temp.Length - firstBracket - 1);
|
||||||
if (firstBracket == LuaText.Text.Length - 1)
|
if (firstBracket == temp.Length - 1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (firstBracket != LuaText.Text.Length - 1)
|
else if (firstBracket != temp.Length - 1)
|
||||||
{
|
{
|
||||||
secondBracket = LuaText.Find("[", firstBracket + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
secondBracket = temp.IndexOf("[", firstBracket + 1, temp.Length - firstBracket - 1);
|
||||||
if (secondBracket >= 0 && IsLongString(LuaText.Text.Substring(firstBracket, secondBracket - firstBracket + 1)))
|
if (secondBracket >= 0 && IsLongString(temp.Substring(firstBracket, secondBracket - firstBracket + 1)))
|
||||||
{
|
{
|
||||||
if (secondBracket + 1 == LuaText.Text.Length)
|
if (secondBracket + 1 == temp.Length)
|
||||||
ending = LuaText.Text.Length - 1;
|
ending = temp.Length - 1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string temp = GetLongStringClosingBracket(LuaText.Text.Substring(firstBracket, secondBracket - firstBracket + 1));
|
string tempBracket = GetLongStringClosingBracket(temp.Substring(firstBracket, secondBracket - firstBracket + 1));
|
||||||
ending = LuaText.Find(temp, secondBracket + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
ending = temp.IndexOf(tempBracket, secondBracket + 1);
|
||||||
if (ending < 0)
|
if (ending < 0)
|
||||||
ending = LuaText.Text.Length;
|
ending = temp.Length;
|
||||||
else
|
else
|
||||||
ending += temp.Length - 1;
|
ending += tempBracket.Length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaText.Select(firstBracket, ending - firstBracket + 1);
|
//Validate if such text is not part of a comment
|
||||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaStringColor);
|
AddPosition(firstBracket, ending - firstBracket + 1, Global.Config.LuaStringColor, Global.Config.LuaStringBold);
|
||||||
if(Global.Config.LuaStringBold)
|
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Bold);
|
|
||||||
else
|
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Regular);
|
|
||||||
|
|
||||||
if (ending < LuaText.Text.Length - 1)
|
if (ending < temp.Length - 1)
|
||||||
firstBracket = LuaText.Find("[", ending + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
firstBracket = temp.IndexOf("[", ending + 1, temp.Length - ending - 1);
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(secondBracket >= 0 && secondBracket != LuaText.Text.Length - 1)
|
if (secondBracket >= 0 && secondBracket != temp.Length - 1)
|
||||||
firstBracket = LuaText.Find("[", secondBracket, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
firstBracket = temp.IndexOf("[", secondBracket, temp.Length - secondBracket - 1);
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -194,6 +191,7 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
while (selection >= 0)
|
while (selection >= 0)
|
||||||
{
|
{
|
||||||
|
//Validate if such text is not part of a string or comment
|
||||||
AddPosition(selection, 1, Global.Config.LuaSymbolColor, Global.Config.LuaSymbolBold);
|
AddPosition(selection, 1, Global.Config.LuaSymbolColor, Global.Config.LuaSymbolBold);
|
||||||
|
|
||||||
currPos = selection + 1;
|
currPos = selection + 1;
|
||||||
|
@ -205,41 +203,42 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ColorStrings()
|
private void AddStrings()
|
||||||
{
|
{
|
||||||
|
string temp = LuaText.Text;
|
||||||
int firstMark, opening, ending, endLine;
|
int firstMark, opening, ending, endLine;
|
||||||
|
|
||||||
char[] chars = { '"', '\'' };
|
char[] chars = { '"', '\'' };
|
||||||
foreach (char mark in chars)
|
foreach (char mark in chars)
|
||||||
{
|
{
|
||||||
firstMark = LuaText.Find(mark.ToString());
|
firstMark = temp.IndexOf(mark.ToString());
|
||||||
while (firstMark >= 0)
|
while (firstMark >= 0)
|
||||||
{
|
{
|
||||||
if (LuaText.SelectionColor.ToArgb() != Global.Config.LuaCommentColor)
|
if (LuaText.SelectionColor.ToArgb() != Global.Config.LuaCommentColor)
|
||||||
{
|
{
|
||||||
opening = firstMark;
|
opening = firstMark;
|
||||||
if (LuaText.GetLineFromCharIndex(opening) + 1 == LuaText.Lines.Count())
|
if (LuaText.GetLineFromCharIndex(opening) + 1 == LuaText.Lines.Count())
|
||||||
endLine = LuaText.Text.Length - 1;
|
endLine = temp.Length - 1;
|
||||||
else
|
else
|
||||||
endLine = LuaText.GetFirstCharIndexFromLine(LuaText.GetLineFromCharIndex(opening) + 1) - 1;
|
endLine = LuaText.GetFirstCharIndexFromLine(LuaText.GetLineFromCharIndex(opening) + 1) - 1;
|
||||||
|
|
||||||
ending = 0;
|
ending = 0;
|
||||||
|
|
||||||
if (opening != LuaText.Text.Length - 1)
|
if (opening != temp.Length - 1)
|
||||||
{
|
{
|
||||||
if (opening + 1 != endLine)
|
if (opening + 1 != endLine)
|
||||||
{
|
{
|
||||||
ending = LuaText.Find(mark.ToString(), opening + 1, endLine, RichTextBoxFinds.MatchCase);
|
ending = temp.IndexOf(mark, opening + 1, endLine - opening + 1);
|
||||||
if (ending > 0)
|
if (ending > 0)
|
||||||
{
|
{
|
||||||
while (ending > 0)
|
while (ending > 0)
|
||||||
{
|
{
|
||||||
if (!IsThisPartOfTheString(LuaText.Text.Substring(opening, ending - opening + 1)))
|
if (!IsThisPartOfTheString(temp.Substring(opening, ending - opening + 1)))
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
ending++;
|
ending++;
|
||||||
|
|
||||||
ending = LuaText.Find(mark.ToString(), ending, endLine, RichTextBoxFinds.MatchCase);
|
ending = temp.IndexOf(mark, ending, endLine - opening + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -251,27 +250,23 @@ namespace BizHawk.MultiClient
|
||||||
else
|
else
|
||||||
ending = endLine;
|
ending = endLine;
|
||||||
|
|
||||||
if (opening != LuaText.Text.Length)
|
if (opening != temp.Length)
|
||||||
{
|
{
|
||||||
LuaText.Select(opening, ending - opening + 1);
|
//Validate if such text is not part of a comment
|
||||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaStringColor);
|
AddPosition(opening, ending - opening + 1, Global.Config.LuaStringColor, Global.Config.LuaStringBold);
|
||||||
if (Global.Config.LuaStringBold)
|
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Bold);
|
|
||||||
else
|
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Regular);
|
|
||||||
|
|
||||||
if (ending >= LuaText.Text.Length)
|
if (ending >= temp.Length)
|
||||||
ending++;
|
ending++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
firstMark = LuaText.Find(mark.ToString(), ending + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
firstMark = temp.IndexOf(mark, ending + 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
firstMark = LuaText.Find(mark.ToString(), firstMark + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
firstMark = temp.IndexOf(mark, firstMark + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,39 +285,33 @@ namespace BizHawk.MultiClient
|
||||||
return !(ammount % 2 == 0);
|
return !(ammount % 2 == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ColorComments()
|
private void AddComments()
|
||||||
{
|
{
|
||||||
foreach (Match CommentMatch in new Regex("--").Matches(LuaText.Text))
|
string temp = LuaText.Text;
|
||||||
|
foreach (Match match in new Regex("--").Matches(temp))
|
||||||
{
|
{
|
||||||
int endComment;
|
int selection, endComment;
|
||||||
|
|
||||||
if (CommentMatch.Index + 4 < LuaText.Text.Length && LuaText.Text.Substring(CommentMatch.Index, 4) == "--[[")
|
if (match.Index + 4 < temp.Length && temp.Substring(match.Index, 4) == "--[[")
|
||||||
{
|
{
|
||||||
if (LuaText.Find("]]", RichTextBoxFinds.MatchCase) > 0)
|
selection = temp.IndexOf("]]");
|
||||||
endComment = LuaText.SelectionStart - CommentMatch.Index + 2;
|
if (selection > 0)
|
||||||
|
endComment = selection - match.Index + 2;
|
||||||
else
|
else
|
||||||
endComment = LuaText.Text.Length;
|
endComment = temp.Length;
|
||||||
|
|
||||||
LuaText.Select(CommentMatch.Index, endComment);
|
//Validate if such text is not part of a string
|
||||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaCommentColor);
|
AddPosition(match.Index, endComment, Global.Config.LuaCommentColor, Global.Config.LuaCommentBold);
|
||||||
if (Global.Config.LuaCommentBold)
|
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Bold);
|
|
||||||
else
|
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Regular);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (LuaText.GetLineFromCharIndex(CommentMatch.Index) + 1 == LuaText.Lines.Count())
|
if (LuaText.GetLineFromCharIndex(match.Index) + 1 == LuaText.Lines.Count())
|
||||||
endComment = LuaText.Text.Length - CommentMatch.Index;
|
endComment = temp.Length - match.Index;
|
||||||
else
|
else
|
||||||
endComment = LuaText.GetFirstCharIndexFromLine(LuaText.GetLineFromCharIndex(CommentMatch.Index) + 1) - CommentMatch.Index;
|
endComment = LuaText.GetFirstCharIndexFromLine(LuaText.GetLineFromCharIndex(match.Index) + 1) - match.Index;
|
||||||
|
|
||||||
LuaText.Select(CommentMatch.Index, endComment);
|
//Validate if such text is not part of a string
|
||||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaCommentColor);
|
AddPosition(match.Index, endComment, Global.Config.LuaCommentColor, Global.Config.LuaCommentBold);
|
||||||
if (Global.Config.LuaCommentBold)
|
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Bold);
|
|
||||||
else
|
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Regular);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue