question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ctrl + A on code in maximized window causes Exception

See original GitHub issue

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 <kbd>Ctrl</kbd> + <kbd>A</kbd>
  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 <kbd>Ctrl</kbd> + <kbd>A</kbd> 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.

Issue Analytics

  • State:open
  • Created 2 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mavaddatcommented, Jul 21, 2023

Can you paste using Ctrl+v and see if there is a difference? Also, can you also try it in a PowerShell session without loading your profile (so that the influence from your custom prompts can be ruled out)?

Nice catch! I see that the issue does not arise in pwsh -NoProfile -NoLogo (i.e., without loading my profile), so this suggests that it is only happening in conjunction with @JanDeDobbeleer ohmyposh.

You are right that I was pasting with right-click. I see the issue persists with <kbd>Ctrl</kbd>+<kbd>v</kbd> though if I am using my custom prompts.

0reactions
mavaddatcommented, Jul 21, 2023

Sure, it is the standard setup for oh-my-posh with oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/jandedobbeleer.omp.json" | Invoke-Expression in my PowerShell profile.

This is my oh-my-posh config:

JSON output of oh-my-posh.exe config export

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "version": 2,
  "final_space": true,
  "console_title_template": "{{ .Shell }} in {{ .Folder }}",
  "blocks": [
    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "session",
          "style": "diamond",
          "foreground": "#ffffff",
          "background": "#c386f1",
          "leading_diamond": "\ue0b6",
          "trailing_diamond": "\ue0b0",
          "template": " {{ .UserName }} "
        },
        {
          "type": "path",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#ffffff",
          "background": "#ff479c",
          "template": " \uea83  {{ .Path }} ",
          "properties": {
            "folder_separator_icon": " \ue0b1 ",
            "home_icon": "~",
            "style": "folder"
          }
        },
        {
          "type": "git",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#193549",
          "background": "#fffb38",
          "background_templates": [
            "{{ if or (.Working.Changed) (.Staging.Changed) }}#FF9248{{ end }}",
            "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#ff4500{{ end }}",
            "{{ if gt .Ahead 0 }}#B388FF{{ end }}",
            "{{ if gt .Behind 0 }}#B388FF{{ end }}"
          ],
          "leading_diamond": "\ue0b6",
          "trailing_diamond": "\ue0b4",
          "template": " {{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \ueb4b {{ .StashCount }}{{ end }} ",
          "properties": {
            "branch_max_length": 25,
            "fetch_stash_count": true,
            "fetch_status": true,
            "fetch_upstream_icon": true
          }
        },
        {
          "type": "node",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#ffffff",
          "background": "#6CA35E",
          "template": " \ue718 {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} ",
          "properties": {
            "fetch_version": true
          }
        },
        {
          "type": "go",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#111111",
          "background": "#8ED1F7",
          "template": " \ue626 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
          "properties": {
            "fetch_version": true
          }
        },
        {
          "type": "julia",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#111111",
          "background": "#4063D8",
          "template": " \ue624 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
          "properties": {
            "fetch_version": true
          }
        },
        {
          "type": "python",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#111111",
          "background": "#FFDE57",
          "template": " \ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
          "properties": {
            "display_mode": "files",
            "fetch_virtual_env": false
          }
        },
        {
          "type": "ruby",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#ffffff",
          "background": "#AE1401",
          "template": " \ue791 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
          "properties": {
            "display_mode": "files",
            "fetch_version": true
          }
        },
        {
          "type": "azfunc",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#ffffff",
          "background": "#FEAC19",
          "template": " \uf0e7{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
          "properties": {
            "display_mode": "files",
            "fetch_version": false
          }
        },
        {
          "type": "aws",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#ffffff",
          "background_templates": [
            "{{if contains \"default\" .Profile}}#FFA400{{end}}",
            "{{if contains \"jan\" .Profile}}#f1184c{{end}}"
          ],
          "template": " \ue7ad {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} ",
          "properties": {
            "display_default": false
          }
        },
        {
          "type": "root",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#111111",
          "background": "#ffff66",
          "template": " \uf0ad "
        },
        {
          "type": "executiontime",
          "style": "plain",
          "foreground": "#ffffff",
          "background": "#83769c",
          "template": "<transparent>\ue0b0</> \ueba2 {{ .FormattedMs }}\u2800",
          "properties": {
            "always_enabled": true
          }
        },
        {
          "type": "exit",
          "style": "diamond",
          "foreground": "#ffffff",
          "background": "#00897b",
          "background_templates": [
            "{{ if gt .Code 0 }}#e91e63{{ end }}"
          ],
          "trailing_diamond": "\ue0b4",
          "template": "<parentBackground>\ue0b0</> \ue23a ",
          "properties": {
            "always_enabled": true
          }
        }
      ]
    },
    {
      "type": "rprompt",
      "segments": [
        {
          "type": "shell",
          "style": "plain",
          "foreground": "#ffffff",
          "background": "#0077c2",
          "template": "<#0077c2,transparent>\ue0b6</> \uf489 {{ .Name }} <transparent,#0077c2>\ue0b2</>"
        },
        {
          "type": "ytm",
          "style": "powerline",
          "powerline_symbol": "\ue0b2",
          "invert_powerline": true,
          "foreground": "#111111",
          "background": "#1BD760",
          "template": " \uf167 {{ .Icon }}{{ if ne .Status \"stopped\" }}{{ .Artist }} - {{ .Track }}{{ end }} ",
          "properties": {
            "paused_icon": "\uf04c ",
            "playing_icon": "\uf04b "
          }
        },
        {
          "type": "battery",
          "style": "powerline",
          "powerline_symbol": "\ue0b2",
          "invert_powerline": true,
          "foreground": "#ffffff",
          "background": "#f36943",
          "background_templates": [
            "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}",
            "{{if eq \"Discharging\" .State.String}}#ff5722{{end}}",
            "{{if eq \"Full\" .State.String}}#4caf50{{end}}"
          ],
          "template": " {{ if not .Error }}{{ .Icon }}{{ .Percentage }}{{ end }}{{ .Error }}\uf295 ",
          "properties": {
            "charged_icon": "\ue22f ",
            "charging_icon": "\ue234 ",
            "discharging_icon": "\ue231 "
          }
        },
        {
          "type": "time",
          "style": "diamond",
          "invert_powerline": true,
          "foreground": "#111111",
          "background": "#2e9599",
          "leading_diamond": "\ue0b2",
          "trailing_diamond": "\ue0b4",
          "template": " {{ .CurrentDate | date .Format }} "
        }
      ]
    }
  ]
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clicking Top of Some Maximized Applications Causes ...
Sometimes when I have a maximized application with another maximized window behind it, clicking the very top of the title bar gives the...
Read more >
How to maximize a UWP window (not fullscreen)
The Windows system keyboard shortcuts to maximize and minimize the active window are WinKey + Up Arrow, WinKey + Down Arrow, respectively. Your ......
Read more >
How to change the default behaviour of the fullscreen ...
You can go to System Preferences -> Dock uncheck "Double-click a window's title bar to minimize" and then, when you double click on...
Read more >
Accessibility in Visual Studio Code
You can control whether VS Code uses screen reader mode with the Editor: Accessibility Support setting ( editor.accessibilitySupport ) and the values are...
Read more >
Windows shortcut to COMPLETELY maximize a window
You can use the following key combos: F11 - Kiosk Mode / Fullscreen; Win + ↑ - Maximize.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found