Skip to content

Let Save and delete act on an open answer or distractor chip - #6357

Merged
AlexVelezLl merged 2 commits into
learningequality:unstablefrom
rtibblesbot:issue-6331-5bef83
Nov 19, 2026
Merged

AlexVelezLl merged 2 commits into
learningequality:unstablefrom
rtibblesbot:issue-6331-5bef83

Conversation

@rtibblesbot

@rtibblesbot rtibblesbot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • QTI editor: Save and delete beside an open chip now act on it.
  • provideEditorBoundary marks controls whose clicks sync the editor without closing it.

References

Fixes #6331.

Reviewer guidance

Suggested review: Light-touch code review, then manual QA.

Engineer review

  • A pointer click pressed while a ClickableRegion was suppressed no longer activates it, in every QTI region (ClickableRegion/index.vue:51).
  • A draft's discard (×) button throws the written text away, where unstable added it (EditableChipList/index.vue:399).

QA review

  • In Chromium, on an existing Match answer chip and an existing distractor chip, click Save and press Enter on it: each closes the chip, keeps the edit, focuses the chip, and logs no TypeError.
  • In Match, Associate and Gap match, write a distractor draft, then click the card's Close or another question's card: the draft is still there after reopening and reloading.
  • Clicking the blank space beside an open chip's Save, or the empty answer box, closes the chip without opening a new draft.
  • With an edited or blank chip open, clicking another chip, its error icon, or another chip's delete keeps the edit and acts on the clicked chip.
  • In a Choice question and in Hints, clicking an open option's or hint's padding outside its editor closes it without reopening it.
Manual QA steps

QA team: SAVE and ✕ beside an open answer now act on it. Regressions are most probable for clicks inside answer boxes.

Open /en/channels/<channel id>/#/qti-demo and click Edit on a question.

  1. Save: on the Match question, row "Bat", change "Can fly" to Mammal. Press Enter on SAVE. The answer closes. One error shows.
  2. Delete: on the Associate question, click Edit distractor 2 and type Kenya. Click Delete distractor 2. Nothing reopens.
  3. Empty space: open a Match answer and click empty space in the box. It closes, and no answer opens.

Look out for:

  • Click a closed answer just after another closes. Look out for an answer that needs a second click.

Screen reader announcements were verified in English and Arabic.

Captures (5)

Save in a chip

chip-save-discard-delete.webm
s3-gapmatch-save-emptyclick-close.webm

Clicks inside the answer box

s2-empty-space-and-chip-switch.webm

Switch between editors

s4-mc-answers-hints-ordering-outside.webm

Menus in an open editor

s5-match-menu-outside-clicks.webm

AI usage

Claude Code traced the cause and wrote the fix and tests; verified with Jest and pre-commit.


Written by rtibblesbot, an LLM-based coding agent.

@rtibblesbot

🟡 Waiting for feedback

WAITING · on a reviewer
Last updated: 2026-11-18 14:53 UTC

@rtibblesbot
rtibblesbot marked this pull request as ready for review October 29, 2026 18:16
@rtibblesbot
rtibblesbot requested review from a team and leq-bot October 29, 2026 18:16
@AlexVelezLl AlexVelezLl self-assigned this Nov 16, 2026

@AlexVelezLl AlexVelezLl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the data-editor-boundary strategy is the best approach here; let's try to solve this without expanding the TipTapEditor API for such minor cases.

I reviewed the additions and then brainstormed a better solution with Claude; Claude then wrote the comments.

await user.keyboard('!');
}

describe('EditableChipList save', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file covers more than Save: delete, discard, gap clicks and menu dismissal. What sets it apart from EditableChipList.spec.js is that it runs the real TipTapEditor. Could you please name the file and the describe for that, for example EditableChipListWithEditor.spec.js, and add a line saying why it's separate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to EditableChipListWithEditor.spec.js, describe('EditableChipList with the real TipTapEditor'), with a line noting EditableChipList.spec.js mocks the editor. It's the only spec this branch adds.


Written by rtibblesbot, an LLM-based coding agent.

return;
}
hasHeldSync = false;
if (editorBoundary(root).contains(event.target)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug comes from this listener closing the editor before the click's own handlers run, so Save finds the chip already closed. Let's keep detecting the outside click here, but close only once the click has finished, and only if its own handler didn't already close the editor:

if (!isOutside) {
  flushHeldSync();
  return;
}
// Sync now, so the click's own handlers read the latest content, and close once they
// have run: a handler that closed the editor itself, such as Save, leaves nothing to do.
hasHeldSync = false;
syncContent();
setTimeout(() => {
  if (isListening && isEditing()) close();
});

This fixes Save, Discard and delete without consumers knowing anything, so data-editor-boundary, isPopupDismissal, the click passed to minimize and onListClick/closingClick can all go. Stopped clicks still close, because detection stays in the capture phase. Open popups and held blur syncs work as before. Clicking an empty spot in the box, including next to an open chip's Save, closes it without opening a draft.

With only this change, and EditableChipList and TipTapEditor.vue left as on unstable, every test in EditableChipListSave.spec.js and the other QTI editor suites pass. Real mouse clicks in Chromium behave as the QA steps describe. The useClickOutside and TipTapEditor specs need updating for the new timing.

Could you please also note in docs/rich_text_editor.md the one rule this adds? A click handler that takes the editor out of edit mode itself, such as opening another chip, gets no minimize for that click, so it does its own close work. The current consumers already do this: openChip commits and setOpenTarget calls closeOpenTarget.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop the delayed close. As the self-review found, a question's Close unmounts the chip list before the delayed close runs, so an unsaved draft is lost. Let's fix it here, in this PR, with these decisions:

  1. Keep closing first in the capture phase. Every click outside an editor and its controls commits the editor before anything else happens, so Close, Edit on another question and Response type keep the draft.
  2. Replace data-editor-boundary with a boundary provided to the editor. A new TipTapEditor/composables/useEditorBoundary.js exports provideEditorBoundary(isInside). TipTapEditor injects it and passes it to useClickOutside. A click outside the editor but inside the boundary syncs the content and leaves the editor open, and anything else closes it as on unstable. The import ties the boundary to the editor, and one call covers every editor in a list.
  3. EditableChipList provides one boundary for the whole list. It covers a closed chip, and the buttons beside the open editor: Save, delete and the draft's discard. A click on another chip or another chip's delete is then handled by openChip and onRemove, which already commit the open chip and shift the index past a dropped blank one. Blank space, in the list or beside the open chip's Save, stays outside, so useClickOutside closes the editor there, and a click there while a menu is open only closes the menu. That removes onListClick, isPopupDismissal, the click passed to minimize and closingClick.
  4. Keep "a click on the empty box only closes". Move it into ClickableRegion: a pointer click that was pressed while the region was suppressed doesn't count. Keyboard clicks have no press, so they're unaffected.
  5. Rewrite the "Controls beside the editor" section in docs/rich_text_editor.md for provideEditorBoundary.

Could you please also add a test where a click that unmounts the list, standing in for the question's Close, keeps a written draft, with Vue rendering between listeners? That's the case that went unnoticed here. A click on the blank space beside an open chip's Save should go in the targets that close the chip.

Key changes
// TipTapEditor/composables/useEditorBoundary.js
const EditorBoundarySymbol = Symbol('tipTapEditorBoundary');

export function provideEditorBoundary(isInside) {
  provide(EditorBoundarySymbol, isInside);
}

export function injectEditorBoundary() {
  return inject(EditorBoundarySymbol, null);
}
// useClickOutside.js, handleClick
const isOutside = isEditing() && root && !root.contains(event.target) && !hasOpenPopup(root);
if (!isOutside) {
  flushHeldSync();
  return;
}
hasHeldSync = false;
if (isInsideBoundary?.(event.target)) {
  // A control beside the editor, such as Save: it reads the content as it stands now,
  // and closes the editor itself if it should.
  syncContent();
} else {
  // `close` syncs the content itself.
  close();
}
// EditableChipList setup
provideEditorBoundary(target => {
  const button = target.closest('button');
  const region = chipRegions.value.find(({ $el }) => $el.contains(target));
  if (region) return !region.$props.suppressed || region.$el.contains(button);
  return Boolean(button && draftRow.value?.contains(button));
});
// ClickableRegion: @pointerdown.capture="onPointerdown" on the root
let pressedWhileSuppressed = false;

function onPointerdown() {
  pressedWhileSuppressed = props.suppressed;
}

function onClick(event) {
  const isPointerClick = Boolean(event?.detail);
  const wasSuppressed = isPointerClick && pressedWhileSuppressed;
  pressedWhileSuppressed = false;
  if (props.suppressed || wasSuppressed) return;
  // ...
}

I tried this on top of the current branch. All of EditableChipListSave.spec.js passes, along with the QTI editor and TipTap suites, once useClickOutside.spec.js is updated. With real mouse clicks in Chromium, these all behave as expected:

  • Save, and Enter on Save
  • Discard
  • With a blank chip open: deleting that chip, deleting another chip, and clicking another chip
  • Clicks on the gap and on the space beside Save
  • Close with an unsaved draft or an edited chip

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as laid out; the delayed close is gone and the branch is two commits.

  • useClickOutside closes first in the capture phase again; a click isInsideBoundary accepts only syncs.
  • useEditorBoundary.js exports provideEditorBoundary/injectEditorBoundary; TipTapEditor passes the injected one to useClickOutside.
  • EditableChipList provides your predicate (draftRow ref for the draft's buttons). No data-editor-boundary, isPopupDismissal, minimize payload or onListClick/closingClick left.
  • ClickableRegion ignores a pointer click pressed while suppressed. Searched :suppressed= consumers: 16 regions across 9 components share it, so a click on an open prompt's or option's blank space now closes without reopening there too. No consumer change needed.
  • docs/rich_text_editor.md: "Controls beside the editor" rewritten for provideEditorBoundary.
  • Tests: EditableChipListWithEditor.spec.js adds Close question unmounting the list (edited chip and written draft, Vue.config.async = false) and the space beside Save in the close targets; useClickOutside.spec.js and ClickableRegion.spec.js cover the boundary and the press check. 4 chip-list tests fail without the ClickableRegion change; all shared/views/QTIEditor and TipTapEditor suites pass.

Real mouse Save on two Associate distractors in Chromium: each closes, keeps the typed text and focuses its chip.

chip-save.webm

Distractors after Save


Written by rtibblesbot, an LLM-based coding agent.

@AlexVelezLl AlexVelezLl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good overall! Just a few comments to help us better understand the reasons behind this in the future.

const chipRegions = ref([]);
const draftRow = ref(null);

provideEditorBoundary(target => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a short comment on what this boundary covers and why? It isn't obvious from the code that an open chip's region counts only for its buttons, so a click on the blank space beside its Save still closes it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split the boundary into two named predicates instead of a comment: isOnClosedChip (whole region) and isOnOpenEditorButton (only buttons inside an open chip's region or the draft row). Blank space beside an open chip's Save matches neither, so it closes. provideEditorBoundary has no other caller.


Written by rtibblesbot, an LLM-based coding agent.

setup(props, { emit }) {
const button = ref(null);

let pressedWhileSuppressed = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a line on why this exists: a browser renders between a click's listeners, so a click that closes an editor inside the region turns the region back on before the click bubbles up to it. Without that, the check reads as arbitrary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added above pressedWhileSuppressed: browsers run microtasks, so Vue renders, between a click's listeners, so closing an editor inside the region un-suppresses it before the click bubbles up. No other suppressed-region check in the branch.


Written by rtibblesbot, an LLM-based coding agent.

Comment thread docs/rich_text_editor.md
- A click outside the editor closes it before the click's own handlers run.
- An ancestor that renders controls acting on the editor, such as Save, calls `provideEditorBoundary(isInside)` from `composables/useEditorBoundary.js`; `isInside(target)` says whether a click on `target` is on one.
- A click outside the editor for which `isInside` is true syncs the content and leaves the editor open: the control's own handler reads the content and closes the editor if it should.
- One call covers every editor below that ancestor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add that isInside should be true only for the controls, not the space around them? A click on that space would otherwise sync and leave the editor open, with nothing to close it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to "Controls beside the editor": isInside is true only on the controls, not the space around them, since a click there would sync and leave the editor open with nothing to close it.


Written by rtibblesbot, an LLM-based coding agent.

@rtibblesbot
rtibblesbot force-pushed the issue-6331-5bef83 branch 2 times, most recently from 08d1f8e to 4c1f3a3 Compare November 17, 2026 20:31

@AlexVelezLl AlexVelezLl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets fix the merge conflicts before merging :)

rtibblesbot and others added 2 commits November 18, 2026 05:42
A click that closes an open editor unsuppresses the region before the
click bubbles to it, which would open another editor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TipTapEditor injects a boundary from `provideEditorBoundary`: a click
outside the editor but inside it syncs the content and leaves the editor
open for the control's own handler. EditableChipList provides one covering
closed chips and the open chip's and draft's buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor Author

Rebased onto unstable; conflicts resolved.


Written by rtibblesbot, an LLM-based coding agent.

@rtibblesbot rtibblesbot changed the title Close an open answer or distractor chip on Save Let Save and delete act on an open answer or distractor chip Nov 18, 2026

@AlexVelezLl AlexVelezLl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes make sense. Manual QA checks out! LGTM!

@AlexVelezLl
AlexVelezLl merged commit 75db89a into learningequality:unstable Nov 19, 2026
73 of 76 checks passed

Copy link
Copy Markdown
Contributor Author

Quick check on rtibblesbot's work on this PR: react 👍 helpful · 😕 mixed · 👎 not helpful. Reply with anything specific.

@rtibblesbot
rtibblesbot deleted the issue-6331-5bef83 branch November 19, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[QTI] Clicking Save on an open answer or distractor chip leaves it open

2 participants