fix notification word wrapping

This commit is contained in:
Howard Stearns 2017-04-07 07:08:19 -07:00
parent b089fd03b8
commit 5d341778c5

View file

@ -427,21 +427,24 @@ function deleteNotification(index) {
arrays.splice(index, 1); arrays.splice(index, 1);
} }
// wraps whole word to newline
function stringDivider(str, slotWidth, spaceReplacer) {
var left, right;
if (str.length > slotWidth && slotWidth > 0) { // Trims extra whitespace and breaks into lines of length no more than MAX_LENGTH, breaking at spaces. Trims extra whitespace.
left = str.substring(0, slotWidth); var MAX_LENGTH = 42;
right = str.substring(slotWidth); function wordWrap(string) {
return left + spaceReplacer + stringDivider(right, slotWidth, spaceReplacer); var finishedLines = [], currentLine = '';
string.split(/\s/).forEach(function (word) {
var tail = currentLine ? ' ' + word : word;
if ((currentLine.length + tail.length) <= MAX_LENGTH) {
currentLine += tail;
} else {
finishedLines.push(currentLine);
currentLine = word;
}
});
if (currentLine) {
finishedLines.push(currentLine);
} }
return str; return finishedLines.join('\n');
}
// formats string to add newline every 43 chars
function wordWrap(str) {
return stringDivider(str, 43.0, "\n");
} }
function update() { function update() {