mirror of
https://github.com/Stone-Red-Code/Decho.git
synced 2026-09-07 07:46:11 +02:00
Support sending multi line messages
This commit is contained in:
@@ -79,11 +79,9 @@
|
|||||||
Margin="0 0 5 0"
|
Margin="0 0 5 0"
|
||||||
Text="{Binding Draft, Mode=TwoWay}"
|
Text="{Binding Draft, Mode=TwoWay}"
|
||||||
IsEnabled="{Binding IsConnected}"
|
IsEnabled="{Binding IsConnected}"
|
||||||
KeyDown="OnTextBoxKeyDown">
|
AcceptsReturn="False"
|
||||||
<TextBox.KeyBindings>
|
TextWrapping="Wrap"
|
||||||
<KeyBinding Command="{Binding SendCommand}" Gesture="Enter" />
|
KeyDown="OnTextBoxKeyDown" />
|
||||||
</TextBox.KeyBindings>
|
|
||||||
</TextBox>
|
|
||||||
<Popup x:Name="MentionPopup"
|
<Popup x:Name="MentionPopup"
|
||||||
Placement="TopEdgeAlignedLeft"
|
Placement="TopEdgeAlignedLeft"
|
||||||
PlacementTarget="{Binding #MessageTextBox}"
|
PlacementTarget="{Binding #MessageTextBox}"
|
||||||
@@ -116,15 +114,18 @@
|
|||||||
<Button Grid.Column="1"
|
<Button Grid.Column="1"
|
||||||
Height="33"
|
Height="33"
|
||||||
Width="33"
|
Width="33"
|
||||||
Margin="0 0 5 0"
|
Margin="0 1 5 0"
|
||||||
Content="Send"
|
Content="Send"
|
||||||
|
VerticalAlignment="Top"
|
||||||
i:Attached.Icon="fa-paper-plane"
|
i:Attached.Icon="fa-paper-plane"
|
||||||
Command="{Binding SendCommand}"
|
Command="{Binding SendCommand}"
|
||||||
IsEnabled="{Binding IsConnected}" />
|
IsEnabled="{Binding IsConnected}" />
|
||||||
<Button Grid.Column="2"
|
<Button Grid.Column="2"
|
||||||
Height="33"
|
Height="33"
|
||||||
Width="33"
|
Width="33"
|
||||||
|
Margin="0 1 0 0"
|
||||||
Click="OnFileUploadClicked"
|
Click="OnFileUploadClicked"
|
||||||
|
VerticalAlignment="Top"
|
||||||
i:Attached.Icon="fa-paperclip"
|
i:Attached.Icon="fa-paperclip"
|
||||||
IsEnabled="{Binding IsConnected}" />
|
IsEnabled="{Binding IsConnected}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Decho.Models;
|
|||||||
using Decho.ViewModels;
|
using Decho.ViewModels;
|
||||||
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Reactive;
|
||||||
|
|
||||||
namespace Decho.Views;
|
namespace Decho.Views;
|
||||||
|
|
||||||
@@ -39,32 +40,61 @@ public partial class MessageComposerView : UserControl
|
|||||||
private void OnTextBoxKeyDown(object? sender, KeyEventArgs e)
|
private void OnTextBoxKeyDown(object? sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
MessageComposerViewModel? vm = this.GetDataContext<MessageComposerViewModel>();
|
MessageComposerViewModel? vm = this.GetDataContext<MessageComposerViewModel>();
|
||||||
if (vm is null || !vm.Autocomplete.ShowPopup)
|
if (vm is null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.Key == Key.Down)
|
if (vm.Autocomplete.ShowPopup)
|
||||||
{
|
{
|
||||||
vm.Autocomplete.SelectedIndex = Math.Min(vm.Autocomplete.SelectedIndex + 1, vm.Autocomplete.FilteredItems.Count - 1);
|
if (e.Key == Key.Down)
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
else if (e.Key == Key.Up)
|
|
||||||
{
|
|
||||||
vm.Autocomplete.SelectedIndex = Math.Max(vm.Autocomplete.SelectedIndex - 1, 0);
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
else if (e.Key is Key.Enter or Key.Tab)
|
|
||||||
{
|
|
||||||
if (vm.Autocomplete.SelectedIndex >= 0 && vm.Autocomplete.SelectedIndex < vm.Autocomplete.FilteredItems.Count)
|
|
||||||
{
|
{
|
||||||
InsertAutocomplete(vm.Autocomplete.FilteredItems[vm.Autocomplete.SelectedIndex]);
|
vm.Autocomplete.SelectedIndex = Math.Min(vm.Autocomplete.SelectedIndex + 1, vm.Autocomplete.FilteredItems.Count - 1);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.Key == Key.Up)
|
||||||
|
{
|
||||||
|
vm.Autocomplete.SelectedIndex = Math.Max(vm.Autocomplete.SelectedIndex - 1, 0);
|
||||||
|
e.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.Key is Key.Enter or Key.Tab)
|
||||||
|
{
|
||||||
|
if (vm.Autocomplete.SelectedIndex >= 0 && vm.Autocomplete.SelectedIndex < vm.Autocomplete.FilteredItems.Count)
|
||||||
|
{
|
||||||
|
InsertAutocomplete(vm.Autocomplete.FilteredItems[vm.Autocomplete.SelectedIndex]);
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.Key == Key.Escape)
|
||||||
|
{
|
||||||
|
vm.Autocomplete.ShowPopup = false;
|
||||||
|
e.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (e.Key == Key.Escape)
|
|
||||||
|
if (e.Key == Key.Enter)
|
||||||
{
|
{
|
||||||
vm.Autocomplete.ShowPopup = false;
|
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
||||||
|
{
|
||||||
|
int caret = MessageTextBox.CaretIndex;
|
||||||
|
string text = vm.Draft ?? "";
|
||||||
|
vm.Draft = text[..caret] + "\n" + text[caret..];
|
||||||
|
Avalonia.Threading.Dispatcher.UIThread.Post(() => MessageTextBox.CaretIndex = caret + 1);
|
||||||
|
e.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vm.Draft = MessageTextBox.Text ?? "";
|
||||||
|
vm.Send();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user