Skip to content

Commit f31538e

Browse files
msftrncsdaxian-dbw
authored andcommitted
Utilize LengthInBufferCells when creating Completions Menu (#1214)
* Use LenthInBufferCells for Completions * Remove unused ShortenLongCompletions Use LengthInBufferCells() for determining the display width of menu items in CreateCompletionMenu() to correct support of CJK characters in completion items.
1 parent 1c41239 commit f31538e

File tree

1 file changed

+1
-16
lines changed

1 file changed

+1
-16
lines changed

PSReadLine/Completion.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -428,21 +428,6 @@ private static string HandleNewlinesForPossibleCompletions(string s)
428428
return s;
429429
}
430430

431-
private static string ShortenLongCompletions(string s, int maxLength)
432-
{
433-
if (s.Length <= maxLength) return s;
434-
// position of split point where ... inserted
435-
int splitPos = 10;
436-
// TODO: will crash for console width < splitPos + 3
437-
438-
// TODO: is it needed ?
439-
// insert '.'
440-
//if (s.Length - maxLength <= 2)
441-
// return s.Substring(0, maxLength - splitPos - 1) + '.' + s.Substring(s.Length - splitPos, splitPos);
442-
// insert '...'
443-
return s.Substring(0, maxLength - splitPos - 3) + "..." + s.Substring(s.Length - splitPos, splitPos);
444-
}
445-
446431
private class Menu
447432
{
448433
internal PSConsoleReadLine Singleton;
@@ -697,7 +682,7 @@ public void SaveCursor()
697682
private Menu CreateCompletionMenu(Collection<CompletionResult> matches)
698683
{
699684
var bufferWidth = _console.BufferWidth;
700-
var colWidth = Math.Min(matches.Max(c => c.ListItemText.Length) + 2, bufferWidth);
685+
var colWidth = Math.Min(matches.Max(c => LengthInBufferCells(c.ListItemText)) + 2, bufferWidth);
701686
var columns = Math.Max(1, bufferWidth / colWidth);
702687

703688
return new Menu

0 commit comments

Comments
 (0)