Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PSFzf.Base.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ function Invoke-FzfPsReadlineHandlerHistory {

$result = Get-PickedHistory -Query $line -UsePSReadLineHistory
if ($result -is [system.array]) {
$result = $result -join "```n"
$result = $result -join "`n"
}

InvokePromptHack
Expand Down
51 changes: 51 additions & 0 deletions PSFzf.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -842,5 +842,56 @@ if ( $false ) {
}
}
}

}
}

Describe "Invoke-FzfPsReadlineHandlerHistory multiline insertion" {
InModuleScope PsFzf {
BeforeEach {
Mock Get-PSConsoleReadLineBufferState {
[pscustomobject]@{
Line = ''
Cursor = 0
}
} -ModuleName PsFzf

Mock InvokePromptHack {} -ModuleName PsFzf
Mock Replace-PSConsoleReadLineText {} -ModuleName PsFzf
}

It "Should join multiline history selections with newlines only" {
$historySelection = @(
'$a = 1'
'$b = 2'
'$c = 3'
)
$expected = $historySelection -join "`n"

Mock Get-PickedHistory { $historySelection } -ModuleName PsFzf

Invoke-FzfPsReadlineHandlerHistory

Should -Invoke 'Replace-PSConsoleReadLineText' -Times 1 -ModuleName PsFzf -ParameterFilter {
$Start -eq 0 -and $Length -eq 0 -and $ReplacementText -eq $expected
}
}

It "Should preserve explicit backticks from history entries" {
$historySelection = @(
'$a = 1 `'
' + 2 `'
' + 3'
)
$expected = $historySelection -join "`n"

Mock Get-PickedHistory { $historySelection } -ModuleName PsFzf

Invoke-FzfPsReadlineHandlerHistory

Should -Invoke 'Replace-PSConsoleReadLineText' -Times 1 -ModuleName PsFzf -ParameterFilter {
$Start -eq 0 -and $Length -eq 0 -and $ReplacementText -eq $expected
}
}
}
}