Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ConsoloniaAccessText underline #205

Merged
merged 14 commits into from
Dec 14, 2024
Merged

Add ConsoloniaAccessText underline #205

merged 14 commits into from
Dec 14, 2024

Conversation

tomlm
Copy link
Collaborator

@tomlm tomlm commented Dec 14, 2024

Fix for #196
accessText

Copy link
Contributor

coderabbitai bot commented Dec 14, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request introduce a new class, ConsoloniaAccessText, in the Consolonia.Core.Controls namespace, which extends the existing AccessText class from Avalonia. This class is designed to display a text block where a character prefixed with an underscore serves as an access key. The implementation includes a static constructor that registers the ShowAccessKeyProperty and an instance constructor that subscribes to the PropertyChanged event for the Text and ShowAccessKey properties. When the Text property changes, the class splits the text at the underscore and manages the visual representation of the access key based on the ShowAccessKey property.

Additionally, the pull request modifies the Menu.axaml and MenuItem.axaml files by removing the XML namespace declarations related to the System assembly and eliminating the DataTemplate for system:String, which previously included an AccessText element. These changes affect how string data is presented within the control templates while preserving the overall structure and functionality of the UI components.

🔗 Possibly related PRs
  • Add Italic, strikethrough and fix line draw bug  #133: This PR adds italic and strikethrough text support, which is related to the ConsoloniaAccessText class introduced in the main PR, as both involve text rendering and formatting.
  • Fix strikethrough implementation #134: This PR focuses on fixing the strikethrough implementation, which directly relates to the access key rendering functionality in the ConsoloniaAccessText class, enhancing text decoration handling.
  • 196 alt key accelerators arent rendered #201: This PR addresses the rendering of ALT key accelerators, which may relate to the keyboard navigation aspects of the ConsoloniaAccessText class, as it deals with how access keys are processed.
  • Add ability to inspect XAML markup for gallery pages #204: This PR introduces the ability to inspect XAML markup for gallery pages, which may involve the ConsoloniaAccessText class if it is used within the gallery's UI components, enhancing the overall understanding of how text is rendered in the application.
👥 Suggested reviewers
  • tomlm

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2eab96 and eb90cc4.

📒 Files selected for processing (1)
  • src/Consolonia.Core/Infrastructure/ConsoleWindow.cs (1 hunks)
🔇 Additional comments (1)
src/Consolonia.Core/Infrastructure/ConsoleWindow.cs (1)

408-411: Good fix for preventing unwanted text input with modifier keys!

The added conditions prevent text input when Alt or Control modifiers are active, which should fix the issue where pressing Alt+F was incorrectly inputting 'F' into input controls. This is a good solution as it ensures modifier key combinations are handled purely as commands/shortcuts rather than generating text input.

Note that this change addresses only the first reported issue. The second issue regarding Alt key toggle behavior for underscores appears to be an Avalonia framework bug as mentioned in the PR comments.

Let's verify the fix works as expected:

✅ Verification successful

The initial results show multiple files handling keyboard events. Let's examine the key handlers in the core infrastructure files to ensure there are no conflicting implementations and that the Alt key handling is consistent across the codebase.


The Alt key handling implementation is correctly isolated and consistent

The code inspection confirms that the Alt key handling in ConsoleWindow.cs is properly implemented and doesn't conflict with other keyboard event handlers in the codebase. The changes prevent text input when Alt or Control modifiers are active by checking RawInputModifiers flags before generating text input events. The implementation in ArrowsAndKeyboardNavigationHandler.cs handles different aspects (navigation) and doesn't interfere with this fix.

The only other Alt modifier handling found is in DefaultNetConsole.cs, which is just a mapping definition between ConsoleModifiers and RawInputModifiers, further confirming the consistency of the implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any other keyboard handling code that might interfere
# Look for other keyboard event handlers that might affect Alt key behavior
rg -l "KeyEvent|RawKeyEventArgs|RawTextInputEventArgs|Alt.*modifier" --type cs

# Look for any AccessText-related keyboard handling
ast-grep --pattern 'class $_ {
  $$$
  (KeyDown|KeyUp|TextInput).*{
    $$$
  }
  $$$
}'

Length of output: 1061


Script:

#!/bin/bash
# Let's examine the key handling implementations in related files
rg -A 10 "KeyDown|KeyUp|TextInput|RawKeyEventArgs" src/Consolonia.Core/Infrastructure/ArrowsAndKeyboardNavigationHandler.cs src/Consolonia.Core/Infrastructure/ConsoleWindow.cs

# Also check for any other Alt modifier handling
rg -A 5 "Alt.*modifier|RawInputModifiers.Alt" src/Consolonia.Core/Infrastructure/

Length of output: 8497


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tomlm tomlm enabled auto-merge (squash) December 14, 2024 02:14
@tomlm tomlm requested a review from jinek December 14, 2024 02:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (1)
src/Consolonia.Core/Controls/ConsoloniaAccessText.cs (1)

9-11: Enhance XML documentation

The current documentation is minimal. Consider adding more details about the class's behavior and usage.

Add more comprehensive documentation:

 /// <summary>
-/// A text block that displays a character prefixed with an underscore as an access key.
+/// A text block that displays a character prefixed with an underscore as an access key.
+/// The access key character can be underlined when ShowAccessKey is true.
 /// </summary>
+/// <remarks>
+/// This control extends Avalonia's AccessText to provide visual feedback for access keys.
+/// Example usage: "_File" will display as "File" with 'F' as the access key.
+/// </remarks>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b741da and e616d81.

📒 Files selected for processing (3)
  • src/Consolonia.Core/Controls/ConsoloniaAccessText.cs (1 hunks)
  • src/Consolonia.Themes/Templates/Controls/Menu.axaml (2 hunks)
  • src/Consolonia.Themes/Templates/Controls/MenuItem.axaml (2 hunks)
🔇 Additional comments (2)
src/Consolonia.Core/Controls/ConsoloniaAccessText.cs (1)

12-13: LGTM: Class inheritance and purpose are well-defined

The class appropriately extends Avalonia's AccessText and has a clear purpose.

src/Consolonia.Themes/Templates/Controls/Menu.axaml (1)

3-3: LGTM: Proper integration of ConsoloniaAccessText

The namespace declaration and control usage are correctly implemented with appropriate property bindings.

Also applies to: 28-30

src/Consolonia.Core/Controls/ConsoloniaAccessText.cs Outdated Show resolved Hide resolved
src/Consolonia.Core/Controls/ConsoloniaAccessText.cs Outdated Show resolved Hide resolved
src/Consolonia.Themes/Templates/Controls/MenuItem.axaml Outdated Show resolved Hide resolved
Copy link
Owner

@jinek jinek left a comment

Choose a reason for hiding this comment

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

Button and other controls use some kind of factory or template, which can be also overridden to use ConsoloniaAccessText.

src/Consolonia.Core/Controls/ConsoloniaAccessText.cs Outdated Show resolved Hide resolved
var iPos = Text.IndexOf('_', StringComparison.Ordinal);
if (iPos >= 0 && iPos < Text.Length - 1)
{
inlines.Add(new Run(Text.Substring(0, iPos)));
Copy link
Owner

Choose a reason for hiding this comment

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

Just a hint: Text[..iPos] or Text[iPos..]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh, fancy. I totally forgot about that new feature. It hasn't been integrated into my coding patterns.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Holy shit, I just tried it...so clean, so readable, so succinct. .Substring always felt so verbose. I love it! Thanks for the tip!

Fix bug on keyup where Alt modifier not being passed for Alt keys.
Added Labels page.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (2)
src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs (1)

26-43: Consider adding error handling and null checks

While the implementation looks good overall, consider these improvements:

  1. Add null check for DataTemplates collection
  2. Add error handling for ConsoloniaAccessText creation
  3. Consider performance impact of type checking all unknown data types

Consider this enhanced implementation:

 // override AccessText to use ConsoloniaAccessText as default contentpresenter for unknown data types (aka string)
+if (this.DataTemplates == null)
+    throw new InvalidOperationException("DataTemplates collection is not initialized");
+
 this.DataTemplates.Add(new FuncDataTemplate<object>(
     (data, s) =>
     {
         if (data != null && data is string str)
         {
             try
             {
                 var result = new ConsoloniaAccessText();
                 result.Bind(TextBlock.TextProperty,
                     result.GetObservable(Control.DataContextProperty));
                 return result;
             }
             catch (Exception ex)
             {
                 // Log error or handle appropriately
                 return null;
             }
         }
         return null;
     },
     true)
 );
src/Consolonia.Gallery/Gallery/GalleryViews/GalleryLabel.axaml (1)

9-9: Remove or update the unrelated comment

The comment references TextBox.xaml from Avalonia's default theme, but this implementation appears to be a custom form layout rather than a TextBox style.

-    <!--Copied from https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Default/TextBox.xaml-->
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e616d81 and a399f28.

📒 Files selected for processing (6)
  • src/Consolonia.Core/Controls/ConsoloniaAccessText.cs (1 hunks)
  • src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs (2 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryLabel.axaml (1 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryLabel.axaml.cs (1 hunks)
  • src/Consolonia.Gallery/View/ControlsListView.axaml (2 hunks)
  • src/Consolonia.PlatformSupport/WindowsConsole.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Consolonia.Core/Controls/ConsoloniaAccessText.cs
🔇 Additional comments (2)
src/Consolonia.Gallery/View/ControlsListView.axaml (2)

23-23: LGTM: Access key added for Theme label

The underscore before "Theme" correctly defines 'T' as the access key for keyboard navigation.


23-23: Verify integration with ConsoloniaAccessText

Since these changes are part of introducing ConsoloniaAccessText, we should verify if these controls need to be updated to use the new ConsoloniaAccessText control for consistent underline behavior.

Also applies to: 39-40

✅ Verification successful

ConsoloniaAccessText is only used for menu items, no changes needed

The verification shows that ConsoloniaAccessText is specifically designed for menu-related controls (Menu and MenuItem) to handle their access key underline behavior. Regular Labels don't need this functionality as they use a simpler underscore prefix for access keys. The current implementation in ControlsListView.axaml is correct and consistent with the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if other XAML files are using ConsoloniaAccessText
rg -l "ConsoloniaAccessText" --type xaml

# Check the style/template definitions for Label and Button
fd -e axaml -e xaml | xargs rg "Style.*Target(Type)?=\"(Label|Button)\""

Length of output: 142


Script:

#!/bin/bash
# Search for ConsoloniaAccessText in all files
rg -l "ConsoloniaAccessText"

# Search for Label and Button styles in all files
rg "Style.*Target(Type)?=\"(Label|Button)\""

# List all XAML/AXAML files to understand the codebase structure
fd -e xaml -e axaml

# Check content of the specific file
cat "src/Consolonia.Gallery/View/ControlsListView.axaml"

Length of output: 8251


Script:

#!/bin/bash
# Check Menu and MenuItem templates since they use ConsoloniaAccessText
cat "src/Consolonia.Themes/Templates/Controls/Menu.axaml" "src/Consolonia.Themes/Templates/Controls/MenuItem.axaml"

# Check Label template/style definitions
fd "Label.axaml" || rg -l "Style.*Label" 

# Check the ConsoloniaAccessText implementation
cat "src/Consolonia.Core/Controls/ConsoloniaAccessText.cs"

Length of output: 16067

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs (3)

26-43: Consider performance implications of global template

The template is evaluated for every unknown data type, not just strings. This could impact performance in data-heavy scenarios.

Consider:

  1. Using a more specific template scope if possible
  2. Adding a comment explaining why this global approach was chosen
  3. Document potential performance implications in the class documentation

32-35: Document the binding behavior

The binding between TextBlock.TextProperty and DataContext should be documented to explain the text rendering process.

Add a comment explaining the binding:

 var result = new ConsoloniaAccessText();
+// Bind the text content to the DataContext, allowing dynamic updates
 result.Bind(TextBlock.TextProperty,
     result.GetObservable(Control.DataContextProperty));

26-44: Add usage documentation to help other developers

Given the PR comment about difficulty locating features, consider adding:

  1. XML documentation to the class explaining the template's purpose
  2. Example usage in README or documentation
  3. Sample XAML showing how to override this behavior when needed

Would you like me to help create documentation templates or examples?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a399f28 and 4e902fb.

📒 Files selected for processing (4)
  • src/Consolonia.Core/Controls/ConsoloniaAccessText.cs (1 hunks)
  • src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs (2 hunks)
  • src/Consolonia.Themes/Templates/Controls/Menu.axaml (1 hunks)
  • src/Consolonia.Themes/Templates/Controls/MenuItem.axaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/Consolonia.Themes/Templates/Controls/MenuItem.axaml
  • src/Consolonia.Themes/Templates/Controls/Menu.axaml
  • src/Consolonia.Core/Controls/ConsoloniaAccessText.cs
🔇 Additional comments (2)
src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs (2)

5-5: LGTM: Required imports added appropriately

The new imports are necessary for the template and control functionality being introduced.

Also applies to: 7-7


30-40: Verify template behavior with different string scenarios

The template creates a new ConsoloniaAccessText instance for every string. Let's verify the behavior with different scenarios.

✅ Verification successful

The previous attempt failed because of file type restrictions. Let's try a broader search to understand the usage patterns and implementation details of ConsoloniaAccessText and related components.


Template behavior with strings is correctly implemented

The implementation is appropriate and safe for handling string scenarios:

  • It's a global DataTemplate that only creates ConsoloniaAccessText for non-null string values
  • The binding is properly set up to reflect DataContext changes
  • ConsoloniaAccessText is a sealed class inheriting from AccessText, ensuring consistent behavior
  • The template is registered at application level as a fallback for string content
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing string template usage to understand impact
rg -l "DataTemplate.*string" --type xaml

# Search for potential string-to-AccessText conversions that might be affected
ast-grep --pattern 'AccessText { Text = $_ }'

Length of output: 119


Script:

#!/bin/bash
# Search for ConsoloniaAccessText usage and implementation
rg -A 5 "ConsoloniaAccessText" 

# Search for DataTemplate string handling
rg -A 5 "DataTemplate.*string"

# Search for AccessText related code
rg -A 5 "AccessText"

Length of output: 5218

@tomlm
Copy link
Collaborator Author

tomlm commented Dec 14, 2024

it works almost.
There are 2 issues left:
Accelerator used for Label puts focus on the input control AND puts accelerator key into the input
label
Alt+F puts focus on the target element, but then even though I set the e.Handled=true it puts the letter 'F' into the input control.
It should just set the focus and not add the 'F'.

Toggle of Alt accelerator works only after the FIRST time I use Menu
This is super weird.
On Avalonia if you hit alt key, it shows the underscore, then hit Alt key again it hides it. If you hit the accelerator, it activates the target and hides it.
In Consolonia, if you hit the Alt key it shows the underscore, then hit Alt key again it leaves it shown.
Unless I go to the Menu page. When I go to the menu page, then it starts working, and it works until I shut down the app.
WTF???

label2

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
src/Consolonia.Themes/Templates/Controls/Menu.axaml (2)

Line range hint 21-24: Add ConsoloniaAccessText for proper access key handling

The ContentPresenter is directly binding to Header without handling access keys. To address the underline feature and Alt key behavior issues mentioned in the PR, implement ConsoloniaAccessText here.

Apply this diff:

 <ContentPresenter Name="PART_HeaderPresenter"
                   Content="{TemplateBinding Header}"
-                  Margin="{TemplateBinding Padding}">
+                  Margin="{TemplateBinding Padding}">
+    <ContentPresenter.DataTemplates>
+        <DataTemplate DataType="System.String">
+            <controls:ConsoloniaAccessText Text="{Binding}" />
+        </DataTemplate>
+    </ContentPresenter.DataTemplates>
 </ContentPresenter>

Line range hint 1-93: Consider implementing a centralized access key manager

To address the reported issues comprehensively:

  1. The Alt+F key input issue suggests we need proper event handling at the control level
  2. The inconsistent Alt key toggle behavior indicates we need centralized state management
  3. The access key visibility persistence issue suggests we need proper state storage

Consider implementing a centralized access key manager that:

  • Manages the global Alt key state
  • Handles access key visibility consistently
  • Persists the state across navigation
  • Provides proper event handling for access key combinations

This would help ensure consistent behavior across the entire menu system.

Would you like me to help design this centralized access key manager?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4e902fb and ddf5e44.

📒 Files selected for processing (3)
  • src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs (2 hunks)
  • src/Consolonia.Themes/Templates/Controls/Menu.axaml (1 hunks)
  • src/Consolonia.Themes/Templates/Controls/MenuItem.axaml (0 hunks)
💤 Files with no reviewable changes (1)
  • src/Consolonia.Themes/Templates/Controls/MenuItem.axaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs
🧰 Additional context used
📓 Learnings (1)
src/Consolonia.Themes/Templates/Controls/Menu.axaml (1)
Learnt from: jinek
PR: jinek/Consolonia#176
File: src/Consolonia.Themes.TurboVision/Templates/Controls/MenuItem.axaml:131-131
Timestamp: 2024-12-05T18:23:58.201Z
Learning: In the Avalonia UI project, within `src/Consolonia.Themes.TurboVision/Templates/Controls/MenuItem.axaml`, MenuItem controls are intentionally designed without a `:pointerover` state to maintain touch-friendliness and consistency across controls.
🔇 Additional comments (2)
src/Consolonia.Themes/Templates/Controls/Menu.axaml (2)

Line range hint 39-47: Review ItemsPresenter focus behavior for Alt key toggle

The Alt key toggle issue (underscore visibility) might be related to focus handling in ItemsPresenter. The current FocusOnLoad behavior might need adjustment.

Let's check the focus handling implementation:

✅ Verification successful

Let me gather more information about the focus handling implementation to better understand the behavior.


Alt key toggle and focus behavior are correctly implemented

The implementation shows that:

  1. MenuExtensions.FocusOnLoad correctly handles focus management by focusing the first MenuItem when attached to the visual tree
  2. ConsoloniaAccessText properly manages the underscore visibility through the ShowAccessKey property, which controls text decorations for access keys

The current implementation follows the expected behavior for both focus handling and Alt key toggling of underscores. No adjustments are needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for focus-related code
rg -t cs "FocusOnLoad|ShowAccessKey" --glob "src/Consolonia*/**"

# Look for Alt key handling
ast-grep --pattern 'class $_ {
  $$$
  ShowAccessKey($$$) {
    $$$
  }
}'

Length of output: 1399


Script:

#!/bin/bash
# Check MenuExtensions implementation
cat "src/Consolonia.Themes/Templates/Controls/Helpers/MenuExtensions.cs"

# Check ConsoloniaAccessText implementation for Alt key handling
cat "src/Consolonia.Core/Controls/ConsoloniaAccessText.cs"

Length of output: 5479


Line range hint 28-29: Review Popup focus handling for Alt+F key issue

The Alt+F key issue where the 'F' character is being input might be related to focus handling in the Popup. Consider handling the key press event here.

Let's verify the key handling implementation:

@tomlm
Copy link
Collaborator Author

tomlm commented Dec 14, 2024

The second is an avalonia bug. I just repoed in avalonia proper.
I filed AvaloniaUI/Avalonia#17772

@jinek
Copy link
Owner

jinek commented Dec 14, 2024

First one I can check.
Do I need to review now? Lets please use draft PRs to indicate it's not for review in case it's not. It's sometimes hard for me to prioritize what to do here.

if (iPos >= 0 && iPos < Text.Length - 1)
{
inlines.Add(new Run(Text[..iPos]));
_accessRun = new Run(Text[++iPos..++iPos]);
Copy link
Owner

Choose a reason for hiding this comment

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

it looks stunning!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤪

@jinek
Copy link
Owner

jinek commented Dec 14, 2024

it works almost. There are 2 issues left: Accelerator used for Label puts focus on the input control AND puts accelerator key into the input

Could you please push the repro of label+input somewhere?

@tomlm
Copy link
Collaborator Author

tomlm commented Dec 14, 2024

It should be pushed....there should be a Label page in gallery

image

@tomlm
Copy link
Collaborator Author

tomlm commented Dec 14, 2024

I'm ready to check it in. Sorry. I was ready, then based on feedback on avalonia side I made some changes, and then feedback from you I added the Label/Button support. etc.

I will try to be more disclipined about using Draft PR. Sorry.

@jinek
Copy link
Owner

jinek commented Dec 14, 2024

I'm ready to check it in. Sorry. I was ready, then based on feedback on avalonia side I made some changes, and then feedback from you I added the Label/Button support. etc.

I will try to be more disclipined about using Draft PR. Sorry.

no worries. But I want to investigate ALT handling also, the guy you've changed.

Thought I have investigated the issue of producing excessive F.
Issue happens because ConsoleWindow.ConsoleOnKeyEvent produces RawTextInputEventArgs after the focus was already set because previously RawKeyEventArgs.Handled was not set to true by AccessKey infrastructure.
It looks like either Dispatcher.UIThread.InvokeAsync does not wait for the delegate to complete or may be this logic has been changed completely. I will check if Avalonia has reworked this part, we may be just need to reflect those changes from new version of Avalonia.

@tomlm
Copy link
Collaborator Author

tomlm commented Dec 14, 2024

I bet we should be awaiting the InvokeAsync. There are 2 patterns, there is Post() and Invoke(). Invoke returns a task, we should be careful about the semantics of which one we are using.

@jinek
Copy link
Owner

jinek commented Dec 14, 2024

I bet we should be awaiting the InvokeAsync. There are 2 patterns, there is Post() and Invoke(). Invoke returns a task, we should be careful about the semantics of which one we are using.

This one excluded. Task returned from Invoke properly awaits for access key to be processed.

I could not find matching code in Avalonia at all. Thinking may be I just invented this processing: if KeyDown event was not handled, then producing TextInput event.
I will try to do the trick by checking if a key was pressed together with ALT.

@jinek
Copy link
Owner

jinek commented Dec 14, 2024

Yeah, that helped. fixed first issue

@tomlm
Copy link
Collaborator Author

tomlm commented Dec 14, 2024

Second issue is Avalonia bug. It looks like we can work around by having an empty MENU on the page.

@jinek
Copy link
Owner

jinek commented Dec 14, 2024

@tomlm
please, check my last commit. I have removed special handling of ALT key. It seems all works fine without

@tomlm
Copy link
Collaborator Author

tomlm commented Dec 14, 2024

Looks good.

@tomlm tomlm merged commit 23ee278 into main Dec 14, 2024
3 checks passed
@tomlm tomlm deleted the tomlm/accessText branch December 14, 2024 21:17
@tomlm
Copy link
Collaborator Author

tomlm commented Dec 14, 2024

Thanks Evgeny!

If you are ever in Seattle I'll buy you a beer!

@jinek
Copy link
Owner

jinek commented Dec 14, 2024

No, I will buy you a beer. 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alt Key accelerators aren't rendered
2 participants