mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-03 15:27:26 -08:00
fix(pwsh): do not render a transient prompt when text is selected
This commit is contained in:
parent
9239b26209
commit
17da877767
|
@ -148,10 +148,6 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Set-TransientPrompt {
|
function Set-TransientPrompt {
|
||||||
param(
|
|
||||||
[string]$Key
|
|
||||||
)
|
|
||||||
|
|
||||||
$previousOutputEncoding = [Console]::OutputEncoding
|
$previousOutputEncoding = [Console]::OutputEncoding
|
||||||
try {
|
try {
|
||||||
$parseErrors = $null
|
$parseErrors = $null
|
||||||
|
@ -174,21 +170,23 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
|
||||||
[Microsoft.PowerShell.PSConsoleReadLine]::Undo()
|
[Microsoft.PowerShell.PSConsoleReadLine]::Undo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch ($Key) {
|
|
||||||
"Ctrl+c" { [Microsoft.PowerShell.PSConsoleReadLine]::CopyOrCancelLine() }
|
|
||||||
Default { [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() }
|
|
||||||
}
|
|
||||||
[Console]::OutputEncoding = $previousOutputEncoding
|
[Console]::OutputEncoding = $previousOutputEncoding
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (("::TRANSIENT::" -eq "true") -and ($ExecutionContext.SessionState.LanguageMode -ne "ConstrainedLanguage")) {
|
if (("::TRANSIENT::" -eq "true") -and ($ExecutionContext.SessionState.LanguageMode -ne "ConstrainedLanguage")) {
|
||||||
Set-PSReadLineKeyHandler -Key Enter -BriefDescription 'OhMyPoshEnterKeyHandler' -ScriptBlock {
|
Set-PSReadLineKeyHandler -Key Enter -BriefDescription 'OhMyPoshEnterKeyHandler' -ScriptBlock {
|
||||||
Set-TransientPrompt -Key "Enter"
|
Set-TransientPrompt
|
||||||
|
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
|
||||||
}
|
}
|
||||||
Set-PSReadLineKeyHandler -Key Ctrl+c -BriefDescription 'OhMyPoshCtrlCKeyHandler' -ScriptBlock {
|
Set-PSReadLineKeyHandler -Key Ctrl+c -BriefDescription 'OhMyPoshCtrlCKeyHandler' -ScriptBlock {
|
||||||
Set-TransientPrompt -Key "Ctrl+c"
|
$start = $null
|
||||||
|
[Microsoft.PowerShell.PSConsoleReadLine]::GetSelectionState([ref]$start, [ref]$null)
|
||||||
|
# only render a transient prompt when no text is selected
|
||||||
|
if ($start -eq -1) {
|
||||||
|
Set-TransientPrompt
|
||||||
|
}
|
||||||
|
[Microsoft.PowerShell.PSConsoleReadLine]::CopyOrCancelLine()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue