[geary/wip/794700-lazy-load-conversations: 1/19] Only collapse runs of space, tab, carriage return, and newline
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/794700-lazy-load-conversations: 1/19] Only collapse runs of space, tab, carriage return, and newline
- Date: Mon, 21 Jan 2019 00:41:37 +0000 (UTC)
commit d5969fde9fd8651a6c039c5833be4d875ca541ef
Author: Alex Henrie <alexhenrie24 gmail com>
Date: Mon Jan 14 19:54:14 2019 -0700
Only collapse runs of space, tab, carriage return, and newline
Closes #184
test/client/composer/composer-web-view-test.vala | 13 +++++++++++++
ui/composer-web-view.js | 6 ++++--
2 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/test/client/composer/composer-web-view-test.vala
b/test/client/composer/composer-web-view-test.vala
index 6ad0268b..4bb36939 100644
--- a/test/client/composer/composer-web-view-test.vala
+++ b/test/client/composer/composer-web-view-test.vala
@@ -22,6 +22,7 @@ public class ComposerWebViewTest : ClientWebViewTestCase<ComposerWebView> {
add_test("get_text_with_nbsp", get_text_with_nbsp);
add_test("get_text_with_named_link", get_text_with_named_link);
add_test("get_text_with_url_link", get_text_with_named_link);
+ add_test("get_text_with_surrounding_nbsps", get_text_with_surrounding_nbsps);
}
public void load_resources() throws Error {
@@ -197,6 +198,18 @@ long, long, long, long, long, long, long, long, long, long,
}
}
+ public void get_text_with_surrounding_nbsps() throws Error {
+ load_body_fixture(" I like my space ");
+ this.test_view.get_text.begin((obj, ret) => { async_complete(ret); });
+ try {
+ assert(this.test_view.get_text.end(async_result()) ==
+ " I like my space\n\n\n\n");
+ } catch (Error err) {
+ print("Error: %s\n", err.message);
+ assert_not_reached();
+ }
+ }
+
protected override ComposerWebView set_up_test_view() {
return new ComposerWebView(this.config);
}
diff --git a/ui/composer-web-view.js b/ui/composer-web-view.js
index 6425cb61..97f2aa18 100644
--- a/ui/composer-web-view.js
+++ b/ui/composer-web-view.js
@@ -473,8 +473,10 @@ ComposerPageState.htmlToText = function(root) {
case 'normal':
case 'nowrap':
case 'pre-line':
- nodeText = nodeText.replace(/\s+/g, " ");
- if (nodeText == " " && /\s/.test(text.substr(-1)))
+ // Only space, tab, carriage return, and newline collapse
+ // https://www.w3.org/TR/2011/REC-CSS2-20110607/text.html#white-space-model
+ nodeText = nodeText.replace(/[ \t\r\n]+/g, " ");
+ if (nodeText == " " && " \t\r\n".includes(text.substr(-1)))
break; // There's already whitespace here
if (node == root.firstChild)
nodeText = nodeText.replace(/^ /, "");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]