@@ -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 }
0 commit comments