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

Fix "Context menu on desktop shows incorrect items after the second showing" #1693

Merged
merged 4 commits into from
Nov 16, 2024

Conversation

igordmn
Copy link
Collaborator

@igordmn igordmn commented Nov 15, 2024

Fixes https://youtrack.jetbrains.com/issue/CMP-7083/Context-menu-on-desktop-shows-incorrect-items-after-second-showing

The issue was that after the first click we remembered context items, but they are constructed dynamically depending on the selected text.

Testing

  • the snippet from the issue
  • a new unit test

Release Notes

Fixes - Desktop

  • Fix "Context menu on desktop shows incorrect items after the second showing"

…howing"

Fixes https://youtrack.jetbrains.com/issue/CMP-7083/Context-menu-on-desktop-shows-incorrect-items-after-second-showing

The issue was that after the first click we remembered context items, but they are constructed dynamically depending on the selected text.

## Testing
- the snippet from the issue
- a new unit test

## Release Notes
### Fixes - Desktop
- Fix "Context menu on desktop shows incorrect items after the second showing"
@igordmn igordmn requested a review from m-sasha November 15, 2024 15:45

internal val allItemsSeq: Sequence<ContextMenuItem>
private val allItemsSeq: Sequence<ContextMenuItem>
Copy link
Member

Choose a reason for hiding this comment

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

Not really related to the change in this PR, but why do we need a sequence here? We could do the same with

    internal val allItems: List<ContextMenuItem>
        get() = buildList {
            var current: ContextMenuData? = this@ContextMenuData
            while (current != null) {
                addAll(current.items())
                current = current.next
            }
        }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Your code is better

val Current get() = overriddenCurrent ?: _current

@VisibleForTesting
fun withOverriddenCurrent(newCurrent: DesktopPlatform, body: () -> Unit) {
Copy link
Member

Choose a reason for hiding this comment

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

Not crucial, but such functions are more useful if they're inline, and return what body returns.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@igordmn igordmn merged commit c9e8958 into jb-main Nov 16, 2024
7 checks passed
@igordmn igordmn deleted the igor.demin/fix-context-menu-copy branch November 16, 2024 00:40
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.

2 participants