MenuComplete throws ArgumentOutOfRangeException after shrinking an open completion menu
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Start in Completion.cs, especially CreateCompletionMenu, UpdateMenuSelection, and the key loop in MenuCompleteImpl. Reproduce the 160-to-118-column ConPTY resize with the provided PowerShell commands, then inspect how active and filtered completion menus respond to dimension changes. Done means the menu redraws or cancels safely without invalid cursor positions while preserving input and selection where possible.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Prerequisites
- Write a descriptive title.
- Reproduce on the latest stable release: PSReadLine 2.4.5 (confirmed against the latest GitHub release).
- Search existing issues and the pinned exception/version guidance (#1306).
Exception report
Captured from a deterministic reproduction with the unmodified PSReadLine 2.4.5 DLL on 2026-09-30. The text below is transcribed from the ConPTY screen snapshot; the only input was the synthetic completion prefix and navigation keys.
### Environment
PSReadLine: 2.4.5
PowerShell: 7.6.5
OS: Microsoft Windows 10.0.26200
BufferWidth: 118
BufferHeight: 34
Last 13 Keys:
z z r e s i z e Tab RightArrow RightArrow RightArrow RightArrow
### Exception
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'left')
Actual value was 120.
at System.ConsolePal.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.Internal.VirtualTerminal.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.PSConsoleReadLine.Menu.UpdateMenuSelection(Int32 selectedItem, Boolean select, Boolean showTooltips, String toolTipColor)
at Microsoft.PowerShell.PSConsoleReadLine.MenuCompleteImpl(Menu menu, CommandCompletion completions)
at Microsoft.PowerShell.PSConsoleReadLine.PossibleCompletionsImpl(CommandCompletion completions, Boolean menuSelect)
at Microsoft.PowerShell.PSConsoleReadLine.CompleteImpl(Boolean menuSelect)
at Microsoft.PowerShell.PSConsoleReadLine.MenuComplete(Nullable`1 key, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)
Screenshot
N/A. The automated ConPTY reproduction captured text rather than a GUI screenshot. Before resizing, the 25 candidates formed five columns; after shrinking, navigation attempted to use the fifth column at offset 120, outside the new 118-column buffer.
Environment data
The version, OS and buffer dimensions above are from the failing session's exception report. The host was PowerShell ConsoleHost in a Windows ConPTY terminal (Unison), started with -NoProfile; Tab was bound to MenuComplete. History saving was disabled and candidates were synthetic functions, with no user profile, CLI extension or external completer involved.
Initial buffer: 160 columns x 34 rows.
Resized buffer: 118 columns x 34 rows.
The original real-world trigger was moving the terminal from a 100% scaling monitor to a 150% scaling monitor while the completion menu was open. A deterministic ResizePseudoConsole width change reproduces the same left = 120 exception without requiring a second monitor. I have not independently reproduced this in Windows Terminal, and a full dual-monitor GUI retest of the local fix is still pending.
Steps to reproduce
-
Start
pwsh -NoLogo -NoProfilewith the official, unmodified PSReadLine 2.4.5 module in a 160-column, 34-row terminal. -
Set up the same 25 synthetic completion candidates and Tab binding:
Import-Module PSReadLine -RequiredVersion 2.4.5 Set-PSReadLineOption -EditMode Windows -HistorySaveStyle SaveNothing Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete function global:prompt { 'RESIZE> ' } 1..25 | ForEach-Object { $name = 'zzresize' + $_.ToString('00') + 'abcdefghijklmnopqr' Set-Item -Path ('function:global:' + $name) -Value { } } -
Type
zzresizeand press Tab. Keep the completion menu open. -
Shrink the terminal to 118 columns, keeping 34 rows, without dismissing the menu. In the automated reproduction this is a ConPTY resize from
(160, 34)to(118, 34), followed by a 300 ms wait. -
Press RightArrow four times. PSReadLine reports the exception above.
Expected behavior
Recalculate and redraw the active completion menu for the new buffer width before navigating. Preserve the selected completion and input when possible. If the new dimensions cannot accommodate the menu, cancel it safely rather than addressing an invalid cursor position.
Actual behavior
The menu keeps its original layout. Each candidate is 28 cells wide, giving a cached ColumnWidth of 30, five columns and five rows at width 160. Moving to the fifth column then requests left = 30 * 4 = 120, although the current buffer only has columns 0 through 117. The completion menu throws ArgumentOutOfRangeException and its display/input can become mixed after reflow.
Source analysis and local fix evidence
CreateCompletionMenuin v2.4.5 computesColumnWidth,ColumnsandRowsfrom the initial buffer width.UpdateMenuSelectionderives the cursor column from the cachedColumnWidthandRows.- The key loop in
MenuCompleteImplreads navigation keys inside the active menu without rebuilding that layout when the buffer dimensions change. - As of filing,
Completion.cson master at commit 2984546f62da9f63c31aba965ec3008fcb107024 has the same Git blob as v2.4.5 (c6654f9241c0d18c1749318015a3e5b00b8c1ef2). This is a source comparison, not a claim that a master build was separately tested.
A local downstream patch against v2.4.5 detects dimension changes after the menu's key read, recalculates the active and filtered-stack menu layouts, and refreshes their drawing positions together with the prompt. It cancels safely when there is insufficient space and avoids executing input when an Enter key only belonged to a canceled completion menu.
Real ConPTY regression checks with that patch passed under PowerShell 7.6.5 and Windows PowerShell 5.1: repeated width/height changes, selected candidate and input preservation, filtering followed by Backspace, Escape, accepting with Enter, insufficient-space cancellation, and reopening the menu. These are local downstream results, not an upstream fix or a completed dual-monitor GUI verification.
Related reports checked
#4187 also reports Menu.UpdateMenuSelection, but describes a top = 27 error at a fixed width rather than a reproducible cached-column failure after shrinking. #3637 concerns the input/prompt anchor after resizing. I did not find an existing report with this deterministic 160 -> 118 active-menu reproduction; please link or consolidate this issue if it shares the same root cause with another report.
- Ngôn ngữ chính
- C#
- Star
- 4.4k
- Fork
- 346
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PowerShell/PSReadLine
-
Get-PSReadLineOption emits the ListView window-size warning, so prompt modules trigger it on every shell startCó thể đã có người làm @thc1006 đã nhận 77 ngày trước. Đang mởNeeds-Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
PowerShell/PSReadLine#5205 ·
-
Needs-Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
PowerShell/PSReadLine#5195 ·
-
Needs-Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
PowerShell/PSReadLine#5121 ·
-
Needs-Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
PowerShell/PSReadLine#5045 ·
-
Area-CommandHelp Issue-Enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
PowerShell/PSReadLine#3470 · 3 reaction ·
Tất cả issue của PowerShell/PSReadLine
Issue tương tự
-
area-templates triage:bot-seen triage:needs-human
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
microsoft/aspire#22356 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Needs-Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
PowerShell/PowerShell#28432 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/aspire.dev#2184 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area-controls-refreshview platform/ios s/triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
dotnet/maui#40314 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Needs: Triage (Functions) v5 v5-preview5
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Azure/azure-functions-core-tools#5918 ·
Maintainer thường phản hồi trong vòng 1 ngày