mirror of
https://github.com/2dust/v2rayN.git
synced 2026-04-16 04:25:45 +00:00
Fix two way bind
This commit is contained in:
parent
868efa6574
commit
2b0b09cd1a
1 changed files with 25 additions and 6 deletions
|
|
@ -15,12 +15,37 @@ public partial class JsonEditor : UserControl
|
||||||
private static readonly Lazy<IHighlightingDefinition> SHighlightingLight =
|
private static readonly Lazy<IHighlightingDefinition> SHighlightingLight =
|
||||||
new(() => BuildHighlighting(dark: false), isThreadSafe: true);
|
new(() => BuildHighlighting(dark: false), isThreadSafe: true);
|
||||||
|
|
||||||
|
public static readonly StyledProperty<string> TextProperty =
|
||||||
|
AvaloniaProperty.Register<JsonEditor, string>(nameof(Text), defaultValue: string.Empty);
|
||||||
|
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get => GetValue(TextProperty);
|
||||||
|
set => SetValue(TextProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public JsonEditor()
|
public JsonEditor()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
var isDark = Application.Current?.ActualThemeVariant != ThemeVariant.Light;
|
var isDark = Application.Current?.ActualThemeVariant != ThemeVariant.Light;
|
||||||
Editor.SyntaxHighlighting = isDark ? SHighlightingDark.Value : SHighlightingLight.Value;
|
Editor.SyntaxHighlighting = isDark ? SHighlightingDark.Value : SHighlightingLight.Value;
|
||||||
Editor.TextArea.TextView.Options.EnableHyperlinks = false;
|
Editor.TextArea.TextView.Options.EnableHyperlinks = false;
|
||||||
|
|
||||||
|
Editor.TextChanged += (_, _) =>
|
||||||
|
{
|
||||||
|
if (Text != Editor.Text)
|
||||||
|
{
|
||||||
|
SetCurrentValue(TextProperty, Editor.Text);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.GetObservable(TextProperty).Subscribe(text =>
|
||||||
|
{
|
||||||
|
if (Editor.Text != text)
|
||||||
|
{
|
||||||
|
Editor.Text = text ?? string.Empty;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IHighlightingDefinition BuildHighlighting(bool dark)
|
private static IHighlightingDefinition BuildHighlighting(bool dark)
|
||||||
|
|
@ -52,12 +77,6 @@ public partial class JsonEditor : UserControl
|
||||||
return HighlightingLoader.Load(reader, HighlightingManager.Instance);
|
return HighlightingLoader.Load(reader, HighlightingManager.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Text
|
|
||||||
{
|
|
||||||
get => Editor.Text;
|
|
||||||
set => Editor.Text = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FormatJson_Click(object? sender, RoutedEventArgs e)
|
private void FormatJson_Click(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue