1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2025-01-15 19:26:50 +00:00

fix(init/pwsh): preserve ViModeChangeHandler (#6225)

* Combine ViModeChangeHandler

If a user has defined a ViModeChangeHandler setting this would respect that as well as redraw the prompt (to allow rendering things like the character change).

* Add newline

* Use call operator to limit new closure scope

* Pass any args to original handler
This commit is contained in:
Gilbert Sanchez 2024-12-27 02:11:45 -08:00 committed by GitHub
parent 1f4b664cff
commit 9b6d394e01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -211,8 +211,20 @@ $null = New-Module starship {
)
try {
Set-PSReadLineOption -ViModeIndicator script -ViModeChangeHandler {
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
# Combine user defined ViModeChangeHandler if it exists
if((Get-PSReadLineOption).ViModeChangeHandler){
# &{...} to limit the scope of the GetNewClosure
& {
$originalHandler = (Get-PSReadLineOption).ViModeChangeHandler
Set-PSReadLineOption -ViModeChangeHandler {
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
& $originalHandler @args
}.GetNewClosure()
}
} else {
Set-PSReadLineOption -ViModeIndicator script -ViModeChangeHandler {
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
}
}
} catch {}