diff --git a/bin/cli.js b/bin/cli.js index c7fc078..a467b91 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -67,7 +67,7 @@ function run () keepRight: !!argv['keep-right'], } - + opts._selectOneActive = false const api = nfzf( opts, function ( result ) { if ( result.selected ) { console.log( result.selected.value ) @@ -114,6 +114,7 @@ function run () list.push( line ) } ) + api._selectOneActive = true api.update( list ) } ) diff --git a/src/main.js b/src/main.js index 3060d5d..221dd71 100644 --- a/src/main.js +++ b/src/main.js @@ -799,9 +799,6 @@ function queryUser ( opts, callback ) function render () { - render._count = render._count || 0 - render._count++ - const width = stdout.columns || clc.windowSize.width const height = stdout.rows || clc.windowSize.height // console.log( 'window height: ' + height ) @@ -852,6 +849,8 @@ function queryUser ( opts, callback ) // get rid of dirt when being pushed above MIN_HEIGHT // from the bottom of the terminal cleanDirtyScreen() + + if (_opts._selectOneActive === undefined) _opts._selectOneActive = true } render.init = true @@ -984,7 +983,7 @@ function queryUser ( opts, callback ) _selectedItem = _matches[ 0 ] } - if (render._count === 1 && _matches.length === 1 && _opts.selectOne ) { + if (_opts._selectOneActive && _matches.length === 1 && _opts.selectOne ) { // console.log(' === attempting to select one === ') _selectedItem = _matches[ 0 ] cleanDirtyScreen() @@ -992,6 +991,7 @@ function queryUser ( opts, callback ) handleKeypress( '', { name: 'return' } ) }) } + _opts._selectOneActive = false // print the matches _printedMatches = 0