Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/editing.js

Issue 2395293002: Work around bad line break offset calculation (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Processes events related to editing text and emits the 6 * @fileoverview Processes events related to editing text and emits the
7 * appropriate spoken and braille feedback. 7 * appropriate spoken and braille feedback.
8 */ 8 */
9 9
10 goog.provide('editing.TextEditHandler'); 10 goog.provide('editing.TextEditHandler');
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 this.node_.textSelEnd, 126 this.node_.textSelEnd,
127 true /* triggered by user */); 127 true /* triggered by user */);
128 this.changed(textChangeEvent); 128 this.changed(textChangeEvent);
129 this.outputBraille_(); 129 this.outputBraille_();
130 }, 130 },
131 131
132 /** @override */ 132 /** @override */
133 getLineIndex: function(charIndex) { 133 getLineIndex: function(charIndex) {
134 if (!this.multiline) 134 if (!this.multiline)
135 return 0; 135 return 0;
136 var breaks = this.node_.lineStartOffsets || []; 136 var breaks = this.getLineBreaks_();
137 var index = 0; 137 var index = 0;
138 while (index < breaks.length && breaks[index] <= charIndex) 138 while (index < breaks.length && breaks[index] <= charIndex)
139 ++index; 139 ++index;
140 return index; 140 return index;
141 }, 141 },
142 142
143 /** @override */ 143 /** @override */
144 getLineStart: function(lineIndex) { 144 getLineStart: function(lineIndex) {
145 if (!this.multiline || lineIndex == 0) 145 if (!this.multiline || lineIndex == 0)
146 return 0; 146 return 0;
(...skipping 14 matching lines...) Expand all
161 return end; 161 return end;
162 }, 162 },
163 163
164 /** 164 /**
165 * @return {Array<number>} 165 * @return {Array<number>}
166 * @private 166 * @private
167 */ 167 */
168 getLineBreaks_: function() { 168 getLineBreaks_: function() {
169 // node.lineStartOffsets is undefined when the multiline field has no line 169 // node.lineStartOffsets is undefined when the multiline field has no line
170 // breaks. 170 // breaks.
171 return this.node_.lineStartOffsets || []; 171 // The line break calculation is fuzzy because the last offset doesn't
172 // correspond with the actual text selection data, so let's just ignore it
173 // here...
174 var breaks = this.node_.lineStartOffsets || [];
175 return breaks.slice(0, breaks.length - 1);
172 }, 176 },
173 177
174 /** @private */ 178 /** @private */
175 outputBraille_: function() { 179 outputBraille_: function() {
176 var isFirstLine = false; // First line in a multiline field. 180 var isFirstLine = false; // First line in a multiline field.
177 var output = new Output(); 181 var output = new Output();
178 var range; 182 var range;
179 if (this.multiline) { 183 if (this.multiline) {
180 var lineIndex = this.getLineIndex(this.start); 184 var lineIndex = this.getLineIndex(this.start);
181 if (lineIndex == 0) { 185 if (lineIndex == 0) {
(...skipping 28 matching lines...) Expand all
210 testNode = testNode.parent; 214 testNode = testNode.parent;
211 } while (testNode); 215 } while (testNode);
212 216
213 if (rootFocusedEditable) 217 if (rootFocusedEditable)
214 return new TextFieldTextEditHandler(rootFocusedEditable); 218 return new TextFieldTextEditHandler(rootFocusedEditable);
215 219
216 return null; 220 return null;
217 }; 221 };
218 222
219 }); 223 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698