diff --git a/module/CHANGELOG-CN.md b/module/CHANGELOG-CN.md index 35ee551..81b3109 100644 --- a/module/CHANGELOG-CN.md +++ b/module/CHANGELOG-CN.md @@ -3,7 +3,12 @@ 简体中文

-## 4.2.4 (2024/8/9) +## 4.2.5 (2024/8/10) + +- 如果菜单启用了前缀匹配(`menu_is_prefix_match`),当有公共前缀时,只提取补全的值 +- 优化补全更新的逻辑 + +## 4.2.4 (2024/8/10) - 修复了因为一个代码文件使用了 LF 换行符导致 Windows PowerShell 模块加载错误的问题 - 对于源代码文件,将 LF 换行符替换为 CRLF 换行符,UTF-8 编码替换为 UTF-8-BOM 编码 diff --git a/module/CHANGELOG.md b/module/CHANGELOG.md index 89e798a..c49e8e9 100644 --- a/module/CHANGELOG.md +++ b/module/CHANGELOG.md @@ -3,7 +3,12 @@ English

-## 4.2.4 (2024/8/9) +## 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. +- Optimize the logic of completion update. + +## 4.2.4 (2024/8/10) - 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. diff --git a/module/PSCompletions.psd1 b/module/PSCompletions.psd1 index 39e0111..15e2a30 100644 --- a/module/PSCompletions.psd1 +++ b/module/PSCompletions.psd1 @@ -10,7 +10,7 @@ RootModule = 'PSCompletions.psm1' - ModuleVersion = '4.2.4' + ModuleVersion = '4.2.5' GUID = '00929632-527d-4dab-a5b3-21197faccd05' diff --git a/module/PSCompletions.psm1 b/module/PSCompletions.psm1 index 1d9253b..5bdafc8 100644 --- a/module/PSCompletions.psm1 +++ b/module/PSCompletions.psm1 @@ -134,57 +134,50 @@ function _update { $completion_list = $PSCompletions.cmd.keys | Where-Object { $_ -in $PSCompletions.list } - # 检查补全列表更新,并将最新结果保存到 update 文件中,以及 $PSCompletions.update 变量中 - function check_update { - $update_list = [System.Collections.Generic.List[string]]@() - + if ($arg.Length -lt 2) { + # 如果只是使用 psc update 则检查更新 + $need_update_list = [System.Collections.Generic.List[string]]@() foreach ($completion in $completion_list) { try { - $url = "$($PSCompletions.url)/completions/$($completion)/guid.txt" - $response = Invoke-WebRequest -Uri $url - } - catch { - $path_guid = $PSCompletions.Join_path($PSCompletions.path.completions, $completion, 'guid.txt') - $PSCompletions.download_file("$($PSCompletions.url)/completions/$($completion)/guid.txt", $path_guid) - return + $response = Invoke-WebRequest -Uri "$($PSCompletions.url)/completions/$($completion)/guid.txt" + $content = $response.Content.Trim() + $guid = $PSCompletions.get_raw_content("$($PSCompletions.path.completions)/$($completion)/guid.txt") + if ($guid -ne $content) { $need_update_list.Add($completion) } } - $content = $response.Content.Trim() - $guid = $PSCompletions.get_raw_content("$($PSCompletions.path.completions)/$($completion)/guid.txt") - if ($guid -ne $content) { $update_list.Add($completion) } - } - $PSCompletions.update = $update_list - if ($update_list) { - $PSCompletions.write_with_color((_replace $PSCompletions.info.update_has)) - $update_list | Out-File $PSCompletions.path.update -Force -Encoding utf8 - } - else { - Clear-Content $PSCompletions.path.update -Force - $PSCompletions.write_with_color((_replace $PSCompletions.info.update_no)) + catch { } } - } - - if ($arg.Length -lt 2) { - # 如果只是 update 没有指定更新什么补全,则检查更新 - check_update + $PSCompletions.update = $need_update_list } else { + $updated_list = [System.Collections.Generic.List[string]]@() if ($arg[1] -eq '*') { # 更新全部可以更新的补全 foreach ($_ in $PSCompletions.update) { $PSCompletions.add_completion($_, $true) + $updated_list.Add($_) } } else { foreach ($completion in $arg[1..($arg.Length - 1)]) { if ($completion -in $completion_list) { $PSCompletions.add_completion($completion, $true) + $updated_list.Add($completion) } else { $PSCompletions.write_with_color((_replace $PSCompletions.info.no_completion)) } } } + $PSCompletions.update = $PSCompletions.get_content($PSCompletions.path.update) | Where-Object { $_ -notin $updated_list } + } + + if ($PSCompletions.update) { + $PSCompletions.write_with_color((_replace $PSCompletions.info.update_has)) + } + else { + $PSCompletions.write_with_color((_replace $PSCompletions.info.update_no)) } + $PSCompletions.update | Out-File $PSCompletions.path.update -Force -Encoding utf8 } function _search { if ($arg.Length -lt 2) { diff --git a/module/core/init.ps1 b/module/core/init.ps1 index b965439..362ffd4 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.4' +$PSCompletions.version = '4.2.5' $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 3756c11..912f13d 100644 --- a/module/core/menu/win.ps1 +++ b/module/core/menu/win.ps1 @@ -535,9 +535,9 @@ Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod move_select } } Add-Member -InputObject $PSCompletions.menu -MemberType ScriptMethod get_prefix { - $prefix = $this.filter_list[-1].ListItemText + $prefix = $this.filter_list[-1].CompletionText for ($i = $this.filter_list.count - 2; $i -ge 0 -and $prefix; --$i) { - $text = $this.filter_list[$i].ListItemText + $text = $this.filter_list[$i].CompletionText if ($text) { while ($prefix -and !$text.StartsWith($prefix, [StringComparison]::OrdinalIgnoreCase)) { $prefix = $prefix.Substring(0, $prefix.Length - 1) diff --git a/module/log.json b/module/log.json index c5f8504..b3b22d3 100644 --- a/module/log.json +++ b/module/log.json @@ -1,11 +1,23 @@ { + "4.2.5": { + "zh-CN": [ + "修复(2024/8/10)\n", + " - 如果菜单启用了前缀匹配(<@Magenta>menu_is_prefix_match<@Blue>),当有公共前缀时,只提取补全的值\n", + " - 优化补全更新的逻辑\n" + ], + "en-US": [ + "Fix(2024/8/10)\n", + " - If prefix match (<@Magenta>menu_is_prefix_match<@Blue>) is enabled in the completion menu, only the value of completion is extracted when there's a common prefix.\n", + " - Optimize the logic of completion update.\n" + ] + }, "4.2.4": { "zh-CN": [ "修复(2024/8/10)\n", " - 修复了因为一个代码文件使用了 LF 换行符导致 Windows PowerShell 模块加载错误的问题\n", " - 对于源代码文件,将 LF 换行符替换为 CRLF 换行符,UTF-8 编码替换为 UTF-8-BOM 编码\n", " - 修复了非 Windows 环境的初始化导入缺失的问题\n", - " - 调整源代码文件目录结构\n" + " - 更改源代码文件目录结构\n" ], "en-US": [ "Fix(2024/8/10)\n", diff --git a/module/version.txt b/module/version.txt index cf78d5b..df0228d 100644 --- a/module/version.txt +++ b/module/version.txt @@ -1 +1 @@ -4.2.4 +4.2.5