(lastKeypressWasTab, { 0: completions, 1: completeOn })
| 714 | } |
| 715 | |
| 716 | [kTabCompleter](lastKeypressWasTab, { 0: completions, 1: completeOn }) { |
| 717 | // Result and the text that was completed. |
| 718 | |
| 719 | if (!completions || completions.length === 0) { |
| 720 | return; |
| 721 | } |
| 722 | |
| 723 | // If there is a common prefix to all matches, then apply that portion. |
| 724 | const prefix = commonPrefix( |
| 725 | ArrayPrototypeFilter(completions, (e) => e !== ''), |
| 726 | ); |
| 727 | if (StringPrototypeStartsWith(prefix, completeOn) && |
| 728 | prefix.length > completeOn.length) { |
| 729 | this[kInsertString](StringPrototypeSlice(prefix, completeOn.length)); |
| 730 | return; |
| 731 | } else if (!StringPrototypeStartsWith(completeOn, prefix)) { |
| 732 | this[kSetLine](StringPrototypeSlice(this.line, |
| 733 | 0, |
| 734 | this.cursor - completeOn.length) + |
| 735 | prefix + |
| 736 | StringPrototypeSlice(this.line, |
| 737 | this.cursor, |
| 738 | this.line.length)); |
| 739 | this.cursor = this.cursor - completeOn.length + prefix.length; |
| 740 | this[kRefreshLine](); |
| 741 | return; |
| 742 | } |
| 743 | |
| 744 | if (!lastKeypressWasTab) { |
| 745 | return; |
| 746 | } |
| 747 | |
| 748 | this[kBeforeEdit](this.line, this.cursor); |
| 749 | |
| 750 | // Apply/show completions. |
| 751 | const completionsWidth = ArrayPrototypeMap(completions, (e) => |
| 752 | getStringWidth(e), |
| 753 | ); |
| 754 | const width = MathMaxApply(completionsWidth) + 2; // 2 space padding |
| 755 | let maxColumns = MathFloor(this.columns / width) || 1; |
| 756 | if (maxColumns === Infinity) { |
| 757 | maxColumns = 1; |
| 758 | } |
| 759 | let output = '\r\n'; |
| 760 | let lineIndex = 0; |
| 761 | let whitespace = 0; |
| 762 | for (let i = 0; i < completions.length; i++) { |
| 763 | const completion = completions[i]; |
| 764 | if (completion === '' || lineIndex === maxColumns) { |
| 765 | output += '\r\n'; |
| 766 | lineIndex = 0; |
| 767 | whitespace = 0; |
| 768 | } else { |
| 769 | output += StringPrototypeRepeat(' ', whitespace); |
| 770 | } |
| 771 | if (completion !== '') { |
| 772 | output += completion; |
| 773 | whitespace = width - completionsWidth[i]; |
nothing calls this directly
no test coverage detected