pi-ask-tool-extension 0.2.3 → 0.2.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ask-tool-extension",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Ask tool extension for pi with tabbed questioning and inline note editing",
5
5
  "repository": {
6
6
  "type": "git",
@@ -111,6 +111,12 @@ export async function askSingleQuestionWithInlineNote(
111
111
  noteEditor.setText(getRawNoteForOption(cursorOptionIndex));
112
112
  };
113
113
 
114
+ const openNoteEditorForCurrentOption = () => {
115
+ if (isNoteEditorOpen) return;
116
+ isNoteEditorOpen = true;
117
+ loadCurrentNoteIntoEditor();
118
+ };
119
+
114
120
  const saveCurrentNoteFromEditor = (value: string) => {
115
121
  noteByOptionIndex.set(cursorOptionIndex, value);
116
122
  };
@@ -206,31 +212,49 @@ export async function askSingleQuestionWithInlineNote(
206
212
  };
207
213
 
208
214
  const handleInput = (data: string) => {
215
+ if (matchesKey(data, Key.ctrl("c"))) {
216
+ done({ cancelled: true });
217
+ return;
218
+ }
219
+
209
220
  if (isNoteEditorOpen) {
210
221
  if (matchesKey(data, Key.tab) || matchesKey(data, Key.escape)) {
211
222
  isNoteEditorOpen = false;
212
223
  requestUiRerender();
213
224
  return;
214
225
  }
215
- noteEditor.handleInput(data);
216
- requestUiRerender();
217
- return;
226
+
227
+ if (
228
+ (matchesKey(data, Key.up) || matchesKey(data, Key.down)) &&
229
+ getTrimmedNoteForOption(cursorOptionIndex).length === 0
230
+ ) {
231
+ isNoteEditorOpen = false;
232
+ } else {
233
+ noteEditor.handleInput(data);
234
+ requestUiRerender();
235
+ return;
236
+ }
218
237
  }
219
238
 
220
239
  if (matchesKey(data, Key.up)) {
221
240
  cursorOptionIndex = Math.max(0, cursorOptionIndex - 1);
241
+ if (selectableOptionLabels[cursorOptionIndex] === OTHER_OPTION) {
242
+ openNoteEditorForCurrentOption();
243
+ }
222
244
  requestUiRerender();
223
245
  return;
224
246
  }
225
247
  if (matchesKey(data, Key.down)) {
226
248
  cursorOptionIndex = Math.min(selectableOptionLabels.length - 1, cursorOptionIndex + 1);
249
+ if (selectableOptionLabels[cursorOptionIndex] === OTHER_OPTION) {
250
+ openNoteEditorForCurrentOption();
251
+ }
227
252
  requestUiRerender();
228
253
  return;
229
254
  }
230
255
 
231
256
  if (matchesKey(data, Key.tab)) {
232
- isNoteEditorOpen = true;
233
- loadCurrentNoteIntoEditor();
257
+ openNoteEditorForCurrentOption();
234
258
  requestUiRerender();
235
259
  return;
236
260
  }
@@ -252,6 +276,14 @@ export async function askSingleQuestionWithInlineNote(
252
276
 
253
277
  if (matchesKey(data, Key.escape)) {
254
278
  done({ cancelled: true });
279
+ return;
280
+ }
281
+
282
+ if (selectableOptionLabels[cursorOptionIndex] === OTHER_OPTION) {
283
+ openNoteEditorForCurrentOption();
284
+ noteEditor.handleInput(data);
285
+ requestUiRerender();
286
+ return;
255
287
  }
256
288
  };
257
289
 
@@ -438,25 +438,55 @@ export async function askQuestionsWithTabs(
438
438
  };
439
439
 
440
440
  const handleInput = (data: string) => {
441
+ if (matchesKey(data, Key.ctrl("c"))) {
442
+ done(createTabsUiStateSnapshot(true, selectedOptionIndexesByQuestion, noteByQuestionByOption));
443
+ return;
444
+ }
445
+
441
446
  if (isNoteEditorOpen) {
442
447
  if (matchesKey(data, Key.tab) || matchesKey(data, Key.escape)) {
443
448
  isNoteEditorOpen = false;
444
449
  requestUiRerender();
445
450
  return;
446
451
  }
447
- noteEditor.handleInput(data);
448
- requestUiRerender();
449
- return;
452
+
453
+ const questionIndex = getActiveQuestionIndex();
454
+ const cursorOptionIndex = questionIndex == null ? 0 : cursorOptionIndexByQuestion[questionIndex];
455
+ const noteIsEmpty = questionIndex == null || getTrimmedQuestionNote(questionIndex, cursorOptionIndex).length === 0;
456
+ if (
457
+ noteIsEmpty &&
458
+ (matchesKey(data, Key.up) || matchesKey(data, Key.down) || matchesKey(data, Key.left) || matchesKey(data, Key.right))
459
+ ) {
460
+ isNoteEditorOpen = false;
461
+ } else {
462
+ noteEditor.handleInput(data);
463
+ requestUiRerender();
464
+ return;
465
+ }
450
466
  }
451
467
 
452
468
  if (matchesKey(data, Key.left)) {
453
469
  activeTabIndex = (activeTabIndex - 1 + preparedQuestions.length + 1) % (preparedQuestions.length + 1);
470
+ if (getActiveQuestionIndex() != null) {
471
+ const questionIndex = getActiveQuestionIndex() as number;
472
+ if (preparedQuestions[questionIndex].options[cursorOptionIndexByQuestion[questionIndex]] === OTHER_OPTION) {
473
+ openNoteEditorForActiveOption();
474
+ return;
475
+ }
476
+ }
454
477
  requestUiRerender();
455
478
  return;
456
479
  }
457
480
 
458
481
  if (matchesKey(data, Key.right)) {
459
482
  activeTabIndex = (activeTabIndex + 1) % (preparedQuestions.length + 1);
483
+ if (getActiveQuestionIndex() != null) {
484
+ const questionIndex = getActiveQuestionIndex() as number;
485
+ if (preparedQuestions[questionIndex].options[cursorOptionIndexByQuestion[questionIndex]] === OTHER_OPTION) {
486
+ openNoteEditorForActiveOption();
487
+ return;
488
+ }
489
+ }
460
490
  requestUiRerender();
461
491
  return;
462
492
  }
@@ -477,6 +507,10 @@ export async function askQuestionsWithTabs(
477
507
 
478
508
  if (matchesKey(data, Key.up)) {
479
509
  cursorOptionIndexByQuestion[questionIndex] = Math.max(0, cursorOptionIndexByQuestion[questionIndex] - 1);
510
+ if (preparedQuestion.options[cursorOptionIndexByQuestion[questionIndex]] === OTHER_OPTION) {
511
+ openNoteEditorForActiveOption();
512
+ return;
513
+ }
480
514
  requestUiRerender();
481
515
  return;
482
516
  }
@@ -486,6 +520,10 @@ export async function askQuestionsWithTabs(
486
520
  preparedQuestion.options.length - 1,
487
521
  cursorOptionIndexByQuestion[questionIndex] + 1,
488
522
  );
523
+ if (preparedQuestion.options[cursorOptionIndexByQuestion[questionIndex]] === OTHER_OPTION) {
524
+ openNoteEditorForActiveOption();
525
+ return;
526
+ }
489
527
  requestUiRerender();
490
528
  return;
491
529
  }
@@ -535,6 +573,14 @@ export async function askQuestionsWithTabs(
535
573
 
536
574
  if (matchesKey(data, Key.escape)) {
537
575
  done(createTabsUiStateSnapshot(true, selectedOptionIndexesByQuestion, noteByQuestionByOption));
576
+ return;
577
+ }
578
+
579
+ if (preparedQuestion.options[cursorOptionIndexByQuestion[questionIndex]] === OTHER_OPTION) {
580
+ openNoteEditorForActiveOption();
581
+ noteEditor.handleInput(data);
582
+ requestUiRerender();
583
+ return;
538
584
  }
539
585
  };
540
586