pi-ask-tool-extension 0.2.4 → 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.4",
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
  };
@@ -217,25 +223,38 @@ export async function askSingleQuestionWithInlineNote(
217
223
  requestUiRerender();
218
224
  return;
219
225
  }
220
- noteEditor.handleInput(data);
221
- requestUiRerender();
222
- 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
+ }
223
237
  }
224
238
 
225
239
  if (matchesKey(data, Key.up)) {
226
240
  cursorOptionIndex = Math.max(0, cursorOptionIndex - 1);
241
+ if (selectableOptionLabels[cursorOptionIndex] === OTHER_OPTION) {
242
+ openNoteEditorForCurrentOption();
243
+ }
227
244
  requestUiRerender();
228
245
  return;
229
246
  }
230
247
  if (matchesKey(data, Key.down)) {
231
248
  cursorOptionIndex = Math.min(selectableOptionLabels.length - 1, cursorOptionIndex + 1);
249
+ if (selectableOptionLabels[cursorOptionIndex] === OTHER_OPTION) {
250
+ openNoteEditorForCurrentOption();
251
+ }
232
252
  requestUiRerender();
233
253
  return;
234
254
  }
235
255
 
236
256
  if (matchesKey(data, Key.tab)) {
237
- isNoteEditorOpen = true;
238
- loadCurrentNoteIntoEditor();
257
+ openNoteEditorForCurrentOption();
239
258
  requestUiRerender();
240
259
  return;
241
260
  }
@@ -257,6 +276,14 @@ export async function askSingleQuestionWithInlineNote(
257
276
 
258
277
  if (matchesKey(data, Key.escape)) {
259
278
  done({ cancelled: true });
279
+ return;
280
+ }
281
+
282
+ if (selectableOptionLabels[cursorOptionIndex] === OTHER_OPTION) {
283
+ openNoteEditorForCurrentOption();
284
+ noteEditor.handleInput(data);
285
+ requestUiRerender();
286
+ return;
260
287
  }
261
288
  };
262
289
 
@@ -449,19 +449,44 @@ export async function askQuestionsWithTabs(
449
449
  requestUiRerender();
450
450
  return;
451
451
  }
452
- noteEditor.handleInput(data);
453
- requestUiRerender();
454
- 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
+ }
455
466
  }
456
467
 
457
468
  if (matchesKey(data, Key.left)) {
458
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
+ }
459
477
  requestUiRerender();
460
478
  return;
461
479
  }
462
480
 
463
481
  if (matchesKey(data, Key.right)) {
464
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
+ }
465
490
  requestUiRerender();
466
491
  return;
467
492
  }
@@ -482,6 +507,10 @@ export async function askQuestionsWithTabs(
482
507
 
483
508
  if (matchesKey(data, Key.up)) {
484
509
  cursorOptionIndexByQuestion[questionIndex] = Math.max(0, cursorOptionIndexByQuestion[questionIndex] - 1);
510
+ if (preparedQuestion.options[cursorOptionIndexByQuestion[questionIndex]] === OTHER_OPTION) {
511
+ openNoteEditorForActiveOption();
512
+ return;
513
+ }
485
514
  requestUiRerender();
486
515
  return;
487
516
  }
@@ -491,6 +520,10 @@ export async function askQuestionsWithTabs(
491
520
  preparedQuestion.options.length - 1,
492
521
  cursorOptionIndexByQuestion[questionIndex] + 1,
493
522
  );
523
+ if (preparedQuestion.options[cursorOptionIndexByQuestion[questionIndex]] === OTHER_OPTION) {
524
+ openNoteEditorForActiveOption();
525
+ return;
526
+ }
494
527
  requestUiRerender();
495
528
  return;
496
529
  }
@@ -540,6 +573,14 @@ export async function askQuestionsWithTabs(
540
573
 
541
574
  if (matchesKey(data, Key.escape)) {
542
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;
543
584
  }
544
585
  };
545
586