Skip to content

Fix selection with Hidden wrapper not being ignored in commandmode - #7186

Open
lL1l1 wants to merge 8 commits into
developfrom
fix/commandmode-ignore-hiddenselect
Open

Fix selection with Hidden wrapper not being ignored in commandmode#7186
lL1l1 wants to merge 8 commits into
developfrom
fix/commandmode-ignore-hiddenselect

Conversation

@lL1l1

@lL1l1 lL1l1 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description of the proposed changes

Fixes selection done within the Hidden wrapper not being ignored in commandmode.lua.
gamemain.lua's SetIgnoreSelection is used since it also sets the ignore mode in commandmode.lua and it lets us avoid an import call every time selection changes, which is especially frequent for hidden selections.

Testing done on the proposed changes

Un-revert the debug logging commit.
Select a unit.
Select the move order, shift click once, then run this command while holding shift:

import('/lua/ui/game/selection.lua').Hidden(function()
    UISelectionByCategory('ALLUNITS', false, false, false, false)
    LOG('Selected units', table.getn(GetSelectedUnits()))
end)

letting go of shift should cancel command mode and not log anything. Before these changes it didn't.

Checklist

Summary by CodeRabbit

  • Bug Fixes
    • Fixed selection handling while the selection interface is temporarily hidden.
    • Prevented hidden selections from affecting command mode, unit views, rally points, sounds, and related updates.
    • Ensured previous selections are restored correctly after hidden selection operations.

lL1l1 added 4 commits July 22, 2026 01:06
Test with
```
import('/lua/ui/game/selection.lua').Hidden(function()
    UISelectionByCategory('ALLUNITS', false, false, false, false)
    LOG('Selected units', table.getn(GetSelectedUnits()))
end)
```
gamemain's SetIgnoreSelection calls commandmode's function too
This also allows us to skip the table accesses with import in gamemain every time we select stuff (+UI responiveness)
This reverts commit e14a779.
@lL1l1
lL1l1 requested review from 4z0t and Basilisk3 July 22, 2026 08:13
@lL1l1 lL1l1 added the area: ui Anything to do with the User Interface of the Game label Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Hidden selection callbacks now set gamemain’s ignore-selection state while restoring selections and command mode. OnSelectionChanged no longer exits solely because the selection UI is hidden, and the fix is documented in the changelog.

Changes

Selection handling

Layer / File(s) Summary
Bracket hidden callbacks with ignore state
lua/ui/game/selection.lua
Hidden(callback) enables gamemain selection ignoring during callback execution and selection restoration, then disables it afterward.
Continue hidden selection processing
lua/ui/game/gamemain.lua, changelog/snippets/fix.7186.md
OnSelectionChanged no longer returns when the selection UI is hidden, and the changelog records the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SelectionUI
  participant GameMain
  participant Callback
  SelectionUI->>GameMain: Enable ignore selection
  SelectionUI->>Callback: Run Hidden callback
  Callback->>GameMain: Restore selection and command mode
  SelectionUI->>GameMain: Disable ignore selection
Loading

Possibly related PRs

Suggested reviewers: 4z0t, basilisk3

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main fix to Hidden selection handling in command mode.
Description check ✅ Passed The description includes the proposed changes, testing, and checklist items and matches the template well enough.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/commandmode-ignore-hiddenselect

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lL1l1
lL1l1 marked this pull request as ready for review July 22, 2026 08:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lua/ui/game/selection.lua`:
- Around line 54-59: Protect the callback and selection-restoration sequence
around callback, SelectUnits, and CM.StartCommandMode using protected execution,
ensuring hidden_select is reset and gamemainSetIgnoreSelection(false) runs even
when any step raises. After cleanup, rethrow the original error while preserving
normal restoration behavior on success.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f19be17e-bd8d-4b63-903e-63dbbcdb14ff

📥 Commits

Reviewing files that changed from the base of the PR and between da311cd and d615d4a.

📒 Files selected for processing (3)
  • changelog/snippets/fix.7186.md
  • lua/ui/game/gamemain.lua
  • lua/ui/game/selection.lua
💤 Files with no reviewable changes (1)
  • lua/ui/game/gamemain.lua

Comment thread lua/ui/game/selection.lua Outdated
Comment on lines +54 to +59
gamemainSetIgnoreSelection(true)
callback()
SelectUnits(old_selection)
CM.StartCommandMode(current_command[1], current_command[2])
hidden_select = false
gamemainSetIgnoreSelection(false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Restore selection state on failure.

If callback(), SelectUnits(), or StartCommandMode() raises, execution skips lines 58-59 and leaves hidden_select and gamemain/commandmode’s ignoreSelection enabled permanently, suppressing later selection handling. Wrap the callback/restoration sequence in protected execution and clear both flags before rethrowing the original error.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/ui/game/selection.lua` around lines 54 - 59, Protect the callback and
selection-restoration sequence around callback, SelectUnits, and
CM.StartCommandMode using protected execution, ensuring hidden_select is reset
and gamemainSetIgnoreSelection(false) runs even when any step raises. After
cleanup, rethrow the original error while preserving normal restoration behavior
on success.

@4z0t

4z0t commented Jul 22, 2026

Copy link
Copy Markdown
Member

@Garanas decided to not make this code for everyone, so you'll have to @lL1l1 ...

@4z0t 4z0t left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use solution from IssueBlueprintCommandToUnits.

@4z0t

4z0t commented Jul 22, 2026

Copy link
Copy Markdown
Member

No, just fix the one you're touching in this PR

@lL1l1

lL1l1 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

I refactored it as requested and also noticed that the hidden state would be broken by errors so I wrapped it in pcall. If pcall fails it fixes the hidden state and then errors so the script that called it doesn't continue assuming something in the callback worked.

@lL1l1
lL1l1 requested a review from 4z0t July 23, 2026 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui Anything to do with the User Interface of the Game

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants