Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit a863ae6

Browse files
Merge branch 'master' into master
2 parents ffc277f + 0a84680 commit a863ae6

File tree

3 files changed

+32
-42
lines changed

3 files changed

+32
-42
lines changed

SourcepawnCondenser/SourcepawnCondenser/SourcepawnCondenser.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<HintPath>..\..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
7575
<Private>True</Private>
7676
</Reference>
77+
<Reference Include="System" />
7778
</ItemGroup>
7879
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7980
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

UI/Components/EditorElement.xaml.cs

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public partial class EditorElement : UserControl
6161
private bool SelectionIsHighlited;
6262
private bool WantFoldingUpdate;
6363

64+
private static DateTime lastParsing;
65+
6466
public EditorElement()
6567
{
6668
InitializeComponent();
@@ -522,7 +524,7 @@ public void UpdateFontSize(double size, bool updateLineHeight = true)
522524
public void ToggleCommentOnLine()
523525
{
524526
var line = editor.Document.GetLineByOffset(editor.CaretOffset);
525-
var lineText = editor.Document.GetText(line.Offset, line.Length);
527+
var lineText = editor.Document.GetText(line);
526528
var leadingWhiteSpaces = 0;
527529
foreach (var l in lineText)
528530
if (char.IsWhiteSpace(l))
@@ -547,7 +549,7 @@ public void ToggleCommentOnLine()
547549
private void DuplicateLine(bool down)
548550
{
549551
var line = editor.Document.GetLineByOffset(editor.CaretOffset);
550-
var lineText = editor.Document.GetText(line.Offset, line.Length);
552+
var lineText = editor.Document.GetText(line);
551553
editor.Document.Insert(line.Offset, lineText + Environment.NewLine);
552554
if (down) editor.CaretOffset -= line.Length + 1;
553555
}
@@ -563,7 +565,7 @@ private void MoveLine(bool down)
563565
}
564566
else
565567
{
566-
var lineText = editor.Document.GetText(line.NextLine.Offset, line.NextLine.Length);
568+
var lineText = editor.Document.GetText(line.NextLine);
567569
editor.Document.Remove(line.NextLine.Offset, line.NextLine.TotalLength);
568570
editor.Document.Insert(line.Offset, lineText + Environment.NewLine);
569571
}
@@ -578,7 +580,7 @@ private void MoveLine(bool down)
578580
{
579581
var insertOffset = line.PreviousLine.Offset;
580582
var relativeCaretOffset = editor.CaretOffset - line.Offset;
581-
var lineText = editor.Document.GetText(line.Offset, line.Length);
583+
var lineText = editor.Document.GetText(line);
582584
editor.Document.Remove(line.Offset, line.TotalLength);
583585
editor.Document.Insert(insertOffset, lineText + Environment.NewLine);
584586
editor.CaretOffset = insertOffset + relativeCaretOffset;
@@ -638,10 +640,9 @@ private void Caret_PositionChanged(object sender, EventArgs e)
638640
var result = bracketSearcher.SearchBracket(editor.Document, editor.CaretOffset);
639641
bracketHighlightRenderer.SetHighlight(result);
640642

641-
643+
642644
if (!Program.OptionsObject.Program_DynamicISAC || Program.MainWindow == null) return;
643645

644-
645646
if (parseTimer != null)
646647
{
647648
parseTimer.Enabled = false;
@@ -696,6 +697,7 @@ private void ParseIncludes(object sender, EventArgs e)
696697
var acNodes = smDef.ProduceACNodes();
697698
var isNodes = smDef.ProduceISNodes();
698699

700+
// Lags the hell out when typing a lot.
699701
ce.editor.SyntaxHighlighting = new AeonEditorHighlighting(smDef);
700702

701703
foreach (var el in ee)
@@ -748,58 +750,45 @@ private void TextArea_TextEntered(object sender, TextCompositionEventArgs e)
748750
// editor.TextArea.IndentationStrategy.IndentLine(editor.Document, editor.Document.GetLineByOffset(editor.CaretOffset));
749751
foldingStrategy.UpdateFoldings(foldingManager, editor.Document);
750752
break;
753+
case "(":
754+
case "[":
751755
case "{":
752-
{
753756
if (Program.OptionsObject.Editor_AutoCloseBrackets)
754757
{
755-
editor.Document.Insert(editor.CaretOffset, "}");
758+
var line = editor.Document.GetLineByOffset(editor.CaretOffset);
759+
var lineText = editor.Document.GetText(line);
760+
761+
// Don't auto close brackets when the user is in a comment or in a string.
762+
if ((lineText[0] == '/' && lineText[1] == '/') ||
763+
editor.Document.GetText(line.Offset, editor.CaretOffset - line.Offset).Count(c => c == '\"') % 2 == 1 ||
764+
editor.Document.GetText(line.Offset - 3, 1) == "\\")
765+
break;
766+
767+
// Getting the char ascii code with int cast and the string pos 0 (the char it self),
768+
// if it's a ( i need to add 1 to get the ascii code for closing bracket
769+
// for [ and { i need to add 2 to get the closing bracket ascii code
770+
char closingBracket = (char)((int)e.Text[0] + (e.Text == "(" ? 1 : 2));
771+
editor.Document.Insert(editor.CaretOffset, closingBracket.ToString());
756772
editor.CaretOffset -= 1;
757-
}
758773

759-
foldingStrategy.UpdateFoldings(foldingManager, editor.Document);
760-
break;
761-
}
762-
default:
763-
{
764-
if (Program.OptionsObject.Editor_AutoCloseBrackets)
765-
{
766-
if (e.Text == "(")
767-
{
768-
editor.Document.Insert(editor.CaretOffset, ")");
769-
editor.CaretOffset -= 1;
770-
}
771-
else if (e.Text == "[")
772-
{
773-
editor.Document.Insert(editor.CaretOffset, "]");
774-
editor.CaretOffset -= 1;
775-
}
774+
// If it's a code block bracket we need to update the folding
775+
if (e.Text == "{")
776+
foldingStrategy.UpdateFoldings(foldingManager, editor.Document);
776777
}
777778

778779
break;
779-
}
780780
}
781781

782782
if (Program.OptionsObject.Editor_AutoCloseStringChars)
783783
{
784-
if (e.Text == "\"")
785-
{
786-
var line = editor.Document.GetLineByOffset(editor.CaretOffset);
787-
var lineText = editor.Document.GetText(line.Offset, editor.CaretOffset - line.Offset);
788-
if (lineText.Length > 0)
789-
if (lineText[Math.Max(lineText.Length - 2, 0)] != '\\')
790-
{
791-
editor.Document.Insert(editor.CaretOffset, "\"");
792-
editor.CaretOffset -= 1;
793-
}
794-
}
795-
else if (e.Text == "'")
784+
if (e.Text == "\"" || e.Text == "'")
796785
{
797786
var line = editor.Document.GetLineByOffset(editor.CaretOffset);
798787
var lineText = editor.Document.GetText(line.Offset, editor.CaretOffset - line.Offset);
799788
if (lineText.Length > 0)
800789
if (lineText[Math.Max(lineText.Length - 2, 0)] != '\\')
801790
{
802-
editor.Document.Insert(editor.CaretOffset, "'");
791+
editor.Document.Insert(editor.CaretOffset, e.Text);
803792
editor.CaretOffset -= 1;
804793
}
805794
}

UI/MainWindowCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private void Command_TidyCode(bool All)
224224
// 0 - start | any other - middle | -1 - EOS
225225
int curserLinePos = currentCaret == line.Offset ? 0 : currentCaret == line.EndOffset ? -1 : currentCaret - line.Offset;
226226

227-
if (curserLinePos > 0) numOfSpacesOrTabsBefore = ee.editor.Document.GetText(line.Offset, curserLinePos).Count(c => c == ' ' || c == '\t');
227+
if (curserLinePos > 0) numOfSpacesOrTabsBefore = ee.editor.Document.GetText(line).Count(c => c == ' ' || c == '\t');
228228

229229
#if DEBUG
230230
Debug.WriteLine($"Curser offset before format: {currentCaret}");
@@ -252,7 +252,7 @@ private void Command_TidyCode(bool All)
252252
}
253253
else if(curserLinePos != 0)
254254
{
255-
int numOfSpacesOrTabsAfter = ee.editor.Document.GetText(line.Offset, curserLinePos).Count(c => c == ' ' || c == '\t');
255+
int numOfSpacesOrTabsAfter = ee.editor.Document.GetText(line).Count(c => c == ' ' || c == '\t');
256256
newCaretPos += curserLinePos + (numOfSpacesOrTabsAfter - numOfSpacesOrTabsBefore);
257257
#if DEBUG
258258
Debug.WriteLine($"Curser offset after format: {newCaretPos}");

0 commit comments

Comments
 (0)