@@ -235,7 +235,6 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
235235 rcfiles_start_time = " $rcStartTime "
236236 rcfiles_end_time = " $rcEndTime "
237237 shell_plugins = ' '
238- # The user's preference, not the session's live edit mode, which Warp overrides.
239238 vi_mode_enabled = $ (if ($script :viEditModeOverridden ) { ' 1' } else { ' ' })
240239 os_category = $osCategory
241240 linux_distribution = " $linuxDistribution "
@@ -352,41 +351,19 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
352351 # it is set to $false.
353352 $script :commandNotFound = $false
354353
355- # Set when Warp turns off PSReadLine's vi edit mode for this session, so that the
356- # 'Bootstrapped' payload can still report the user's preference for vi keybindings.
357- # See Warp-Configure-PSReadLine for why the edit mode is overridden.
354+ # Reports the user's vi preference in the 'Bootstrapped' payload even though the session's
355+ # live edit mode is overridden. See Warp-Configure-PSReadLine.
358356 $script :viEditModeOverridden = $false
359357
360358 function Warp-Configure-PSReadLine {
361- # Warp drives PSReadLine over the PTY with two chords that are a bare Escape plus a
362- # printable character: 'Alt+1' reports and drains the input buffer on every prompt, and
363- # 'Alt+2' clears it ahead of every submitted command. ConPTY readily delivers the two
364- # bytes in separate reads, and a chord split that way never dispatches, because 'Alt+1'
365- # is its own dispatch entry rather than the two-key chord 'Escape,1'. What the stray
366- # Escape then costs is entirely down to the edit mode. Measured on PSReadLine 2.3.5:
367- #
368- # Emacs Escape is bound to no function at all, only ever the first key of two-key
369- # chords ('Escape,f' and friends), so the fragment resolves to an unbound chord
370- # and is swallowed, leaving the buffer untouched.
371- # Windows Escape is RevertLine, so the fragment clears the line and the digit then
372- # self-inserts. That is the stray '1'/'2' prefix of GH #10891.
373- # Vi Escape is ViCommandMode, so the fragment strands the editor in command mode
374- # and everything Warp writes next is reinterpreted as vi edits. A submitted
375- # 'echo hello' arrives as 'o hello'.
376- #
377- # Only vi is overridden, because only vi reinterprets the command. Windows edit mode is
378- # PSReadLine's default on Windows, so forcing Emacs there would reset the key handlers of
379- # every Windows user to address a milder, separately tracked defect. Nothing the user can
380- # see changes: their keystrokes go through Warp's own input editor, never PSReadLine's. A
381- # vi user does lose PSReadLine handlers registered elsewhere, since changing the edit mode
382- # resets them all; that is an accepted trade, because those handlers are equally
383- # unreachable inside Warp. fish resolves the same conflict the same way, resetting
384- # 'fish_key_bindings' to the defaults on every precmd.
385- #
386- # Reasserting this on every prompt, rather than once after the user's profile is sourced,
387- # also covers an edit mode set later in the session, from the next prompt onward. The
388- # check keeps that cheap and non-destructive, and the handler reset it guards against is
389- # why this has to precede the Set-PSReadLineKeyHandler calls below.
359+ # The 'Alt+1' and 'Alt+2' chords below reach PSReadLine as a bare Escape plus a digit, and
360+ # a chord split across reads -- which ConPTY readily produces -- never dispatches. Emacs
361+ # swallows the stray Escape, but Vi binds it to ViCommandMode, so everything Warp writes
362+ # next is reinterpreted as vi edits and 'echo hello' submits as 'o hello'. Only vi is
363+ # overridden, because only vi corrupts the command; the milder stray-digit damage under
364+ # the 'Windows' edit mode is GH #10891. The override costs a vi user nothing they can see,
365+ # since a Warpified session's keystrokes go through Warp's input editor rather than
366+ # PSReadLine's, and it must precede the bindings because it resets every key handler.
390367 if ((Get-PSReadLineOption ).EditMode -eq ' Vi' ) {
391368 $script :viEditModeOverridden = $true
392369 Set-PSReadLineOption - EditMode Emacs
@@ -997,10 +974,8 @@ $null = New-Module -Name Warp-Module -ScriptBlock {
997974
998975 function Warp-Finish-Bootstrap {
999976 param ([decimal ]$rcStartTime , [decimal ]$rcEndTime )
1000- # Sourcing the user's profiles can reconfigure PSReadLine out from under the bootstrap's
1001- # own Warp-Precmd call, which ran before them: 'Set-PSReadLineOption -EditMode Vi' resets
1002- # every key handler and so unbinds Warp's chords. Reconfiguring here, rather than waiting
1003- # for the first prompt, also means the payload Warp-Bootstrapped sends below reports it.
977+ # The profiles just sourced ran after the bootstrap's own Warp-Precmd, and setting the vi
978+ # edit mode there unbinds Warp's chords by resetting every key handler.
1004979 Warp- Configure- PSReadLine
1005980
1006981 # This is the closest we can get in PowerShell to a proper preexec hook. We wrap the
0 commit comments