formatting

This commit is contained in:
inssein 2015-05-27 21:30:17 -07:00
parent 8934b93bc7
commit b9aa3500a2

View file

@ -105,8 +105,7 @@
if (ctx.measureText(text).width < maxWidth) { if (ctx.measureText(text).width < maxWidth) {
lines.push(text); lines.push(text);
} } else {
else {
while (words.length > 0) { while (words.length > 0) {
/* /*
@ -125,21 +124,21 @@
while (Math.ceil(ctx.measureText(words[0]).width) >= maxWidth) { while (Math.ceil(ctx.measureText(words[0]).width) >= maxWidth) {
var tmp = words[0]; var tmp = words[0];
words[0] = tmp.slice(0, -1); words[0] = tmp.slice(0, -1);
if (words.length > 1) { if (words.length > 1) {
words[1] = tmp.slice(-1) + words[1]; words[1] = tmp.slice(-1) + words[1];
} } else {
else {
words.push(tmp.slice(-1)); words.push(tmp.slice(-1));
} }
} }
if (Math.ceil(ctx.measureText(line + words[0]).width) < maxWidth) { if (Math.ceil(ctx.measureText(line + words[0]).width) < maxWidth) {
line += words.shift() + ' '; line += words.shift() + ' ';
} } else {
else {
lines.push(line); lines.push(line);
line = ''; line = '';
} }
if (words.length === 0) { if (words.length === 0) {
lines.push(line.substring(0, line.length - 1)); lines.push(line.substring(0, line.length - 1));
} }
@ -194,9 +193,7 @@
selectionStart = this.selectionStart; selectionStart = this.selectionStart;
} }
var numLines = this._textLines.length; var numLines = this._textLines.length, removed = 0, lineLength;
var removed = 0;
var lineLength;
// case: we are at the end of input // case: we are at the end of input
if (selectionStart >= this.text.length) { if (selectionStart >= this.text.length) {
@ -210,7 +207,7 @@
lineLength = this._textLines[i].length; lineLength = this._textLines[i].length;
// case: we are in the current line // case: we are in the current line
if (selectionStart < lineLength + (this.text[removed + lineLength] == "\n" ? 1 : 0)) { if (selectionStart < lineLength + (this.text[removed + lineLength] == '\n' ? 1 : 0)) {
return { return {
lineIndex: i, lineIndex: i,
charIndex: selectionStart charIndex: selectionStart
@ -224,7 +221,7 @@
removed += lineLength; removed += lineLength;
// if there was a newline, we need to account for the newline character // if there was a newline, we need to account for the newline character
if (this.text[removed] == "\n") { if (this.text[removed] == '\n') {
removed++; removed++;
selectionStart--; selectionStart--;
} }