Skip to content

Commit

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

## 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`),当有公共前缀时,只提取补全的值
- 优化补全更新的逻辑

## 4.2.4 (2024/8/10)

- 修复了因为一个代码文件使用了 LF 换行符导致 Windows PowerShell 模块加载错误的问题
- 修复了因为一个代码文件使用了 LF 换行符导致 `Windows PowerShell` 模块加载错误的问题
- 对于源代码文件,将 LF 换行符替换为 CRLF 换行符,UTF-8 编码替换为 UTF-8-BOM 编码
- 修复了非 Windows 环境的初始化导入缺失的问题
- 更改源代码文件目录结构
Expand Down
12 changes: 11 additions & 1 deletion module/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
<a href="./CHANGELOG.md">English</a>
</p>

## 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.
- 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.
- 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.
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.5'
ModuleVersion = '4.2.6'

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

Expand Down
6 changes: 3 additions & 3 deletions module/PSCompletions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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 '')
}
}
}
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.5'
$PSCompletions.version = '4.2.6'
$PSCompletions.path = @{}
$PSCompletions.path.root = Split-Path $PSScriptRoot -Parent
$PSCompletions.path.completions = Join-Path $PSCompletions.path.root 'completions'
Expand Down
42 changes: 21 additions & 21 deletions module/core/menu/win.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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()
Expand All @@ -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)
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions module/log.json
Original file line number Diff line number Diff line change
@@ -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",
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.5
4.2.6

0 comments on commit 662dc72

Please sign in to comment.