Skip to content

Commit

Permalink
Merge pull request #1843 from UnderminersTeam/fix-local-var-highlighting
Browse files Browse the repository at this point in the history
Fix local variable syntax highlighting getting reset when switching tabs
  • Loading branch information
Miepee authored Jul 23, 2024
2 parents 1291e79 + 6ffdecb commit c7573d1
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public partial class UndertaleCodeEditor : DataUserControl

public UndertaleCode CurrentDisassembled = null;
public UndertaleCode CurrentDecompiled = null;
public List<string> CurrentLocals = null;
public List<string> CurrentLocals = new();
public string ProfileHash = mainWindow.ProfileHash;
public string MainPath = Path.Combine(Settings.ProfilesFolder, mainWindow.ProfileHash, "Main");
public string TempPath = Path.Combine(Settings.ProfilesFolder, mainWindow.ProfileHash, "Temp");
Expand Down Expand Up @@ -249,6 +249,11 @@ private void FillInCodeViewer(bool overrideFirst = false)
else
_ = DecompileCode(code, true);
}
if (DecompiledTab.IsSelected)
{
// Re-populate local variables when in decompiled code, fixing #1320
PopulateCurrentLocals(mainWindow.Data, code);
}
}

private async void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down Expand Up @@ -525,7 +530,7 @@ private void DisassembleCode(UndertaleCode code, bool first)
var data = mainWindow.Data;
text = code.Disassemble(data.Variables, data.CodeLocals.For(code));

CurrentLocals = new List<string>();
CurrentLocals.Clear();
}
catch (Exception ex)
{
Expand Down Expand Up @@ -784,14 +789,7 @@ private async Task DecompileCode(UndertaleCode code, bool first, LoaderDialog ex
else if (decompiled != null)
{
DecompiledEditor.Document.Text = decompiled;
CurrentLocals = new List<string>();
var locals = dataa.CodeLocals.ByName(code.Name.Content);
if (locals != null)
{
foreach (var local in locals.Locals)
CurrentLocals.Add(local.Name.Content);
}
PopulateCurrentLocals(dataa, code);
RestoreCaretPosition(DecompiledEditor, currLine, currColumn, scrollPos);
Expand Down Expand Up @@ -825,6 +823,19 @@ private async Task DecompileCode(UndertaleCode code, bool first, LoaderDialog ex
}
}

private void PopulateCurrentLocals(UndertaleData data, UndertaleCode code)
{
CurrentLocals.Clear();

// Look up locals for given code entry's name, for syntax highlighting
var locals = data.CodeLocals.ByName(code.Name.Content);
if (locals != null)
{
foreach (var local in locals.Locals)
CurrentLocals.Add(local.Name.Content);
}
}

private void DecompiledEditor_GotFocus(object sender, RoutedEventArgs e)
{
if (DecompiledEditor.IsReadOnly)
Expand Down

0 comments on commit c7573d1

Please sign in to comment.