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.
This commit is contained in:
Michael James Gratton 2017-01-26 14:06:36 +11:00
parent e06a73ebd6
commit e22ece508c
4 changed files with 37 additions and 19 deletions

View file

@ -369,6 +369,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.
*/
@ -484,13 +491,6 @@ public class ComposerWebView : ClientWebView {
return flowed.str;
}
/**
* ???
*/
public void undo_blockquote_style() {
this.run_javascript.begin("geary.undoBlockquoteStyle();", null);
}
/**
* ???
*/

View file

@ -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,

View file

@ -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>

View file

@ -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);
},