X-Git-Url: https://git.josue.xyz/?p=dotfiles%2F.git;a=blobdiff_plain;f=.config%2Fcoc%2Fextensions%2Fnode_modules%2Fcoc-prettier%2Fnode_modules%2Finquirer%2Flib%2Futils%2Fpaginator.js;h=c6e60359611ef067af6527fd5d61770c4108be9c;hp=e0932b579ef59e39113a979b183aae4dd8b10a11;hb=4d07c77cf4d78cab8639e13ddc3c22495e585b0b;hpb=b3950616b54221c40a7dab9099bda675007e5b6e diff --git a/.config/coc/extensions/node_modules/coc-prettier/node_modules/inquirer/lib/utils/paginator.js b/.config/coc/extensions/node_modules/coc-prettier/node_modules/inquirer/lib/utils/paginator.js index e0932b57..c6e60359 100644 --- a/.config/coc/extensions/node_modules/coc-prettier/node_modules/inquirer/lib/utils/paginator.js +++ b/.config/coc/extensions/node_modules/coc-prettier/node_modules/inquirer/lib/utils/paginator.js @@ -7,20 +7,19 @@ var _ = { var chalk = require('chalk'); /** - * The paginator keeps track of a pointer index in a list and returns - * a subset of the choices if the list is too long. + * The paginator returns a subset of the choices if the list is too long. */ class Paginator { - constructor(screen) { - this.pointer = 0; + constructor(screen, options = {}) { + const { isInfinite = true } = options; this.lastIndex = 0; this.screen = screen; + this.isInfinite = isInfinite; } paginate(output, active, pageSize) { pageSize = pageSize || 7; - var middleOfList = Math.floor(pageSize / 2); var lines = output.split('\n'); if (this.screen) { @@ -33,7 +32,22 @@ class Paginator { if (lines.length <= pageSize) { return output; } + const visibleLines = this.isInfinite + ? this.getInfiniteLines(lines, active, pageSize) + : this.getFiniteLines(lines, active, pageSize); + this.lastIndex = active; + return ( + visibleLines.join('\n') + + '\n' + + chalk.dim('(Move up and down to reveal more choices)') + ); + } + getInfiniteLines(lines, active, pageSize) { + if (this.pointer === undefined) { + this.pointer = 0; + } + var middleOfList = Math.floor(pageSize / 2); // Move the pointer only when the user go down and limit it to the middle of the list if ( this.pointer < middleOfList && @@ -43,14 +57,21 @@ class Paginator { this.pointer = Math.min(middleOfList, this.pointer + active - this.lastIndex); } - this.lastIndex = active; - // Duplicate the lines so it give an infinite list look var infinite = _.flatten([lines, lines, lines]); var topIndex = Math.max(0, active + lines.length - this.pointer); - var section = infinite.splice(topIndex, pageSize).join('\n'); - return section + '\n' + chalk.dim('(Move up and down to reveal more choices)'); + return infinite.splice(topIndex, pageSize); + } + + getFiniteLines(lines, active, pageSize) { + var topIndex = active - pageSize / 2; + if (topIndex < 0) { + topIndex = 0; + } else if (topIndex + pageSize > lines.length) { + topIndex = lines.length - pageSize; + } + return lines.splice(topIndex, pageSize); } }