fix(pwsh): ignore remove when in constrained language mode

This commit is contained in:
Jan De Dobbeleer 2022-09-16 07:31:14 +02:00 committed by Jan De Dobbeleer
parent 4056729e8e
commit 8d9fe9d3c8

View file

@ -354,12 +354,14 @@ Example:
function Enable-PoshLineError {}
# perform cleanup on removal so a new initialization in current session works
$ExecutionContext.SessionState.Module.OnRemove += {
if ((Get-PSReadLineKeyHandler -Key Spacebar).Function -eq 'OhMyPoshSpaceKeyHandler') {
Remove-PSReadLineKeyHandler -Key Spacebar
}
if ((Get-PSReadLineKeyHandler -Key Enter).Function -eq 'OhMyPoshEnterKeyHandler') {
Set-PSReadLineKeyHandler -Key Enter -Function AcceptLine
if ($ExecutionContext.SessionState.LanguageMode -ne "ConstrainedLanguage") {
$ExecutionContext.SessionState.Module.OnRemove += {
if ((Get-PSReadLineKeyHandler -Key Spacebar).Function -eq 'OhMyPoshSpaceKeyHandler') {
Remove-PSReadLineKeyHandler -Key Spacebar
}
if ((Get-PSReadLineKeyHandler -Key Enter).Function -eq 'OhMyPoshEnterKeyHandler') {
Set-PSReadLineKeyHandler -Key Enter -Function AcceptLine
}
}
}