Skip to content

Commit

Permalink
fix(module): update version to 4.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
abgox committed Aug 10, 2024
1 parent 31c1731 commit 3f43f9f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 36 deletions.
7 changes: 6 additions & 1 deletion module/CHANGELOG-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
<a href="./CHANGELOG-CN.md">简体中文</a>
</p>

## 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 编码
Expand Down
7 changes: 6 additions & 1 deletion module/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
<a href="./CHANGELOG.md">English</a>
</p>

## 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.
Expand Down
2 changes: 1 addition & 1 deletion module/PSCompletions.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

RootModule = 'PSCompletions.psm1'

ModuleVersion = '4.2.4'
ModuleVersion = '4.2.5'

GUID = '00929632-527d-4dab-a5b3-21197faccd05'

Expand Down
49 changes: 21 additions & 28 deletions module/PSCompletions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion module/core/init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions module/core/menu/win.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion module/log.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion module/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.4
4.2.5

0 comments on commit 3f43f9f

Please sign in to comment.