[geary/wip/728002-webkit2] Replace two composer IPC calls for indenting with a single one.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/728002-webkit2] Replace two composer IPC calls for indenting with a single one.
- Date: Fri, 27 Jan 2017 06:52:52 +0000 (UTC)
commit ba2a49b41f10eccab9b22f183dd91f73c13b2503
Author: Michael James Gratton <mike vee net>
Date: Thu Jan 26 14:06:36 2017 +1100
Replace two composer IPC calls for indenting with a single one.
* src/client/composer/composer-web-view.vala (ClientWebView): Replace
::undo_blockquote_style with ::indent_line.
* src/client/composer/composer-widget.vala (ComposerWidget::on_indent):
Call new ::indent_line method, rather than doing a execCommand and a
second JS thunking call to fix the markup.
* ui/composer-web-view.js: Also replace ::undoBlockquoteStyle with new
::indentLine method. Add unit test.
src/client/composer/composer-web-view.vala | 14 +++++++-------
src/client/composer/composer-widget.vala | 3 +--
test/js/composer-page-state-test.vala | 18 ++++++++++++++++++
ui/composer-web-view.js | 21 +++++++++++----------
4 files changed, 37 insertions(+), 19 deletions(-)
---
diff --git a/src/client/composer/composer-web-view.vala b/src/client/composer/composer-web-view.vala
index 20593a9..5356696 100644
--- a/src/client/composer/composer-web-view.vala
+++ b/src/client/composer/composer-web-view.vala
@@ -370,6 +370,13 @@ public class ComposerWebView : ClientWebView {
}
/**
+ * Indents the line at the current text cursor location.
+ */
+ public void indent_line() {
+ this.run_javascript.begin("geary.indentLine();", null);
+ }
+
+ /**
* Updates the signature block if it has not been deleted.
*/
public new void update_signature(string signature) {
@@ -487,13 +494,6 @@ public class ComposerWebView : ClientWebView {
/**
* ???
*/
- public void undo_blockquote_style() {
- this.run_javascript.begin("geary.undoBlockquoteStyle();", null);
- }
-
- /**
- * ???
- */
public void linkify_document() {
// XXX
}
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 7a44bcd..cb9fc2e 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -1781,8 +1781,7 @@ public class ComposerWidget : Gtk.EventBox {
}
private void on_indent(SimpleAction action, Variant? param) {
- on_action(action, param);
- this.editor.undo_blockquote_style();
+ this.editor.indent_line();
}
private void on_mouse_target_changed(WebKit.WebView web_view,
diff --git a/test/js/composer-page-state-test.vala b/test/js/composer-page-state-test.vala
index 931933a..f792984 100644
--- a/test/js/composer-page-state-test.vala
+++ b/test/js/composer-page-state-test.vala
@@ -11,6 +11,7 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
base("ComposerPageStateTest");
add_test("edit_context_font", edit_context_font);
add_test("edit_context_link", edit_context_link);
+ add_test("indent_line", indent_line);
add_test("contains_attachment_keywords", contains_attachment_keywords);
add_test("get_html", get_html);
add_test("get_text", get_text);
@@ -54,6 +55,23 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
}
}
+ public void indent_line() {
+ load_body_fixture("""<span id="test">some text</span>""");
+ try {
+ run_javascript(@"SelectionUtil.selectNode(document.getElementById('test'))");
+ run_javascript(@"geary.indentLine()");
+
assert(WebKitUtil.to_number(run_javascript(@"document.querySelectorAll('blockquote[type=cite]').length")) ==
1);
+
assert(WebKitUtil.to_string(run_javascript(@"document.querySelectorAll('blockquote[type=cite]').item(0).innerText"))
==
+ "some text");
+ } catch (Geary.JS.Error err) {
+ print("Geary.JS.Error: %s\n", err.message);
+ assert_not_reached();
+ } catch (Error err) {
+ print("WKError: %s\n", err.message);
+ assert_not_reached();
+ }
+ }
+
public void contains_attachment_keywords() {
load_body_fixture("""
<blockquote>inner quote</blockquote>
diff --git a/ui/composer-web-view.js b/ui/composer-web-view.js
index a1adeae..8207f2e 100644
--- a/ui/composer-web-view.js
+++ b/ui/composer-web-view.js
@@ -157,6 +157,17 @@ ComposerPageState.prototype = {
}
}
},
+ indentLine: function() {
+ document.execCommand("indent", false, null);
+ let nodeList = document.querySelectorAll(
+ "blockquote[style=\"margin: 0 0 0 40px; border: none; padding: 0px;\"]"
+ );
+ for (let i = 0; i < nodeList.length; ++i) {
+ let element = nodeList.item(i);
+ element.removeAttribute("style");
+ element.setAttribute("type", "cite");
+ }
+ },
updateSignature: function(signature) {
// XXX need mark the sig somehow so we can find it, select
// it and replace it using execCommand
@@ -278,16 +289,6 @@ ComposerPageState.prototype = {
);
}
},
- undoBlockquoteStyle: function() {
- let nodeList = document.querySelectorAll(
- "blockquote[style=\"margin: 0 0 0 40px; border: none; padding: 0px;\"]"
- );
- for (let i = 0; i < nodeList.length; ++i) {
- let element = nodeList.item(i);
- element.removeAttribute("style");
- element.setAttribute("type", "cite");
- }
- },
documentModified: function(element) {
window.webkit.messageHandlers.documentModified.postMessage(null);
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]