mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
enhance: only update grammar if it is necessary
This commit is contained in:
parent
68519c76ca
commit
93706449be
1 changed files with 10 additions and 3 deletions
|
@ -81,6 +81,8 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
public class RegistryOptionsWrapper(ThemeName defaultTheme) : IRegistryOptions
|
public class RegistryOptionsWrapper(ThemeName defaultTheme) : IRegistryOptions
|
||||||
{
|
{
|
||||||
|
public string LastScope { get; set; } = string.Empty;
|
||||||
|
|
||||||
public IRawTheme GetTheme(string scopeName) => _backend.GetTheme(scopeName);
|
public IRawTheme GetTheme(string scopeName) => _backend.GetTheme(scopeName);
|
||||||
public IRawTheme GetDefaultTheme() => _backend.GetDefaultTheme();
|
public IRawTheme GetDefaultTheme() => _backend.GetDefaultTheme();
|
||||||
public IRawTheme LoadTheme(ThemeName name) => _backend.LoadTheme(name);
|
public IRawTheme LoadTheme(ThemeName name) => _backend.LoadTheme(name);
|
||||||
|
@ -111,11 +113,16 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
public static void SetGrammarByFileName(TextMate.Installation installation, string filePath)
|
public static void SetGrammarByFileName(TextMate.Installation installation, string filePath)
|
||||||
{
|
{
|
||||||
if (installation is { RegistryOptions: RegistryOptionsWrapper reg })
|
if (installation is { RegistryOptions: RegistryOptionsWrapper reg } && !string.IsNullOrEmpty(filePath))
|
||||||
{
|
{
|
||||||
|
var scope = reg.GetScope(filePath);
|
||||||
|
if (reg.LastScope != scope)
|
||||||
|
{
|
||||||
|
reg.LastScope = scope;
|
||||||
installation.SetGrammar(reg.GetScope(filePath));
|
installation.SetGrammar(reg.GetScope(filePath));
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue