Repository navigation
Let Save and delete act on an open answer or distractor chip - #6357
Conversation
1fb006a to
b7761d3
Compare
b7761d3 to
4965747
Compare
AlexVelezLl
left a comment
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- 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.
- Replace
data-editor-boundarywith a boundary provided to the editor. A newTipTapEditor/composables/useEditorBoundary.jsexportsprovideEditorBoundary(isInside).TipTapEditorinjects it and passes it touseClickOutside. A click outside the editor but inside the boundary syncs the content and leaves the editor open, and anything else closes it as onunstable. The import ties the boundary to the editor, and one call covers every editor in a list. EditableChipListprovides 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 byopenChipandonRemove, 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, souseClickOutsidecloses the editor there, and a click there while a menu is open only closes the menu. That removesonListClick,isPopupDismissal, the click passed tominimizeandclosingClick.- 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. - Rewrite the "Controls beside the editor" section in
docs/rich_text_editor.mdforprovideEditorBoundary.
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
There was a problem hiding this comment.
Done as laid out; the delayed close is gone and the branch is two commits.
useClickOutsidecloses first in the capture phase again; a clickisInsideBoundaryaccepts only syncs.useEditorBoundary.jsexportsprovideEditorBoundary/injectEditorBoundary;TipTapEditorpasses the injected one touseClickOutside.EditableChipListprovides your predicate (draftRowref for the draft's buttons). Nodata-editor-boundary,isPopupDismissal,minimizepayload oronListClick/closingClickleft.ClickableRegionignores 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 forprovideEditorBoundary.- Tests:
EditableChipListWithEditor.spec.jsadds 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.jsandClickableRegion.spec.jscover the boundary and the press check. 4 chip-list tests fail without theClickableRegionchange; allshared/views/QTIEditorandTipTapEditorsuites pass.
Real mouse Save on two Associate distractors in Chromium: each closes, keeps the typed text and focuses its chip.
chip-save.webm
Written by rtibblesbot, an LLM-based coding agent.
4965747 to
91e8b4a
Compare
91e8b4a to
48ac7c8
Compare
AlexVelezLl
left a comment
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| - 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
08d1f8e to
4c1f3a3
Compare
AlexVelezLl
left a comment
There was a problem hiding this comment.
Lets fix the merge conflicts before merging :)
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>
|
Rebased onto
Written by rtibblesbot, an LLM-based coding agent. |
4c1f3a3 to
bdfc4ef
Compare
AlexVelezLl
left a comment
There was a problem hiding this comment.
Code changes make sense. Manual QA checks out! LGTM!
75db89a
into
learningequality:unstable
|
Quick check on rtibblesbot's work on this PR: react 👍 helpful · 😕 mixed · 👎 not helpful. Reply with anything specific. |

Summary
provideEditorBoundarymarks 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
ClickableRegionwas suppressed no longer activates it, in every QTI region (ClickableRegion/index.vue:51).unstableadded it (EditableChipList/index.vue:399).QA review
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-demoand click Edit on a question.Mammal. Press Enter on SAVE. The answer closes. One error shows.Kenya. Click Delete distractor 2. Nothing reopens.Look out for:
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.
🟡 Waiting for feedback
WAITING · on a reviewerLast updated: 2026-11-18 14:53 UTC