Skip to content

Commit aee7d2f

Browse files
Copilotkelleyma49
andauthored
Add configurable PreviewWindow behavior for tab completion (#361)
* Initial plan * Add TabCompletionPreviewWindow configuration option to Set-PsFzfOption - Added script-level variable $script:TabCompletionPreviewWindow with default 'hidden|down|right|right:hidden' - Added TabCompletionPreviewWindow parameter to Set-PsFzfOption function - Updated Invoke-FzfTabCompletionInner to parse and use the configurable PreviewWindow value - Added comprehensive tests for the new configuration option - All 62 tests passing Co-authored-by: kelleyma49 <2152684+kelleyma49@users.noreply.github.com> * Add documentation for TabCompletionPreviewWindow option - Updated Set-PsFzfOption.md with detailed parameter documentation - Added section in README.md explaining tab completion preview window customization - Included examples showing different configuration options Co-authored-by: kelleyma49 <2152684+kelleyma49@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: kelleyma49 <2152684+kelleyma49@users.noreply.github.com>
1 parent 9a0d808 commit aee7d2f

File tree

5 files changed

+83
-4
lines changed

5 files changed

+83
-4
lines changed

PSFzf.Base.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ $script:OverrideFzfDefaults = $null
149149
$script:PSReadlineHandlerChords = @()
150150
$script:TabContinuousTrigger = [IO.Path]::DirectorySeparatorChar.ToString()
151151
$script:PsReadlineHandlerProviderDelimiter = ','
152+
$script:TabCompletionPreviewWindow = 'hidden|down|right|right:hidden'
152153

153154
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove =
154155
{
@@ -209,7 +210,9 @@ function Set-PsFzfOption {
209210
[ScriptBlock]
210211
$AltCCommand,
211212
[string]
212-
$PsReadlineHandlerProviderDelimiter
213+
$PsReadlineHandlerProviderDelimiter,
214+
[string]
215+
$TabCompletionPreviewWindow
213216
)
214217
if ($PSBoundParameters.ContainsKey('TabExpansion')) {
215218
SetTabExpansion $TabExpansion
@@ -260,6 +263,10 @@ function Set-PsFzfOption {
260263
if ($PSBoundParameters.ContainsKey('PsReadlineHandlerProviderDelimiter')) {
261264
$script:PsReadlineHandlerProviderDelimiter = $PsReadlineHandlerProviderDelimiter
262265
}
266+
267+
if ($PSBoundParameters.ContainsKey('TabCompletionPreviewWindow')) {
268+
$script:TabCompletionPreviewWindow = $TabCompletionPreviewWindow
269+
}
263270
}
264271

265272
function Stop-Pipeline {

PSFzf.TabExpansion.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,21 @@ function script:Invoke-FzfTabCompletionInner() {
289289
# normalize so path works correctly for Windows:
290290
$path = $PWD.ProviderPath.Replace('\', '/')
291291

292+
# Parse the TabCompletionPreviewWindow option to extract initial state and change-preview-window options
293+
$previewParts = $script:TabCompletionPreviewWindow -split '\|', 2
294+
$initialPreviewState = $previewParts[0]
295+
$changePreviewWindowOptions = if ($previewParts.Length -gt 1) { $previewParts[1] } else { 'down|right|right:hidden' }
296+
292297
$arguments = @{
293298
Layout = 'reverse'
294299
Expect = "$expectTriggers"
295-
PreviewWindow = 'hidden'
300+
PreviewWindow = $initialPreviewState
296301
}
297302
if ($isTabTrigger) {
298-
$arguments["Bind"] = @('ctrl-/:change-preview-window:down|right|right:hidden')
303+
$arguments["Bind"] = @("ctrl-/:change-preview-window:$changePreviewWindowOptions")
299304
}
300305
else {
301-
$arguments["Bind"] = @('tab:down', 'btab:up', 'ctrl-/:change-preview-window:down|right|right:hidden')
306+
$arguments["Bind"] = @('tab:down', 'btab:up', "ctrl-/:change-preview-window:$changePreviewWindowOptions")
302307
}
303308

304309
# need to handle parameters differently so PowerShell doesn't parse completion item as a script parameter:

PSFzf.tests.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,34 @@ Describe "Set-PsFzfOption PsReadlineHandlerProviderDelimiter" {
650650
}
651651
}
652652

653+
Describe "Set-PsFzfOption TabCompletionPreviewWindow" {
654+
InModuleScope PsFzf {
655+
Context "Default preview window configuration" {
656+
It "Should default to 'hidden|down|right|right:hidden'" {
657+
# The default preview window configuration should be 'hidden|down|right|right:hidden'
658+
$script:TabCompletionPreviewWindow | Should -Be 'hidden|down|right|right:hidden'
659+
}
660+
}
661+
662+
Context "Can override preview window configuration" {
663+
It "Should allow setting custom preview window configuration" {
664+
Set-PsFzfOption -TabCompletionPreviewWindow 'visible|up|left'
665+
$script:TabCompletionPreviewWindow | Should -Be 'visible|up|left'
666+
}
667+
668+
It "Should allow setting to hidden with different change options" {
669+
Set-PsFzfOption -TabCompletionPreviewWindow 'hidden|up|down|left:hidden'
670+
$script:TabCompletionPreviewWindow | Should -Be 'hidden|up|down|left:hidden'
671+
}
672+
673+
It "Should allow setting back to default" {
674+
Set-PsFzfOption -TabCompletionPreviewWindow 'hidden|down|right|right:hidden'
675+
$script:TabCompletionPreviewWindow | Should -Be 'hidden|down|right|right:hidden'
676+
}
677+
}
678+
}
679+
}
680+
653681
Describe "Get-EditorLaunch" {
654682

655683

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ Use the following command to enable tab expansion:
8888
Set-PsFzfOption -TabExpansion
8989
```
9090

91+
### Tab Completion Preview Window
92+
93+
By default, the tab completion preview window starts hidden and can be toggled with <kbd>Ctrl+/</kbd> to cycle through different positions (down, right, or hidden). You can customize this behavior:
94+
95+
```powershell
96+
# Start with visible preview on the right
97+
Set-PsFzfOption -TabCompletionPreviewWindow 'right|down|hidden'
98+
99+
# Start hidden and toggle between up, left, and hidden
100+
Set-PsFzfOption -TabCompletionPreviewWindow 'hidden|up|left|hidden'
101+
```
102+
103+
The format is `initial_state|change_preview_window_options` where the first part sets whether the preview window is initially visible or hidden, and the rest defines the states to cycle through when pressing <kbd>Ctrl+/</kbd>.
104+
91105
## Using within a Pipeline
92106

93107
`Invoke-Fzf` works with input from a pipeline. You can use it in the middle of a pipeline, or as part of an expression.

docs/Set-PsFzfOption.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,31 @@ Default value: ','
271271
Accept pipeline input: False
272272
Accept wildcard characters: False
273273
```
274+
275+
### -TabCompletionPreviewWindow
276+
Specifies the preview window behavior for tab completion. The format is 'initial_state|change_preview_window_options' where the first part sets the initial state of the preview window (e.g., 'hidden' or 'visible'), and the rest is passed to the change-preview-window command (typically bound to Ctrl+/).
277+
278+
```powershell
279+
# example - start with hidden preview, toggle between up, left, and hidden:
280+
Set-PsFzfOption -TabCompletionPreviewWindow 'hidden|up|left|hidden'
281+
282+
# example - start with visible preview on the right:
283+
Set-PsFzfOption -TabCompletionPreviewWindow 'right|up|down|hidden'
284+
285+
# default - start hidden, toggle between down, right, and right:hidden:
286+
Set-PsFzfOption -TabCompletionPreviewWindow 'hidden|down|right|right:hidden'
287+
```
288+
```yaml
289+
Type: String
290+
Parameter Sets: (All)
291+
Aliases:
292+
293+
Required: False
294+
Position: Named
295+
Default value: 'hidden|down|right|right:hidden'
296+
Accept pipeline input: False
297+
Accept wildcard characters: False
298+
```
274299
## INPUTS
275300
### None
276301

0 commit comments

Comments
 (0)