@inquirer/select 4.2.4 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -89,7 +89,15 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
89
89
  }
90
90
  }
91
91
  else if ((0, core_1.isNumberKey)(key) && !Number.isNaN(Number(rl.line))) {
92
- const position = Number(rl.line) - 1;
92
+ const selectedIndex = Number(rl.line) - 1;
93
+ // Find the nth item (ignoring separators)
94
+ let selectableIndex = -1;
95
+ const position = items.findIndex((item) => {
96
+ if (core_1.Separator.isSeparator(item))
97
+ return false;
98
+ selectableIndex++;
99
+ return selectableIndex === selectedIndex;
100
+ });
93
101
  const item = items[position];
94
102
  if (item != null && isSelectable(item)) {
95
103
  setActive(position);
@@ -133,14 +141,16 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
133
141
  helpTipTop = theme.style.help(`(${config.instructions?.navigation ?? 'Use arrow keys'})`);
134
142
  }
135
143
  }
144
+ let separatorCount = 0;
136
145
  const page = (0, core_1.usePagination)({
137
146
  items,
138
147
  active,
139
148
  renderItem({ item, isActive, index }) {
140
149
  if (core_1.Separator.isSeparator(item)) {
150
+ separatorCount++;
141
151
  return ` ${item.separator}`;
142
152
  }
143
- const indexLabel = theme.indexMode === 'number' ? `${index + 1}. ` : '';
153
+ const indexLabel = theme.indexMode === 'number' ? `${index + 1 - separatorCount}. ` : '';
144
154
  if (item.disabled) {
145
155
  const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
146
156
  return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
package/dist/esm/index.js CHANGED
@@ -83,7 +83,15 @@ export default createPrompt((config, done) => {
83
83
  }
84
84
  }
85
85
  else if (isNumberKey(key) && !Number.isNaN(Number(rl.line))) {
86
- const position = Number(rl.line) - 1;
86
+ const selectedIndex = Number(rl.line) - 1;
87
+ // Find the nth item (ignoring separators)
88
+ let selectableIndex = -1;
89
+ const position = items.findIndex((item) => {
90
+ if (Separator.isSeparator(item))
91
+ return false;
92
+ selectableIndex++;
93
+ return selectableIndex === selectedIndex;
94
+ });
87
95
  const item = items[position];
88
96
  if (item != null && isSelectable(item)) {
89
97
  setActive(position);
@@ -127,14 +135,16 @@ export default createPrompt((config, done) => {
127
135
  helpTipTop = theme.style.help(`(${config.instructions?.navigation ?? 'Use arrow keys'})`);
128
136
  }
129
137
  }
138
+ let separatorCount = 0;
130
139
  const page = usePagination({
131
140
  items,
132
141
  active,
133
142
  renderItem({ item, isActive, index }) {
134
143
  if (Separator.isSeparator(item)) {
144
+ separatorCount++;
135
145
  return ` ${item.separator}`;
136
146
  }
137
- const indexLabel = theme.indexMode === 'number' ? `${index + 1}. ` : '';
147
+ const indexLabel = theme.indexMode === 'number' ? `${index + 1 - separatorCount}. ` : '';
138
148
  if (item.disabled) {
139
149
  const disabledLabel = typeof item.disabled === 'string' ? item.disabled : '(disabled)';
140
150
  return theme.style.disabled(`${indexLabel}${item.name} ${disabledLabel}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/select",
3
- "version": "4.2.4",
3
+ "version": "4.3.1",
4
4
  "description": "Inquirer select/list prompt",
5
5
  "keywords": [
6
6
  "answer",
@@ -74,15 +74,15 @@
74
74
  "tsc": "tshy"
75
75
  },
76
76
  "dependencies": {
77
- "@inquirer/core": "^10.1.14",
78
- "@inquirer/figures": "^1.0.12",
79
- "@inquirer/type": "^3.0.7",
77
+ "@inquirer/core": "^10.1.15",
78
+ "@inquirer/figures": "^1.0.13",
79
+ "@inquirer/type": "^3.0.8",
80
80
  "ansi-escapes": "^4.3.2",
81
81
  "yoctocolors-cjs": "^2.1.2"
82
82
  },
83
83
  "devDependencies": {
84
- "@arethetypeswrong/cli": "^0.18.1",
85
- "@inquirer/testing": "^2.1.48",
84
+ "@arethetypeswrong/cli": "^0.18.2",
85
+ "@inquirer/testing": "^2.1.49",
86
86
  "tshy": "^3.0.2"
87
87
  },
88
88
  "engines": {
@@ -108,5 +108,5 @@
108
108
  "optional": true
109
109
  }
110
110
  },
111
- "gitHead": "43b7bb94390c1e2b6473af1b790ff2fd1c8007c8"
111
+ "gitHead": "5fbae895f0da93446b99ed0b03ccaa6dfb12cf00"
112
112
  }