Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/RemoteViewer.Client/Views/Viewer/ViewerView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@
PointerWheelChanged="DisplayPanel_PointerWheelChanged"
KeyDown="DisplayPanel_KeyDown"
KeyUp="DisplayPanel_KeyUp"
TextInput="DisplayPanel_TextInput"
>
<Panel>
<Image x:Name="FrameImage"
Expand Down
59 changes: 21 additions & 38 deletions src/RemoteViewer.Client/Views/Viewer/ViewerView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,51 +248,43 @@ private async void DisplayPanel_KeyDown(object? sender, KeyEventArgs e)
}
}

if (!this._viewModel.IsInputEnabled)
if (this._viewModel.IsInputEnabled is false)
return;

// Printable characters are handled by TextInput event
if (ShouldDeferToTextInput(e.KeySymbol))
{
e.Handled = true;
return;
}

e.Handled = true;

var keyCode = (ushort)KeyInterop.VirtualKeyFromKey(e.Key);
var modifiers = this.GetKeyModifiers(e.KeyModifiers);
await this._viewModel.Connection.RequiredViewerService.SendKeyDownAsync(keyCode, modifiers);
}

private async void DisplayPanel_TextInput(object? sender, TextInputEventArgs e)
{
e.Handled = true;

// Validate input: must be enabled, non-empty, and reasonable length
// Max 100 chars handles typical IME input and paste scenarios
if (this._viewModel is not { IsInputEnabled: true } ||
string.IsNullOrEmpty(e.Text) ||
e.Text.Length > 100)
return;
// If KeySymbol is a printable character, send as text input
if (string.IsNullOrEmpty(e.KeySymbol) is false &&
e.KeySymbol.Length == 1 &&
char.IsControl(e.KeySymbol[0]) is false)
{
await this._viewModel.Connection.RequiredViewerService.SendTextInputAsync(e.KeySymbol);
Comment on lines +257 to +261
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The single-character check e.KeySymbol.Length == 1 may break IME (Input Method Editor) support for languages like Chinese, Japanese, and Korean. The previous TextInput event could receive multi-character strings from IME composition (up to 100 chars), but KeyDown.KeySymbol only provides single characters. IME users may not be able to input complex characters that require composition. Does Avalonia's KeyDown.KeySymbol handle IME composition, or should IME be handled separately through TextInput events?

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/RemoteViewer.Client/Views/Viewer/ViewerView.axaml.cs
Line: 257:261

Comment:
**logic:** The single-character check `e.KeySymbol.Length == 1` may break IME (Input Method Editor) support for languages like Chinese, Japanese, and Korean. The previous `TextInput` event could receive multi-character strings from IME composition (up to 100 chars), but `KeyDown.KeySymbol` only provides single characters. IME users may not be able to input complex characters that require composition. Does Avalonia's KeyDown.KeySymbol handle IME composition, or should IME be handled separately through TextInput events?

How can I resolve this? If you propose a fix, please make it concise.

}
// Non-printable keys (arrows, function keys, etc.) go through KeyDown
else
{
var keyCode = (ushort)KeyInterop.VirtualKeyFromKey(e.Key);
var modifiers = this.GetKeyModifiers(e.KeyModifiers);
await this._viewModel.Connection.RequiredViewerService.SendKeyDownAsync(keyCode, modifiers);
}

await this._viewModel.Connection.RequiredViewerService.SendTextInputAsync(e.Text);
}

private async void DisplayPanel_KeyUp(object? sender, KeyEventArgs e)
{
if (this._viewModel is not { IsInputEnabled: true })
return;

// Printable characters were handled by TextInput event
if (ShouldDeferToTextInput(e.KeySymbol))
e.Handled = true;

// Printable characters were sent as text on KeyDown, no KeyUp needed
if (string.IsNullOrEmpty(e.KeySymbol) is false &&
e.KeySymbol.Length == 1 &&
char.IsControl(e.KeySymbol[0]) is false)
{
e.Handled = true;
return;
}

e.Handled = true;

var keyCode = (ushort)KeyInterop.VirtualKeyFromKey(e.Key);
var modifiers = this.GetKeyModifiers(e.KeyModifiers);
await this._viewModel.Connection.RequiredViewerService.SendKeyUpAsync(keyCode, modifiers);
Expand Down Expand Up @@ -421,15 +413,6 @@ private void ResetToolbarHideTimer()
#endregion

#region Helper Methods
private static bool ShouldDeferToTextInput(string? keySymbol)
{
// If KeySymbol is a printable character, let TextInput handle it.
// Control characters (Ctrl+key) and null (special keys) go through KeyDown.
return !string.IsNullOrEmpty(keySymbol) &&
keySymbol.Length == 1 &&
!char.IsControl(keySymbol[0]);
}

private bool TryGetNormalizedPosition(PointerEventArgs e, out float x, out float y)
{
x = -1;
Expand Down
Loading