Skip to content

Ctrl + A on code in maximized window causes Exception #3750

Open
@mavaddat

Description

@mavaddat

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

Last 200 Keys:

 i l e n a m e Spacebar o f Spacebar t h e Spacebar X M L Spacebar w e l l - f o r m e d Enter
 Spacebar Spacebar $ ( $ u s i n g : C S D B M i g r a t i o n S t a t u s ) [ $ i ] . F i l e n a m e Spacebar = Spacebar $ x m l p a t h . F u l l N a m e Spacebar - r e p l a c e Spacebar ( [ r e g e x ] : : E s c a p e ( $ T p G x ) ) , Spacebar ' t p - g x ' Enter
 Enter
 Spacebar Spacebar # Spacebar R e l e a s e Spacebar t h e Spacebar s e m a p h o r e Enter
 Spacebar Spacebar $ ( $ u s i n g : s e m a p h o r e ) . R e l e a s e ( ) Enter
 } Ctrl+a

### Exception

System.InvalidOperationException: Cannot locate the offset in the rendered text that was pointed by the original cursor. Initial Coord: (35, -3) Buffer: (98, 30) Cursor: (3, 29)
   at Microsoft.PowerShell.PSConsoleReadLine.RecomputeInitialCoords(Boolean isTextBufferUnchanged)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Render()
   at Microsoft.PowerShell.PSConsoleReadLine.RenderWithPredictionQueryPaused()
   at Microsoft.PowerShell.PSConsoleReadLine.SelectAll(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

Screenshot

🛈 Note: Some data has been obscured for privacy.

Environment data

PS Version: 7.3.6
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.3.1-beta1
PSReadLine EditMode: Windows
OS: 10.0.19041.320 (WinBuild.160101.0800)

Window size

Before maximizing
BufferWidth: 98
BufferHeight: 30
After maximizing
BufferWidth: 183
BufferHeight: 51

Steps to reproduce

  1. Small PowerShell window.
  2. Multiline scriptblock at the prompt.
$CSDBMigrationStatus = Import-Csv -Path "$env:OneDriveCommercial\Documents\csdbMigrationPlan.csv"  # A CSV export of the latest version of the CSDB Migration Plan XLSX file
$semaphore = [System.Threading.Semaphore]::new(0,1)  # A semaphore to limit the number of threads accessing the CSDB object concurrently
$CSDBMigrationStatus | Where-Object -FilterScript { -not [string]::IsNullOrEmpty($_.'Full Path') } | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {  
# Get the export.log path for the manual export
$exportPath = $_.'Full Path' -replace 'tp-gx', $($using:TpGx) | Split-Path -Parent

# Get all the XML files in the export folder
$xmls = Get-ChildItem -Path $exportPath -Filter '*.xml' | Where-Object -FilterScript {-not (Select-String -Path $_ -Pattern 'This is DRAFT data to be used only for development')} 

# Get the latest XML with the 'well' keyword
$xmlPath = $xmls | Where-Object -FilterScript { $_.BaseName -match 'well' } | Sort-Object -Descending -Property CreationTimeUtc -Top 1

# If there is no such file, get the latest XML with the same name as the export folder
if ($null -eq $xmlPath -or $xmlPath.Count -eq 0) {
  $xmlPath = $xmls | Where-Object -FilterScript { $_.BaseName -match ([regex]::Escape(($exportPath | Split-Path -Leaf))) } | Sort-Object -Descending -Property CreationTimeUtc -Top 1
}

# Look up the index of the current item in the array
$i = $($using:CSDBMigrationStatus).IndexOf($_)

# Wait for the semaphore
$($using:semaphore).WaitOne()

# Set the filename of the XML well-formed
$($using:CSDBMigrationStatus)[$i].Filename = $xmlpath.FullName -replace ([regex]::Escape($TpGx)), 'tp-gx'

# Release the semaphore
$($using:semaphore).Release()
}
  1. Maximize window
  2. Select all using Ctrl + A
  3. Boom 💥 exception

Expected behavior

The original issue is that when I maximize, the text as displayed in the window is not the position of the editable underlying command text. That is, the maximize command isn't able to correctly reflow the command at the command prompt to anticipate where it is in the maximized context.

This is evident by the fact that moving the cursor around does not land in the correct place corresponding to the text as rendered. (I.e., the cursor does not edit the shown text and moving the cursor around doesn't follow the text as shown.)

To mitigate, I do a select all Ctrl + A to force the PowerShell to recalculate the text reflow. The highlighting will show be the boundaries of the text and allow me to understand how the text has moved.

Actual behavior

There is an exception thrown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-StabilityLabel for tracking stability IssuesNeeds-More InvestigationInitial investigation is done, but need to follow up.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions