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

Commit a7b33d4

Browse files
committed
Debounce parsing
1 parent 4424dd1 commit a7b33d4

File tree

1 file changed

+55
-37
lines changed

1 file changed

+55
-37
lines changed

UI/Components/EditorElement.xaml.cs

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ private void editor_TextChanged(object sender, EventArgs e)
628628
NeedsSave = true;
629629
}
630630

631+
private Timer parseTimer;
632+
631633
private void Caret_PositionChanged(object sender, EventArgs e)
632634
{
633635
StatusLine_Coloumn.Text = $"{Program.Translations.GetLanguage("ColAbb")} {editor.TextArea.Caret.Column}";
@@ -639,55 +641,71 @@ private void Caret_PositionChanged(object sender, EventArgs e)
639641

640642
if (!Program.OptionsObject.Program_DynamicISAC || Program.MainWindow == null) return;
641643

644+
645+
if (parseTimer != null)
646+
{
647+
parseTimer.Enabled = false;
648+
parseTimer.Close();
649+
}
650+
651+
parseTimer = new Timer(500)
652+
{
653+
AutoReset = false,
654+
Enabled = true,
655+
};
656+
parseTimer.Elapsed += ParseIncludes;
657+
}
658+
659+
private static void ParseIncludes(object sender, EventArgs e)
660+
{
642661
var ee = Program.MainWindow.GetAllEditorElements();
643662
var ce = Program.MainWindow.GetCurrentEditorElement();
644663

645664
var caret = -1;
646665

647-
if (ee != null)
648-
{
649-
var definitions = new SMDefinition[ee.Length];
650-
List<SMFunction> currentFunctions = null;
651-
for (var i = 0; i < ee.Length; ++i)
652-
{
653-
var el = ee[i];
654-
var fInfo = new FileInfo(el.FullFilePath);
655-
var text = el.editor.Document.Text;
656-
if (fInfo.Extension.Trim('.').ToLowerInvariant() == "inc")
657-
definitions[i] =
658-
new Condenser(text
659-
, fInfo.Name).Condense();
660-
661-
if (fInfo.Extension.Trim('.').ToLowerInvariant() == "sp")
662-
if (el.IsLoaded)
663-
{
664-
caret = el.editor.CaretOffset;
665-
definitions[i] =
666-
new Condenser(text, fInfo.Name)
667-
.Condense();
668-
currentFunctions = definitions[i].Functions;
669-
}
670-
}
666+
if (ee == null) return;
671667

672-
var smDef = Program.Configs[Program.SelectedConfig].GetSMDef()
673-
.ProduceTemporaryExpandedDefinition(definitions, caret, currentFunctions);
674-
var smFunctions = smDef.Functions.ToArray();
675-
var acNodes = smDef.ProduceACNodes();
676-
var isNodes = smDef.ProduceISNodes();
668+
var definitions = new SMDefinition[ee.Length];
669+
List<SMFunction> currentFunctions = null;
670+
for (var i = 0; i < ee.Length; ++i)
671+
{
672+
var el = ee[i];
673+
var fInfo = new FileInfo(el.FullFilePath);
674+
var text = el.editor.Document.Text;
675+
if (fInfo.Extension.Trim('.').ToLowerInvariant() == "inc")
676+
definitions[i] =
677+
new Condenser(text
678+
, fInfo.Name).Condense();
677679

678-
ce.editor.SyntaxHighlighting = new AeonEditorHighlighting(smDef);
679-
foreach (var el in ee)
680-
{
681-
if (el == ce)
680+
if (fInfo.Extension.Trim('.').ToLowerInvariant() == "sp")
681+
if (el.IsLoaded)
682682
{
683-
Debug.Assert(ce != null, nameof(ce) + " != null");
684-
if (ce.ISAC_Open) continue;
683+
caret = el.editor.CaretOffset;
684+
definitions[i] =
685+
new Condenser(text, fInfo.Name)
686+
.Condense();
687+
currentFunctions = definitions[i].Functions;
685688
}
689+
}
686690

691+
var smDef = Program.Configs[Program.SelectedConfig].GetSMDef()
692+
.ProduceTemporaryExpandedDefinition(definitions, caret, currentFunctions);
693+
var smFunctions = smDef.Functions.ToArray();
694+
var acNodes = smDef.ProduceACNodes();
695+
var isNodes = smDef.ProduceISNodes();
687696

688-
el.InterruptLoadAutoCompletes(smDef.FunctionStrings, smFunctions, acNodes,
689-
isNodes, smDef.Methodmaps.ToArray(), smDef.Variables.ToArray());
697+
ce.editor.SyntaxHighlighting = new AeonEditorHighlighting(smDef);
698+
foreach (var el in ee)
699+
{
700+
if (el == ce)
701+
{
702+
Debug.Assert(ce != null, nameof(ce) + " != null");
703+
if (ce.ISAC_Open) continue;
690704
}
705+
706+
707+
el.InterruptLoadAutoCompletes(smDef.FunctionStrings, smFunctions, acNodes,
708+
isNodes, smDef.Methodmaps.ToArray(), smDef.Variables.ToArray());
691709
}
692710
}
693711

0 commit comments

Comments
 (0)