| 
5 | 5 |   isBackspaceKey,  | 
6 | 6 |   isDownKey,  | 
7 | 7 |   isEnterKey,  | 
 | 8 | +  isSpaceKey,  | 
8 | 9 |   isUpKey,  | 
9 | 10 |   makeTheme,  | 
10 | 11 |   useKeypress,  | 
@@ -55,6 +56,7 @@ const fileSelectorTheme: FileSelectorTheme = {  | 
55 | 56 | 
 
  | 
56 | 57 | export default createPrompt<string, FileSelectorConfig>((config, done) => {  | 
57 | 58 |   const {  | 
 | 59 | +    type = 'file',  | 
58 | 60 |     pageSize = 10,  | 
59 | 61 |     loop = false,  | 
60 | 62 |     showExcluded = false,  | 
@@ -101,13 +103,19 @@ export default createPrompt<string, FileSelectorConfig>((config, done) => {  | 
101 | 103 | 
 
  | 
102 | 104 |   useKeypress((key, rl) => {  | 
103 | 105 |     if (isEnterKey(key)) {  | 
104 |  | -      if (activeItem.isDirectory()) {  | 
105 |  | -        setCurrentDir(activeItem.path)  | 
106 |  | -        setActive(bounds.first)  | 
107 |  | -      } else if (!activeItem.isDisabled) {  | 
108 |  | -        setStatus('done')  | 
109 |  | -        done(activeItem.path)  | 
 | 106 | +      if (  | 
 | 107 | +        activeItem.isDisabled ||  | 
 | 108 | +        (type === 'file' && activeItem.isDirectory()) ||  | 
 | 109 | +        (type === 'directory' && !activeItem.isDirectory())  | 
 | 110 | +      ) {  | 
 | 111 | +        return  | 
110 | 112 |       }  | 
 | 113 | + | 
 | 114 | +      setStatus('done')  | 
 | 115 | +      done(activeItem.path)  | 
 | 116 | +    } else if (isSpaceKey(key) && activeItem.isDirectory()) {  | 
 | 117 | +      setCurrentDir(activeItem.path)  | 
 | 118 | +      setActive(bounds.first)  | 
111 | 119 |     } else if (isUpKey(key) || isDownKey(key)) {  | 
112 | 120 |       rl.clearLine(0)  | 
113 | 121 | 
 
  | 
@@ -173,8 +181,8 @@ export default createPrompt<string, FileSelectorConfig>((config, done) => {  | 
173 | 181 |   const header = theme.style.currentDir(ensureTrailingSlash(currentDir))  | 
174 | 182 |   const helpTip = useMemo(() => {  | 
175 | 183 |     const helpTipLines = [  | 
176 |  | -      `${theme.style.key(figures.arrowUp + figures.arrowDown)} navigate, ${theme.style.key('<enter>')} select or open directory`,  | 
177 |  | -      `${theme.style.key('<backspace>')} go back${allowCancel ? `, ${theme.style.key('<esc>')} cancel` : ''}`  | 
 | 184 | +      `${theme.style.key(figures.arrowUp + figures.arrowDown)} navigate, ${theme.style.key('<enter>')} select${allowCancel ? `, ${theme.style.key('<esc>')} cancel` : ''}`,  | 
 | 185 | +      `${theme.style.key('<space>')} open directory, ${theme.style.key('<backspace>')} go back`  | 
178 | 186 |     ]  | 
179 | 187 | 
 
  | 
180 | 188 |     const helpTipMaxLength = getMaxLength(helpTipLines)  | 
 | 
0 commit comments