Reimplement inserting/removing \t chars in the composer.
* ui/composer-web-view.js (ComposerPageState): Add tabOut/tabIn functions, listen to key Tab key pressess on the body and invoke the appropriate method if found. * src/client/web-process/util-composer.vala: Removed old vala implementation of same.
This commit is contained in:
parent
742573c978
commit
fd97ad2887
2 changed files with 30 additions and 28 deletions
|
|
@ -27,34 +27,6 @@ namespace Util.Composer {
|
|||
Util.DOM.linkify_document(page.get_dom_document());
|
||||
}
|
||||
|
||||
public bool handle_key_press(WebKit.WebPage page, Gdk.EventKey event) {
|
||||
WebKit.DOM.Document document = page.get_dom_document();
|
||||
if (event.keyval == Gdk.Key.Tab) {
|
||||
document.exec_command("inserthtml", false,
|
||||
"<span style='white-space: pre-wrap'>\t</span>");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.keyval == Gdk.Key.ISO_Left_Tab) {
|
||||
// If there is no selection and the character before the cursor is tab, delete it.
|
||||
// WebKit.DOM.DOMSelection selection = document.get_default_view().get_selection();
|
||||
// if (selection.is_collapsed) {
|
||||
// selection.modify("extend", "backward", "character");
|
||||
// try {
|
||||
// if (selection.get_range_at(0).get_text() == "\t")
|
||||
// selection.delete_from_document();
|
||||
// else
|
||||
// selection.collapse_to_end();
|
||||
// } catch (Error error) {
|
||||
// debug("Error handling Left Tab: %s", error.message);
|
||||
// }
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////// From WebEditorFixer ///////////////////////
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,19 @@ ComposerPageState.prototype = {
|
|||
});
|
||||
},
|
||||
loaded: function() {
|
||||
let state = this;
|
||||
|
||||
this.messageBody = document.getElementById(ComposerPageState.BODY_ID);
|
||||
this.messageBody.addEventListener("keydown", function(e) {
|
||||
if (e.keyCode == 9) {
|
||||
if (!e.shiftKey) {
|
||||
state.tabOut();
|
||||
} else {
|
||||
state.tabIn();
|
||||
}
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
// Search for and remove a particular styling when we quote
|
||||
// text. If that style exists in the quoted text, we alter it
|
||||
|
|
@ -90,6 +102,24 @@ ComposerPageState.prototype = {
|
|||
document.execCommand("redo", false, null);
|
||||
this.checkCommandStack();
|
||||
},
|
||||
tabOut: function() {
|
||||
document.execCommand(
|
||||
"inserthtml", false, "<span style='white-space: pre-wrap'>\t</span>"
|
||||
);
|
||||
},
|
||||
tabIn: function() {
|
||||
// If there is no selection and the character before the
|
||||
// cursor is tab, delete it.
|
||||
let selection = window.getSelection();
|
||||
if (selection.isCollapsed) {
|
||||
selection.modify("extend", "backward", "character");
|
||||
if (selection.getRangeAt(0).toString() == "\t") {
|
||||
document.execCommand("delete", false, null);
|
||||
} else {
|
||||
selection.collapseToEnd();
|
||||
}
|
||||
}
|
||||
},
|
||||
getHtml: function() {
|
||||
return this.messageBody.innerHTML;
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue