Commit c2ac7c32 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Filter out whitespace-only nodes in speech during editable text feedback

Sometimes, we get inline text boxes containing only whitespace in the middle or end of a line.
This is typically fine if the whitespace is the only text. However, there are situations where we want this whitespace not to be queued.

When there is non-whitespace text in the line:
inLineTextBox: "this is a soft-wrap"
inLineTextBox.nextOnLine: " "
inLineTextBox: "of text"

becomes (for the first line):
"this is a soft-wrap", "space"

inlineTextBox: "this"
inLineTextBox.nextOnLine: " "
inLineTextBox.nextOnLine.nextOnLine: "is"

becomes
"this", "space", "is"

Test: manual.
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: If8524c90f4187704bbf1dcfb5580e5697eedeccf
Reviewed-on: https://chromium-review.googlesource.com/1015657Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: David Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551767}
parent ca196300
...@@ -538,12 +538,17 @@ AutomationRichEditableText.prototype = { ...@@ -538,12 +538,17 @@ AutomationRichEditableText.prototype = {
for (var i = 0, cur; cur = lineNodes[i]; i++) { for (var i = 0, cur; cur = lineNodes[i]; i++) {
if (cur.children.length) if (cur.children.length)
continue; continue;
new Output()
var o = new Output()
.withRichSpeech( .withRichSpeech(
Range.fromNode(cur), prev ? Range.fromNode(prev) : null, Range.fromNode(cur), prev ? Range.fromNode(prev) : null,
Output.EventType.NAVIGATE) Output.EventType.NAVIGATE)
.withQueueMode(queueMode) .withQueueMode(queueMode);
.go();
// Ignore whitespace only output except if it is leading content on the
// line.
if (!o.isOnlyWhitespace || i == 0)
o.go();
prev = cur; prev = cur;
queueMode = cvox.QueueMode.QUEUE; queueMode = cvox.QueueMode.QUEUE;
} }
......
...@@ -679,6 +679,15 @@ Output.prototype = { ...@@ -679,6 +679,15 @@ Output.prototype = {
return false; return false;
}, },
/**
* @return {boolean} True if there is only whitespace in this output.
*/
get isOnlyWhitespace() {
return this.speechBuffer_.every(function(buff) {
return !/\S+/.test(buff.toString());
});
},
/** @return {Spannable} */ /** @return {Spannable} */
get braille() { get braille() {
return this.mergeBraille_(this.brailleBuffer_); return this.mergeBraille_(this.brailleBuffer_);
......
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