0

[lensoverlay] Fix highlights being visible after selection clear.

Change-Id: If09252bbe6ed99fc5edff47fad8e51a5848961fb
Bug: 407113472
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6410674
Commit-Queue: Ali Stanfield <stanfield@google.com>
Reviewed-by: Ali Stanfield <stanfield@google.com>
Auto-Submit: Juan Mojica <juanmojica@google.com>
Cr-Commit-Position: refs/heads/main@{#1439802}
This commit is contained in:
Juan Mojica 2025-03-28 17:30:02 -07:00 committed by Chromium LUCI CQ
parent aa240be668
commit 7e6217a4e8
2 changed files with 69 additions and 0 deletions
chrome
browser/resources/lens/overlay
test/data/webui/lens/overlay

@ -120,6 +120,10 @@ export class SimplifiedTextLayerElement extends CrLitElement implements
this.listenerIds = [
this.browserProxy.callbackRouter.textReceived.addListener(
this.onTextReceived.bind(this)),
this.browserProxy.callbackRouter.clearAllSelections.addListener(
this.onClearRegionSelection.bind(this)),
this.browserProxy.callbackRouter.clearRegionSelection.addListener(
this.onClearRegionSelection.bind(this)),
];
this.setTextReceivedTimeout();
@ -218,6 +222,13 @@ export class SimplifiedTextLayerElement extends CrLitElement implements
}, this.translateTimeout.timeout);
}
private onClearRegionSelection() {
this.isSelectingRegion = false;
this.hasActionedText = false;
this.hideHighlightedLines = true;
this.highlightedLines = [];
}
private setTextReceivedTimeout() {
this.textReceivedTimeout.timeoutElapsedOrCleared = false;
this.textReceivedTimeout.timeoutId = setTimeout(() => {

@ -625,4 +625,62 @@ suite('SimplifiedSelection', function() {
await dispatchDetectTextInRegionEvent();
await showSelectedRegionContextMenuEvent2;
});
test('ClearAllSelectionsClearsHighlightedLines', async () => {
await addEmptyTextToPage(callbackRouterRemote);
// Add 3 words to the region text response.
await addGenericWordsToPageNormalized(callbackRouterRemote);
await waitAfterNextRender(textLayerElement);
assertFalse(textLayerElement.getHasActionedTextForTesting());
assertEquals(
2,
textLayerElement.shadowRoot.querySelectorAll('.highlighted-line')
.length);
// Simulate an action.
textLayerElement.onCopyDetectedText(/*startIndex=*/ 0,
/*endIndex=*/ 2,
/*callback=*/ () => {});
assertTrue(textLayerElement.getHasActionedTextForTesting());
callbackRouterRemote.clearAllSelections();
await flushTasks();
await waitAfterNextRender(textLayerElement);
assertFalse(textLayerElement.getHasActionedTextForTesting());
assertEquals(
0,
textLayerElement.shadowRoot.querySelectorAll('.highlighted-line')
.length);
});
test('ClearRegionSelectionClearsHighlightedLines', async () => {
await addEmptyTextToPage(callbackRouterRemote);
// Add 3 words to the region text response.
await addGenericWordsToPageNormalized(callbackRouterRemote);
await waitAfterNextRender(textLayerElement);
assertFalse(textLayerElement.getHasActionedTextForTesting());
assertEquals(
2,
textLayerElement.shadowRoot.querySelectorAll('.highlighted-line')
.length);
// Simulate an action.
textLayerElement.onCopyDetectedText(/*startIndex=*/ 0,
/*endIndex=*/ 2,
/*callback=*/ () => {});
assertTrue(textLayerElement.getHasActionedTextForTesting());
callbackRouterRemote.clearRegionSelection();
await flushTasks();
await waitAfterNextRender(textLayerElement);
assertFalse(textLayerElement.getHasActionedTextForTesting());
assertEquals(
0,
textLayerElement.shadowRoot.querySelectorAll('.highlighted-line')
.length);
});
});