Commit 6c6ab536 authored by Milan Crha's avatar Milan Crha

e-convert.js: Treat dash as a wrap-able character

WebKit can wrap after the dash ('-'), similarly as before a space,
thus let the EConvert to wrap in the same way.
parent 41c77587
......@@ -369,7 +369,7 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
ignoreLineLetters : 0, // used for EvoConvert.NOWRAP_CHAR_START and EvoConvert.NOWRAP_CHAR_END, which should be skipped in width calculation
useWrapWidth : wrapWidth,
spacesFrom : -1, // in 'str'
lastSpace : -1, // in this->line
lastWrapableChar : -1, // in this->line
lineLetters : 0,
line : "",
......@@ -404,10 +404,10 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
shouldWrap : function(nextChar) {
return this.canWrap && (!this.collapseWhiteSpace || nextChar != '\n') &&
(!this.isInUnwrapPart() || this.lastSpace != -1) && (this.lineLetters - this.ignoreLineLetters > this.useWrapWidth || (
(!this.isInUnwrapPart() || this.lastWrapableChar != -1) && (this.lineLetters - this.ignoreLineLetters > this.useWrapWidth || (
((!this.charWrap && (nextChar == " " || nextChar == "\t") && this.lineLetters - this.ignoreLineLetters > this.useWrapWidth) ||
((this.charWrap || (nextChar != " " && nextChar != "\t")) && this.lineLetters - this.ignoreLineLetters == this.useWrapWidth)) && (
this.lastSpace == -1/* || this.lastSpace == this.line.length*/)));
this.lastWrapableChar == -1/* || this.lastWrapableChar == this.line.length*/)));
},
commitSpaces : function(ii) {
......@@ -427,9 +427,9 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
}
this.spacesFrom = -1;
this.lastSpace = this.line.length;
this.lastWrapableChar = this.line.length;
} else if (this.spacesFrom != -1) {
this.lastSpace = this.line.length;
this.lastWrapableChar = this.line.length;
}
},
......@@ -438,9 +438,9 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
var didWrap = false;
if (this.canWrap && this.lastSpace != -1 && this.lineLetters - this.ignoreLineLetters > this.useWrapWidth) {
lines[lines.length] = this.line.substr(0, this.lastSpace);
this.line = this.line.substr(this.lastSpace);
if (this.canWrap && this.lastWrapableChar != -1 && this.lineLetters - this.ignoreLineLetters > this.useWrapWidth) {
lines[lines.length] = this.line.substr(0, this.lastWrapableChar);
this.line = this.line.substr(this.lastWrapableChar);
this.maybeRecalcIgnoreLineLetters();
didWrap = true;
} else if (!this.isInUnwrapPart() && this.useWrapWidth != -1 && this.lineLetters - this.ignoreLineLetters > this.useWrapWidth) {
......@@ -493,7 +493,7 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
this.lineLetters = this.canWrap ? EvoConvert.calcLineLetters(this.line) : this.line.length;
this.spacesFrom = -1;
this.lastSpace = -1;
this.lastWrapableChar = -1;
}
};
......@@ -535,7 +535,7 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
} else if (!worker.charWrap && (chr == " " || chr == "\t")) {
var setSpacesFrom = false;
if (chr == '\t') {
if (chr == "\t") {
worker.lineLetters = worker.lineLetters - ((worker.lineLetters - worker.ignoreLineLetters) % EvoConvert.TAB_WIDTH) + EvoConvert.TAB_WIDTH;
setSpacesFrom = true;
} else if ((worker.spacesFrom == -1 && worker.line != "") || (!worker.collapseWhiteSpace && !worker.mayConsumeWhitespaceAfterWrap(str, ii))) {
......@@ -563,6 +563,9 @@ EvoConvert.formatParagraph = function(str, ltr, align, indent, whiteSpace, wrapW
if (worker.shouldWrap(str[ii + 1]))
worker.commit(ii, false);
if (chr == "-" && worker.line.length && !worker.inAnchor)
worker.lastWrapableChar = worker.line.length;
}
}
......
......@@ -2611,7 +2611,19 @@ test_convert_to_plain (TestFixture *fixture)
"\n"
"\n"
"line6\n",
71 }
71 },
/* 67 */{ HTML ("<div>123 456-78 123456 7-890123 123-456-789- 1122------------- 789 --------------------- 123</div>"),
"123 456-78\n"
"123456 7-\n"
"890123\n"
"123-456-\n"
"789- 1122-\n"
"----------\n"
"-- 789 ---\n"
"----------\n"
"--------\n"
"123\n",
10 }
};
#undef HTML
......@@ -2950,7 +2962,21 @@ test_convert_to_plain_quoted (TestFixture *fixture)
"> level 1 repeat\n"
"level 0 back\n"
"level 0 back nested\n",
71 }
71 },
/* 23 */{ HTML ("<blockquote type='cite'>"
"<div>" QUOTE_SPAN (QUOTE_CHR) "123 456-78 123456 7-890123 123-456-789- 1122------------- 789 --------------------- 123</div>"
"</blockquote>"),
"> 123 456-78\n"
"> 123456 7-\n"
"> 890123\n"
"> 123-456-\n"
"> 789- 1122-\n"
"> ----------\n"
"> -- 789 ---\n"
"> ----------\n"
"> --------\n"
"> 123\n",
12 }
};
#undef QUOTE_SPAN
......
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