Browse Source

Add IsEnabled toggle for CompletionBehavior

pull/165/head
Ionite 1 year ago
parent
commit
bca5b7f063
No known key found for this signature in database
  1. 16
      StabilityMatrix.Avalonia/Behaviors/TextEditorCompletionBehavior.cs
  2. 2
      StabilityMatrix.Avalonia/Controls/PromptCard.axaml

16
StabilityMatrix.Avalonia/Behaviors/TextEditorCompletionBehavior.cs

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Avalonia;
using Avalonia.Input;
@ -14,6 +15,7 @@ using CompletionWindow = StabilityMatrix.Avalonia.Controls.CodeCompletion.Comple
namespace StabilityMatrix.Avalonia.Behaviors;
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public class TextEditorCompletionBehavior : Behavior<TextEditor>
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
@ -21,8 +23,7 @@ public class TextEditorCompletionBehavior : Behavior<TextEditor>
private TextEditor textEditor = null!;
private CompletionWindow? completionWindow;
// ReSharper disable once MemberCanBePrivate.Global
public static readonly StyledProperty<ICompletionProvider> CompletionProviderProperty =
AvaloniaProperty.Register<TextEditorCompletionBehavior, ICompletionProvider>(nameof(CompletionProvider));
@ -31,6 +32,15 @@ public class TextEditorCompletionBehavior : Behavior<TextEditor>
get => GetValue(CompletionProviderProperty);
set => SetValue(CompletionProviderProperty, value);
}
public static readonly StyledProperty<bool> IsEnabledProperty = AvaloniaProperty.Register<TextEditorCompletionBehavior, bool>(
"IsEnabled", true);
public bool IsEnabled
{
get => GetValue(IsEnabledProperty);
set => SetValue(IsEnabledProperty, value);
}
protected override void OnAttached()
{
@ -72,7 +82,7 @@ public class TextEditorCompletionBehavior : Behavior<TextEditor>
private void TextArea_TextEntered(object? sender, TextInputEventArgs e)
{
if (e.Text is not { } triggerText) return;
if (!IsEnabled || e.Text is not { } triggerText) return;
if (triggerText.All(char.IsLetterOrDigit))
{

2
StabilityMatrix.Avalonia/Controls/PromptCard.axaml

@ -69,6 +69,7 @@
FontFamily="Cascadia Code,Consolas,Menlo,Monospace">
<i:Interaction.Behaviors>
<behaviors:TextEditorCompletionBehavior
IsEnabled="{Binding CompletionProvider.IsLoaded}"
CompletionProvider="{Binding CompletionProvider}"/>
</i:Interaction.Behaviors>
</avaloniaEdit:TextEditor>
@ -103,6 +104,7 @@
FontFamily="Cascadia Code,Consolas,Menlo,Monospace">
<i:Interaction.Behaviors>
<behaviors:TextEditorCompletionBehavior
IsEnabled="{Binding CompletionProvider.IsLoaded}"
CompletionProvider="{Binding CompletionProvider}"/>
</i:Interaction.Behaviors>
</avaloniaEdit:TextEditor>

Loading…
Cancel
Save