Skip to content

Commit a2812d9

Browse files
committed
Allow multiline input, disable send button focus
fixes #155, closes #160
1 parent a249a6c commit a2812d9

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

Signal-Windows/Controls/Conversation.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<Button x:Name="SendMessageButton" Grid.Column="1" Click="SendMessageButton_Click" IsEnabled="{x:Bind SendButtonEnabled, Mode=OneWay}" Background="{x:Bind SendButtonBackground}" VerticalAlignment="Bottom" Width="50" VerticalContentAlignment="Stretch" MinHeight="50" Visibility="{x:Bind SendMessageVisible, Mode=OneWay}">
127127
<SymbolIcon Symbol="Send"/>
128128
</Button>
129-
<Button x:Name="UnblockButton" Content="Unblock" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.ColumnSpan="2" Height="50" Visibility="{x:Bind Blocked, Mode=OneWay}" Click="UnblockButton_Click"/>
129+
<Button x:Name="UnblockButton" Content="Unblock" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.ColumnSpan="2" Height="50" Visibility="{x:Bind Blocked, Mode=OneWay}" Click="UnblockButton_Click" AllowFocusOnInteraction="False"/>
130130
</Grid>
131131
</Grid>
132132
</UserControl>

Signal-Windows/Controls/Conversation.xaml.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Threading.Tasks;
1515
using Windows.Foundation;
1616
using Windows.Storage;
17+
using Windows.System;
1718
using Windows.UI.Core;
1819
using Windows.UI.ViewManagement;
1920
using Windows.UI.Xaml;
@@ -36,7 +37,6 @@ public sealed partial class Conversation : UserControl, INotifyPropertyChanged
3637
{
3738
private readonly ILogger Logger = LibsignalLogging.CreateLogger<Conversation>();
3839
public event PropertyChangedEventHandler PropertyChanged;
39-
private bool SendingMessage = false;
4040
private SignalConversation SignalConversation;
4141
public VirtualizedCollection Collection;
4242
private CoreWindowActivationState ActivationState = CoreWindowActivationState.Deactivated;
@@ -283,18 +283,23 @@ public AppendResult Append(Message sm)
283283

284284
private async void TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
285285
{
286-
if (e.Key == Windows.System.VirtualKey.Enter)
286+
if (e.Key == VirtualKey.Enter)
287287
{
288-
// this fixes double send by enter repeat
289-
if (!SendingMessage)
288+
e.Handled = true; // Prevent KeyDown from firing twice on W10 CU
289+
bool shift = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
290+
if (shift)
290291
{
291-
SendingMessage = true;
292-
bool sendMessageResult = await GetMainPageVm().SendMessageButton_Click(InputTextBox.Text);
292+
InputTextBox.Text += "\r";
293+
InputTextBox.SelectionStart = InputTextBox.Text.Length;
294+
InputTextBox.SelectionLength = 0;
295+
}
296+
else
297+
{
298+
bool sendMessageResult = await GetMainPageVm().SendMessage(InputTextBox.Text);
293299
if (sendMessageResult)
294300
{
295301
InputTextBox.Text = string.Empty;
296302
}
297-
SendingMessage = false;
298303
}
299304
}
300305
}
@@ -310,8 +315,7 @@ private void ScrollToBottom()
310315

311316
private async void SendMessageButton_Click(object sender, RoutedEventArgs e)
312317
{
313-
InputTextBox.Focus(FocusState.Programmatic);
314-
bool sendMessageResult = await GetMainPageVm().SendMessageButton_Click(InputTextBox.Text);
318+
bool sendMessageResult = await GetMainPageVm().SendMessage(InputTextBox.Text);
315319
if (sendMessageResult)
316320
{
317321
InputTextBox.Text = string.Empty;

Signal-Windows/ViewModels/MainPageViewModel.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,14 @@ public bool ThreadListAlignRight
8888
set { _ThreadListAlignRight = value; RaisePropertyChanged(nameof(ThreadListAlignRight)); }
8989
}
9090

91-
private async Task<bool> SendMessage(string messageText)
91+
internal async Task<bool> SendMessage(string messageText)
9292
{
9393
try
9494
{
9595
if (!string.IsNullOrEmpty(messageText))
9696
{
9797
var now = Util.CurrentTimeMillis();
98+
messageText = messageText.Replace("\r", "\r\n");
9899
SignalMessage message = new SignalMessage()
99100
{
100101
Author = null,
@@ -144,11 +145,6 @@ internal void RepositionConversation(SignalConversation uiConversation)
144145
}
145146
}
146147

147-
internal async Task<bool> SendMessageButton_Click(string text)
148-
{
149-
return await SendMessage(text.Replace("\r", "\r\n"));
150-
}
151-
152148
internal void Deselect()
153149
{
154150
if (SelectedConversation != null)

0 commit comments

Comments
 (0)