Commit 71868534 authored by Lei Shi's avatar Lei Shi Committed by Chromium LUCI CQ

Fix resuming from selection that ended in space in Select-to-Speak

Previously, at the end of a nodeGroup, we use the trimmed text of the
nodeGroup to update currentCharIndex_. This approach causes issues when
the user resumes from selection that ended in space.

Bug: 1167435
Change-Id: Ifa74c459100f6fd444f6200b09eec1fe2f2b4042
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638917Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Commit-Queue: Lei Shi <leileilei@google.com>
Cr-Commit-Position: refs/heads/master@{#845339}
parent 06975e2d
...@@ -1602,10 +1602,15 @@ export class SelectToSpeak { ...@@ -1602,10 +1602,15 @@ export class SelectToSpeak {
onNodeGroupSpeakingCompleted_() { onNodeGroupSpeakingCompleted_() {
const currentNodeGroup = this.getCurrentNodeGroup_(); const currentNodeGroup = this.getCurrentNodeGroup_();
// Update the current char index to the end of the text content in this // Update the current char index to the end of the node group. If the
// nodeGroup. // endOffset is undefined, we set the index to the length of the node
// group's text.
if (currentNodeGroup && currentNodeGroup.endOffset !== undefined) {
this.currentCharIndex_ = currentNodeGroup.endOffset;
} else {
const nodeGroupText = (currentNodeGroup && currentNodeGroup.text) || ''; const nodeGroupText = (currentNodeGroup && currentNodeGroup.text) || '';
this.currentCharIndex_ = nodeGroupText.trimEnd().length; this.currentCharIndex_ = nodeGroupText.length;
}
const isLastNodeGroup = const isLastNodeGroup =
(this.currentNodeGroupIndex_ === this.currentNodeGroups_.length - 1); (this.currentNodeGroupIndex_ === this.currentNodeGroups_.length - 1);
......
...@@ -854,6 +854,48 @@ TEST_F( ...@@ -854,6 +854,48 @@ TEST_F(
}); });
}); });
TEST_F(
'SelectToSpeakNavigationControlTest', 'ResumeFromSelectionEndingInSpace',
function() {
const bodyHtml = '<p>This is some text with space.</p>';
const setFocusCallback = this.newCallback((root) => {
const node = this.findTextNode(root, 'This is some text with space.');
// Sets the selection to "This ".
chrome.automation.setDocumentSelection({
anchorObject: node,
anchorOffset: 0,
focusObject: node,
focusOffset: 5
});
});
this.runWithLoadedTree(bodyHtml, (root) => {
root.addEventListener(
'documentSelectionChanged', this.newCallback((event) => {
this.triggerReadSelectedText();
assertTrue(this.mockTts.currentlySpeaking());
assertEquals(this.mockTts.pendingUtterances().length, 1);
this.assertEqualsCollapseWhitespace(
this.mockTts.pendingUtterances()[0], 'This');
// Finishes the current utterance.
this.mockTts.finishPendingUtterance();
// Hitting resume will start from the remaining content of the
// paragraph.
selectToSpeak.onSelectToSpeakPanelAction_(
chrome.accessibilityPrivate.SelectToSpeakPanelAction.RESUME);
assertTrue(this.mockTts.currentlySpeaking());
assertEquals(this.mockTts.pendingUtterances().length, 1);
this.assertEqualsCollapseWhitespace(
this.mockTts.pendingUtterances()[0],
'is some text with space.');
}),
false);
setFocusCallback(root);
});
});
TEST_F('SelectToSpeakNavigationControlTest', 'ResizeWhilePlaying', function() { TEST_F('SelectToSpeakNavigationControlTest', 'ResizeWhilePlaying', function() {
const longLine = const longLine =
'Second paragraph is longer than 300 pixels and will wrap when resized'; 'Second paragraph is longer than 300 pixels and will wrap when resized';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment