diff --git a/module/CHANGELOG-CN.md b/module/CHANGELOG-CN.md index 81b3109..1ee5858 100644 --- a/module/CHANGELOG-CN.md +++ b/module/CHANGELOG-CN.md @@ -3,6 +3,16 @@ 简体中文
+## 4.2.6 (2024/8/10) + +- 修复补全项列表为空的bug +- 如果使用 `Windows PowerShell`,且使用了命令行主题(如: oh-my-posh),当补全菜单显示在上方时,可能会导致当前行附近的文字及图标错乱 + - 解决方案: + 1. 禁用命令行主题 + 2. 尽量让补全菜单显示在下方(只要当前行在窗口中部以上即可) + 3. 不要使用 `Windows PowerShell`,直接使用 [`PowerShell`](https://github.com/PowerShell/PowerShell) + - `Windows PowerShell` 真的很差,小问题总是很多 + ## 4.2.5 (2024/8/10) - 如果菜单启用了前缀匹配(`menu_is_prefix_match`),当有公共前缀时,只提取补全的值 @@ -10,7 +20,7 @@ ## 4.2.4 (2024/8/10) -- 修复了因为一个代码文件使用了 LF 换行符导致 Windows PowerShell 模块加载错误的问题 +- 修复了因为一个代码文件使用了 LF 换行符导致 `Windows PowerShell` 模块加载错误的问题 - 对于源代码文件,将 LF 换行符替换为 CRLF 换行符,UTF-8 编码替换为 UTF-8-BOM 编码 - 修复了非 Windows 环境的初始化导入缺失的问题 - 更改源代码文件目录结构 diff --git a/module/CHANGELOG.md b/module/CHANGELOG.md index c49e8e9..0e9a2f8 100644 --- a/module/CHANGELOG.md +++ b/module/CHANGELOG.md @@ -3,6 +3,16 @@ English +## 4.2.6 (2024/8/10) + +- Fix a bug where the list of completions list was empty. +- If using `Windows PowerShell` and using a command-line theme (such as oh-my-posh), it may cause the current line and nearby text and icons to be distorted when the completion menu is displayed above the current line. + - Solution: + 1. Disable the command-line theme. + 2. Try to make the completion menu display below the current line. (Only if the current line is above the middle of the window.) + 3. Do not use `Windows PowerShell`, use [`PowerShell`](https://github.com/PowerShell/PowerShell). + - `Windows PowerShell` is really bad, there are always many small issues. + ## 4.2.5 (2024/8/10) - If prefix match (`menu_is_prefix_match`) is enabled in the completion menu, only the value of completion is extracted when there's a common prefix. @@ -10,7 +20,7 @@ ## 4.2.4 (2024/8/10) -- Fix an issue where Windows PowerShell module loading failed because a code file used LF line breaks. +- Fix an issue where `Windows PowerShell` module loading failed because a code file used LF line breaks. - For code files , replace LF line breaks to CRLF line breaks and replace UTF-8 to UTF-8-BOM encoding. - Fix an issue where initialization imports were missing in non-Windows environments. - Change the source file directory structure. diff --git a/module/PSCompletions.psd1 b/module/PSCompletions.psd1 index 15e2a30..b12d81c 100644 --- a/module/PSCompletions.psd1 +++ b/module/PSCompletions.psd1 @@ -10,7 +10,7 @@ RootModule = 'PSCompletions.psm1' - ModuleVersion = '4.2.5' + ModuleVersion = '4.2.6' GUID = '00929632-527d-4dab-a5b3-21197faccd05' diff --git a/module/PSCompletions.psm1 b/module/PSCompletions.psm1 index 5bdafc8..ebc2ddb 100644 --- a/module/PSCompletions.psm1 +++ b/module/PSCompletions.psm1 @@ -365,13 +365,13 @@ handle_done ($arg[2] -is [int] -and $arg[2] -in @(1, 0)) -common_err } 'github' { - handle_done ($arg[2] -match 'http[s]?://github.com/.*') + handle_done ($arg[2] -match 'http[s]?://github.com/.*' -or $arg[2] -eq '') } 'gitee' { - handle_done ($arg[2] -match 'http[s]?://gitee.com/.*') + handle_done ($arg[2] -match 'http[s]?://gitee.com/.*' -or $arg[2] -eq '') } 'url' { - handle_done ($arg[2] -match 'http[s]?://') + handle_done ($arg[2] -match 'http[s]?://' -or $arg[2] -eq '') } } } diff --git a/module/core/init.ps1 b/module/core/init.ps1 index 362ffd4..17a75b9 100644 --- a/module/core/init.ps1 +++ b/module/core/init.ps1 @@ -3,7 +3,7 @@ New-Variable -Name PSCompletions -Value @{} -Option Constant # 模块版本 -$PSCompletions.version = '4.2.5' +$PSCompletions.version = '4.2.6' $PSCompletions.path = @{} $PSCompletions.path.root = Split-Path $PSScriptRoot -Parent $PSCompletions.path.completions = Join-Path $PSCompletions.path.root 'completions' diff --git a/module/core/menu/win.ps1 b/module/core/menu/win.ps1 index 912f13d..087e0dd 100644 --- a/module/core/menu/win.ps1 +++ b/module/core/menu/win.ps1 @@ -1,4 +1,5 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod handle_list_first { + param($filter_list) $max_width = 0 if ($this.is_show_tip) { $tip_max_height = 0 @@ -84,7 +85,7 @@ } } - foreach ($arr in $PSCompletions.split_array($this.filter_list, [Environment]::ProcessorCount, $true)) { + foreach ($arr in $PSCompletions.split_array($filter_list, [Environment]::ProcessorCount, $true)) { $filterListTasks += [powershell]::Create().AddScript($scriptBlock).AddArgument($arr).AddArgument($PSCompletions).AddArgument($Host.UI) } @@ -94,10 +95,6 @@ @{ Runspace = $task; Job = $job } } - - $this.filter_list = [System.Collections.Generic.List[System.Object]]@() - $this.origin_filter_list = [System.Collections.Generic.List[System.Object]]@() - foreach ($rs in $runspaces) { $results = $rs.Runspace.EndInvoke($rs.Job) $rs.Runspace.Dispose() @@ -112,8 +109,8 @@ width = $width height = $result.ToolTip.Count } - $this.filter_list.Add($result) $this.origin_filter_list.Add($result) + $this.filter_list.Add($result) } } @@ -122,14 +119,16 @@ $this.tip_max_height = $tip_max_height } else { - $this.filter_list = foreach ($_ in $this.filter_list) { + foreach ($_ in $filter_list) { $width = $this.get_length($_.ListItemText) if ($width -gt $max_width) { $max_width = $width } - @{ + $result = @{ ListItemText = $_.ListItemText CompletionText = $_.CompletionText width = $width } + $this.origin_filter_list.Add($result) + $this.filter_list.Add($result) } } if ($max_width -lt $PSCompletions.config.menu_list_min_width) { @@ -287,7 +286,7 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod new_buffer X = 0 Y = $this.pos.Y } - if ($PSCompletions.menu.is_show_above) { $pos.Y -- } + if ($this.is_show_above) { $pos.Y -- } $buffer = $Host.UI.RawUI.NewBufferCellArray($box, $host.UI.RawUI.BackgroundColor, $host.UI.RawUI.BackgroundColor) $Host.UI.RawUI.SetBufferContents($pos, $buffer) } @@ -376,7 +375,7 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod new_status_ $this.old_status_pos = $old_top # 之前的位置 $current = "$(([string]($this.selected_index + 1)).PadLeft($this.filter_list.Count.ToString().Length, ' '))" - $buffer_status = $Host.UI.RawUI.NewBufferCellArray(@("$($current)$($PSCompletions.config.menu_status_symbol)$($PSCompletions.menu.filter_list.Count)"), $PSCompletions.config.menu_color_status_text, $PSCompletions.config.menu_color_status_back) + $buffer_status = $Host.UI.RawUI.NewBufferCellArray(@("$($current)$($PSCompletions.config.menu_status_symbol)$($this.filter_list.Count)"), $PSCompletions.config.menu_color_status_text, $PSCompletions.config.menu_color_status_back) $pos_status = $Host.UI.RawUI.CursorPosition $pos_status.X = $this.pos.X + 3 @@ -386,7 +385,7 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod new_status_ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod get_old_tip_buffer { param($X, $Y) if ($PSCompletions.config.menu_tip_cover_buffer) { - if ($PSCompletions.menu.is_show_above) { + if ($this.is_show_above) { $Y = 0 $to_Y = $this.pos.Y } @@ -396,7 +395,7 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod get_old_tip } } else { - if ($PSCompletions.menu.is_show_above) { + if ($this.is_show_above) { $Y = $this.pos_tip.Y - 1 $to_Y = $this.pos.Y } @@ -416,7 +415,7 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod new_tip_buf param($index) $box = @() if ($PSCompletions.config.menu_tip_cover_buffer) { - if ($PSCompletions.menu.is_show_above) { + if ($this.is_show_above) { foreach ($_ in 0..($this.pos.Y - 1)) { $box += (' ' * $Host.UI.RawUI.BufferSize.Width) } @@ -443,7 +442,7 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod new_tip_buf X = 0 Y = $this.pos_tip.Y - 1 } - if ($PSCompletions.menu.is_show_above -and $pos.Y -lt 0) { $pos.Y = 0 } + if ($this.is_show_above -and $pos.Y -lt 0) { $pos.Y = 0 } } $buffer = $Host.UI.RawUI.NewBufferCellArray($box, $host.UI.RawUI.BackgroundColor, $host.UI.RawUI.BackgroundColor) $Host.UI.RawUI.SetBufferContents($pos, $buffer) @@ -558,7 +557,7 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod filter_comp $this.filter_list = [System.Collections.Generic.List[System.Object]]@() foreach ($f in $filter_list) { - if ($f.ListItemText -and $f.ListItemText -like $match) { + if ($f.CompletionText -and $f.CompletionText -like $match) { $this.filter_list.Add($f) } } @@ -592,10 +591,10 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod reset { $this.offset = 0 $this.selected_index = 0 $this.page_current_index = 0 - + $this.tip_max_height = 0 if ($is_menu_enhance) { - $PSCompletions.menu.is_show_tip = $PSCompletions.config.menu_show_tip_when_enhance -eq 1 + $this.is_show_tip = $PSCompletions.config.menu_show_tip_when_enhance -eq 1 } else { if ($PSCompletions.current_cmd) { @@ -614,7 +613,6 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod reset { } Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod show_module_menu { param($filter_list, [bool]$is_menu_enhance) - $this.filter_list = $filter_list $lastest_encoding = [console]::OutputEncoding [console]::OutputEncoding = $PSCompletions.encoding @@ -635,11 +633,13 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod show_module $this.offset = 0 # 索引的偏移量,用于滚动翻页 - $this.filter_completions($this.filter_list) # 如果没有可用的选项,直接结束,触发路径补全 - if (!$this.filter_list) { return } + if (!$filter_list) { return } $this.reset($true, $is_menu_enhance) - $this.handle_list_first() + + $this.origin_filter_list = [System.Collections.Generic.List[System.Object]]@() + $this.filter_list = [System.Collections.Generic.List[System.Object]]@() + $this.handle_list_first($filter_list) if ($PSCompletions.config.enter_when_single -and $PSCompletions.is_single) { return $this.filter_list[$this.selected_index].CompletionText diff --git a/module/log.json b/module/log.json index b3b22d3..461aa30 100644 --- a/module/log.json +++ b/module/log.json @@ -1,4 +1,26 @@ { + "4.2.6": { + "zh-CN": [ + "修复(2024/8/10)\n", + " - 修复补全项列表为空的bug\n", + " - 如果使用 <@Magenta>Windows PowerShell<@Blue>,且使用了命令行主题(如: oh-my-posh),当补全菜单显示在上方时,可能会导致当前行附近的文字及图标错乱\n", + " - 解决方案:\n", + " 1. 禁用命令行主题\n", + " 2. 尽量让补全菜单显示在下方(只要当前行在窗口中部以上即可)\n", + " 3. 不要使用 <@Magenta>Windows PowerShell<@Blue>,直接使用 <@Magenta>PowerShell<@Blue>: https://github.com/PowerShell/PowerShell\n", + " - <@Magenta>Windows PowerShell<@Blue> 真的很差,小问题总是很多\n" + ], + "en-US": [ + "Fix(2024/8/10)\n", + " - Fix a bug where the list of completions list was empty.\n", + " - If using <@Magenta>Windows PowerShell<@Blue> and using a command-line theme (such as oh-my-posh), it may cause the current line and nearby text and icons to be distorted when the completion menu is displayed above the current line.\n", + " - Solution:\n", + " 1. Disable the command-line theme.\n", + " 2. Try to make the completion menu display below the current line. (Only if the current line is above the middle of the window.)\n", + " 3. Do not use <@Magenta>Windows PowerShell<@Blue>, use <@Magenta>PowerShell<@Blue>: https://github.com/PowerShell/PowerShell\n", + " - <@Magenta>Windows PowerShell<@Blue> is really bad, there are always many small issues.\n" + ] + }, "4.2.5": { "zh-CN": [ "修复(2024/8/10)\n", diff --git a/module/version.txt b/module/version.txt index df0228d..d6f85ab 100644 --- a/module/version.txt +++ b/module/version.txt @@ -1 +1 @@ -4.2.5 +4.2.6