2016-11-30 22:56:01 +11:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright 2016 Software Freedom Conservancy Inc.
|
|
|
|
|
|
* Copyright 2016 Michael Gratton <mike@vee.net>
|
|
|
|
|
|
*
|
|
|
|
|
|
* This software is licensed under the GNU Lesser General Public License
|
|
|
|
|
|
* (version 2.1 or later). See the COPYING file in this distribution.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Application logic for ComposerWebView.
|
|
|
|
|
|
*/
|
2017-01-04 01:15:08 +11:00
|
|
|
|
let ComposerPageState = function() {
|
2016-11-30 22:56:01 +11:00
|
|
|
|
this.init.apply(this, arguments);
|
|
|
|
|
|
};
|
2019-10-07 23:46:33 +11:00
|
|
|
|
ComposerPageState.SPACE_CHAR_REGEX = /[\s]/i;
|
|
|
|
|
|
ComposerPageState.WORD_CHAR_REGEX = /[\s\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~\u2000-\u206F\u2E00-\u2E7F]/i;
|
2017-01-26 16:31:03 +11:00
|
|
|
|
ComposerPageState.QUOTE_MARKER = "\x7f"; // delete
|
|
|
|
|
|
ComposerPageState.PROTOCOL_REGEX = /^(aim|apt|bitcoin|cvs|ed2k|ftp|file|finger|git|gtalk|http|https|irc|ircs|irc6|lastfm|ldap|ldaps|magnet|news|nntp|rsync|sftp|skype|smb|sms|svn|telnet|tftp|ssh|webcal|xmpp):/i;
|
2017-01-26 13:31:08 +11:00
|
|
|
|
// Taken from Geary.HTML.URL_REGEX, without the inline modifier (?x)
|
|
|
|
|
|
// at the start, which is unsupported in JS
|
2020-03-03 10:36:52 -05:00
|
|
|
|
ComposerPageState.URL_REGEX = new RegExp("\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)"+
|
|
|
|
|
|
"(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+"+
|
|
|
|
|
|
"(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))", "gi");
|
2016-12-02 01:08:07 +11:00
|
|
|
|
|
2016-11-30 22:56:01 +11:00
|
|
|
|
ComposerPageState.prototype = {
|
|
|
|
|
|
__proto__: PageState.prototype,
|
|
|
|
|
|
init: function() {
|
|
|
|
|
|
PageState.prototype.init.apply(this, []);
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
this.bodyPart = null;
|
|
|
|
|
|
this.signaturePart = null;
|
|
|
|
|
|
this.quotePart = null;
|
|
|
|
|
|
this.focusedPart = null;
|
|
|
|
|
|
|
2017-01-30 00:23:49 +11:00
|
|
|
|
this.selections = new Map();
|
|
|
|
|
|
this.nextSelectionId = 0;
|
2017-01-19 01:48:03 +11:00
|
|
|
|
this.cursorContext = null;
|
2017-01-04 20:11:01 +11:00
|
|
|
|
|
2016-12-03 11:20:00 +11:00
|
|
|
|
document.addEventListener("click", function(e) {
|
|
|
|
|
|
if (e.target.tagName == "A") {
|
2017-01-19 13:16:13 +11:00
|
|
|
|
e.preventDefault();
|
2016-12-03 11:20:00 +11:00
|
|
|
|
}
|
|
|
|
|
|
}, true);
|
2016-11-30 22:56:01 +11:00
|
|
|
|
},
|
|
|
|
|
|
loaded: function() {
|
2017-01-05 13:12:14 +11:00
|
|
|
|
let state = this;
|
|
|
|
|
|
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
this.bodyPart = document.getElementById("geary-body");
|
2017-11-16 15:49:51 +11:00
|
|
|
|
if (this.bodyPart != null) {
|
|
|
|
|
|
// Capture clicks on the document that aren't on an
|
|
|
|
|
|
// existing part and prevent focus leaving it. Bug 779369.
|
|
|
|
|
|
document.addEventListener("mousedown", function(e) {
|
|
|
|
|
|
if (!state.containedInPart(e.target)) {
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// This happens if we are loading a draft created by a MUA
|
|
|
|
|
|
// that isn't Geary, so we can't rely on any of the
|
|
|
|
|
|
// expected HTML structure to be in place.
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
this.bodyPart = document.body;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.signaturePart = document.getElementById("geary-signature");
|
2019-11-08 10:39:46 +11:00
|
|
|
|
if (this.signaturePart != null) {
|
|
|
|
|
|
ComposerPageState.linkify(this.signaturePart);
|
|
|
|
|
|
}
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
this.quotePart = document.getElementById("geary-quote");
|
|
|
|
|
|
|
2017-01-26 19:09:19 +11:00
|
|
|
|
// Should be using 'e.key' in listeners below instead of
|
|
|
|
|
|
// keyIdentifier, but that was only fixed in WK in Oct 2016
|
|
|
|
|
|
// (WK Bug 36267). Migrate to that when we can rely on it
|
|
|
|
|
|
// being in WebKitGTK.
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
document.body.addEventListener("keydown", function(e) {
|
2017-01-26 19:09:19 +11:00
|
|
|
|
if (e.keyIdentifier == "U+0009" &&// Tab
|
|
|
|
|
|
!e.ctrlKey && !e.altKey && !e.metaKey) {
|
2017-01-05 13:12:14 +11:00
|
|
|
|
if (!e.shiftKey) {
|
|
|
|
|
|
state.tabOut();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
state.tabIn();
|
|
|
|
|
|
}
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2017-01-26 19:09:19 +11:00
|
|
|
|
// We can't use keydown for this, captured or bubbled, since
|
2019-05-22 20:47:08 +00:00
|
|
|
|
// that will also cause the line that the cursor is currently
|
2017-01-26 19:09:19 +11:00
|
|
|
|
// positioned on when Enter is pressed to also be outdented.
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
document.body.addEventListener("keyup", function(e) {
|
2017-01-26 19:09:19 +11:00
|
|
|
|
if (e.keyIdentifier == "Enter" && !e.shiftKey) {
|
|
|
|
|
|
// XXX WebKit seems to support both InsertNewline and
|
|
|
|
|
|
// InsertNewlineInQuotedContent arguments for
|
|
|
|
|
|
// execCommand, both of which sound like they would be
|
|
|
|
|
|
// useful here. After a quick bit of testing neither
|
|
|
|
|
|
// worked out of the box, so need to investigate
|
|
|
|
|
|
// further. See:
|
|
|
|
|
|
// https://github.com/WebKit/webkit/blob/master/Source/WebCore/editing/EditorCommand.cpp
|
|
|
|
|
|
state.breakBlockquotes();
|
|
|
|
|
|
}
|
|
|
|
|
|
}, true);
|
2017-01-04 18:53:28 +11:00
|
|
|
|
|
2019-09-18 12:24:01 +02:00
|
|
|
|
// Handle file drag & drop
|
|
|
|
|
|
document.body.addEventListener("drop", state.handleFileDrop, true);
|
|
|
|
|
|
document.body.addEventListener("allowDrop", function(e) {
|
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
2016-11-30 22:56:01 +11:00
|
|
|
|
// Search for and remove a particular styling when we quote
|
|
|
|
|
|
// text. If that style exists in the quoted text, we alter it
|
|
|
|
|
|
// slightly so we don't mess with it later.
|
2017-01-02 10:51:26 +11:00
|
|
|
|
let nodeList = document.querySelectorAll(
|
2016-11-30 22:56:01 +11:00
|
|
|
|
"blockquote[style=\"margin: 0 0 0 40px; border: none; padding: 0px;\"]");
|
2017-01-02 10:51:26 +11:00
|
|
|
|
for (let i = 0; i < nodeList.length; ++i) {
|
2016-11-30 22:56:01 +11:00
|
|
|
|
nodeList.item(i).setAttribute(
|
|
|
|
|
|
"style",
|
|
|
|
|
|
"margin: 0 0 0 40px; padding: 0px; border:none;"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Focus within the HTML document
|
|
|
|
|
|
document.body.focus();
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
this.updateFocusClass(this.bodyPart);
|
2016-11-30 22:56:01 +11:00
|
|
|
|
|
2017-01-19 01:48:03 +11:00
|
|
|
|
// Set text cursor at appropriate position
|
2017-01-02 10:51:26 +11:00
|
|
|
|
let cursor = document.getElementById("cursormarker");
|
2016-11-30 22:56:01 +11:00
|
|
|
|
if (cursor != null) {
|
2017-01-02 10:51:26 +11:00
|
|
|
|
let range = document.createRange();
|
2016-11-30 22:56:01 +11:00
|
|
|
|
range.selectNodeContents(cursor);
|
|
|
|
|
|
range.collapse(false);
|
|
|
|
|
|
|
2017-01-02 10:51:26 +11:00
|
|
|
|
let selection = window.getSelection();
|
2016-11-30 22:56:01 +11:00
|
|
|
|
selection.removeAllRanges();
|
|
|
|
|
|
selection.addRange(range);
|
|
|
|
|
|
cursor.parentNode.removeChild(cursor);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-13 17:41:55 +10:00
|
|
|
|
|
|
|
|
|
|
// Enable editing only after modifying the body above.
|
|
|
|
|
|
this.setEditable(true);
|
|
|
|
|
|
|
|
|
|
|
|
PageState.prototype.loaded.apply(this, []);
|
|
|
|
|
|
},
|
|
|
|
|
|
setEditable: function(enabled) {
|
|
|
|
|
|
if (!enabled) {
|
|
|
|
|
|
this.stopBodyObserver();
|
|
|
|
|
|
}
|
2019-03-11 11:59:11 +11:00
|
|
|
|
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
this.bodyPart.contentEditable = true;
|
|
|
|
|
|
if (this.signaturePart != null) {
|
|
|
|
|
|
this.signaturePart.contentEditable = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.quotePart != null) {
|
|
|
|
|
|
this.quotePart.contentEditable = true;
|
|
|
|
|
|
}
|
2019-03-11 11:59:11 +11:00
|
|
|
|
|
2018-06-13 17:41:55 +10:00
|
|
|
|
if (enabled) {
|
|
|
|
|
|
// Enable modification observation only after the document
|
|
|
|
|
|
// has been set editable as WebKit will alter some attrs
|
|
|
|
|
|
this.startBodyObserver();
|
|
|
|
|
|
}
|
2016-12-02 01:08:07 +11:00
|
|
|
|
},
|
2017-01-04 18:53:28 +11:00
|
|
|
|
undo: function() {
|
|
|
|
|
|
document.execCommand("undo", false, null);
|
|
|
|
|
|
this.checkCommandStack();
|
|
|
|
|
|
},
|
|
|
|
|
|
redo: function() {
|
|
|
|
|
|
document.execCommand("redo", false, null);
|
|
|
|
|
|
this.checkCommandStack();
|
|
|
|
|
|
},
|
2017-01-30 00:23:49 +11:00
|
|
|
|
saveSelection: function() {
|
2017-01-30 15:40:58 +11:00
|
|
|
|
let id = (++this.nextSelectionId).toString();
|
2017-01-30 00:23:49 +11:00
|
|
|
|
this.selections.set(id, SelectionUtil.save());
|
|
|
|
|
|
return id;
|
|
|
|
|
|
},
|
|
|
|
|
|
freeSelection: function(id) {
|
|
|
|
|
|
this.selections.delete(id);
|
|
|
|
|
|
},
|
|
|
|
|
|
insertLink: function(href, selectionId) {
|
2019-10-05 10:25:25 -06:00
|
|
|
|
SelectionUtil.restore(this.selections.get(selectionId));
|
|
|
|
|
|
if (window.getSelection().isCollapsed) {
|
|
|
|
|
|
// The saved selection was empty, which means that the user is
|
|
|
|
|
|
// modifying an existing link instead of inserting a new one.
|
|
|
|
|
|
let selection = SelectionUtil.save();
|
|
|
|
|
|
let selected = SelectionUtil.getCursorElement();
|
|
|
|
|
|
SelectionUtil.selectNode(selected);
|
2017-01-19 02:26:42 +11:00
|
|
|
|
document.execCommand("createLink", false, href);
|
2019-10-05 10:25:25 -06:00
|
|
|
|
SelectionUtil.restore(selection);
|
2017-01-19 02:26:42 +11:00
|
|
|
|
} else {
|
2017-01-30 00:23:49 +11:00
|
|
|
|
document.execCommand("createLink", false, href);
|
2017-01-19 02:26:42 +11:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2019-10-05 10:25:25 -06:00
|
|
|
|
deleteLink: function(selectionId) {
|
|
|
|
|
|
SelectionUtil.restore(this.selections.get(selectionId));
|
|
|
|
|
|
if (window.getSelection().isCollapsed) {
|
|
|
|
|
|
// The saved selection was empty, which means that the user is
|
|
|
|
|
|
// deleting the entire existing link.
|
|
|
|
|
|
let selection = SelectionUtil.save();
|
|
|
|
|
|
let selected = SelectionUtil.getCursorElement();
|
|
|
|
|
|
SelectionUtil.selectNode(selected);
|
2017-01-19 02:26:42 +11:00
|
|
|
|
document.execCommand("unlink", false, null);
|
2019-10-05 10:25:25 -06:00
|
|
|
|
SelectionUtil.restore(selection);
|
2017-01-19 02:26:42 +11:00
|
|
|
|
} else {
|
2019-10-05 10:25:25 -06:00
|
|
|
|
document.execCommand("unlink", false, null);
|
2017-01-19 02:26:42 +11:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2017-01-26 14:06:36 +11:00
|
|
|
|
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");
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2017-12-06 17:04:18 -03:00
|
|
|
|
insertOrderedList: function() {
|
|
|
|
|
|
document.execCommand("insertOrderedList", false, null);
|
|
|
|
|
|
},
|
|
|
|
|
|
insertUnorderedList: function() {
|
|
|
|
|
|
document.execCommand("insertUnorderedList", false, null);
|
|
|
|
|
|
},
|
Clean up how composer loads content into its web view.
The main gist of this is to ensure that the composer's widgets are
constructed seperately to loading its content, and that we only ever call
ComposerWebView::load_html precisely once per composer instance.
* src/client/composer/composer-widget.vala: Remove referred message,
quote text and draft flag param from constructor signature, move any
calls that loaded data from them to new load method. Don't load
anything into the editor here. Make loading the signature file async,
and call new ComposerWebView::updateSignature method on the editor to
update it.
(ComposerWidget::load): New async message for loading content into the
composer. Move related code from the constructor and GearyController
here, make methods that were previously public for that private
again. Tidy up calls a bit now that we have a single place from which
to do it all, and can understand the process a bit better.
(ComposerWidget::on_editor_key_press_event): Don't reload the editor to
remove the quoted text, call new ComposerWebView::delete_quoted_message
method on it instead.
* src/client/composer/composer-web-view.vala
(ComposerWebView): Add ::delete_quoted_message ::update_signature
methods, thunk to JS.
(ComposerWebView::load_html): Add quote and is_draft parameters,
construct HTML for the composer using apporporate spacing here, instead
of relying on all the disparate parts from doing the right thing.
* src/client/application/geary-controller.vala
(GearyController::create_compose_widget_async): Load composer content
after adding it to the widget hierarchy, set focus only after
everything is set up.
* src/engine/rfc822/rfc822-utils.vala (quote_email_for_reply,
quote_email_for_forward): Don't add extra padding around quoted parts -
let callers manage their own whitespace.
* test/client/components/client-web-view-test-case.vala
(TestCase:load_body_fixture): Make HTML param non-nullable, update
subclasses.
* ui/composer-web-view.js (ComposerPageState): Add ::updateSignature and
::deleteQuotedMessage method stubs.
2017-01-25 11:16:20 +11:00
|
|
|
|
updateSignature: function(signature) {
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
if (this.signaturePart != null) {
|
2019-03-11 11:59:11 +11:00
|
|
|
|
if (signature.trim()) {
|
|
|
|
|
|
this.signaturePart.innerHTML = signature;
|
|
|
|
|
|
this.signaturePart.classList.remove("geary-no-display");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.signaturePart.innerHTML = "";
|
|
|
|
|
|
this.signaturePart.classList.add("geary-no-display");
|
|
|
|
|
|
}
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
}
|
Clean up how composer loads content into its web view.
The main gist of this is to ensure that the composer's widgets are
constructed seperately to loading its content, and that we only ever call
ComposerWebView::load_html precisely once per composer instance.
* src/client/composer/composer-widget.vala: Remove referred message,
quote text and draft flag param from constructor signature, move any
calls that loaded data from them to new load method. Don't load
anything into the editor here. Make loading the signature file async,
and call new ComposerWebView::updateSignature method on the editor to
update it.
(ComposerWidget::load): New async message for loading content into the
composer. Move related code from the constructor and GearyController
here, make methods that were previously public for that private
again. Tidy up calls a bit now that we have a single place from which
to do it all, and can understand the process a bit better.
(ComposerWidget::on_editor_key_press_event): Don't reload the editor to
remove the quoted text, call new ComposerWebView::delete_quoted_message
method on it instead.
* src/client/composer/composer-web-view.vala
(ComposerWebView): Add ::delete_quoted_message ::update_signature
methods, thunk to JS.
(ComposerWebView::load_html): Add quote and is_draft parameters,
construct HTML for the composer using apporporate spacing here, instead
of relying on all the disparate parts from doing the right thing.
* src/client/application/geary-controller.vala
(GearyController::create_compose_widget_async): Load composer content
after adding it to the widget hierarchy, set focus only after
everything is set up.
* src/engine/rfc822/rfc822-utils.vala (quote_email_for_reply,
quote_email_for_forward): Don't add extra padding around quoted parts -
let callers manage their own whitespace.
* test/client/components/client-web-view-test-case.vala
(TestCase:load_body_fixture): Make HTML param non-nullable, update
subclasses.
* ui/composer-web-view.js (ComposerPageState): Add ::updateSignature and
::deleteQuotedMessage method stubs.
2017-01-25 11:16:20 +11:00
|
|
|
|
},
|
|
|
|
|
|
deleteQuotedMessage: function() {
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
if (this.quotePart != null) {
|
|
|
|
|
|
this.quotePart.parentNode.removeChild(this.quotePart);
|
|
|
|
|
|
this.quotePart = null;
|
|
|
|
|
|
}
|
Clean up how composer loads content into its web view.
The main gist of this is to ensure that the composer's widgets are
constructed seperately to loading its content, and that we only ever call
ComposerWebView::load_html precisely once per composer instance.
* src/client/composer/composer-widget.vala: Remove referred message,
quote text and draft flag param from constructor signature, move any
calls that loaded data from them to new load method. Don't load
anything into the editor here. Make loading the signature file async,
and call new ComposerWebView::updateSignature method on the editor to
update it.
(ComposerWidget::load): New async message for loading content into the
composer. Move related code from the constructor and GearyController
here, make methods that were previously public for that private
again. Tidy up calls a bit now that we have a single place from which
to do it all, and can understand the process a bit better.
(ComposerWidget::on_editor_key_press_event): Don't reload the editor to
remove the quoted text, call new ComposerWebView::delete_quoted_message
method on it instead.
* src/client/composer/composer-web-view.vala
(ComposerWebView): Add ::delete_quoted_message ::update_signature
methods, thunk to JS.
(ComposerWebView::load_html): Add quote and is_draft parameters,
construct HTML for the composer using apporporate spacing here, instead
of relying on all the disparate parts from doing the right thing.
* src/client/application/geary-controller.vala
(GearyController::create_compose_widget_async): Load composer content
after adding it to the widget hierarchy, set focus only after
everything is set up.
* src/engine/rfc822/rfc822-utils.vala (quote_email_for_reply,
quote_email_for_forward): Don't add extra padding around quoted parts -
let callers manage their own whitespace.
* test/client/components/client-web-view-test-case.vala
(TestCase:load_body_fixture): Make HTML param non-nullable, update
subclasses.
* ui/composer-web-view.js (ComposerPageState): Add ::updateSignature and
::deleteQuotedMessage method stubs.
2017-01-25 11:16:20 +11:00
|
|
|
|
},
|
2017-01-26 13:31:08 +11:00
|
|
|
|
/**
|
|
|
|
|
|
* Determines if subject or body content refers to attachments.
|
|
|
|
|
|
*/
|
|
|
|
|
|
containsAttachmentKeyword: function(keywordSpec, subject) {
|
|
|
|
|
|
let ATTACHMENT_KEYWORDS_SUFFIX = "doc|pdf|xls|ppt|rtf|pps";
|
|
|
|
|
|
|
|
|
|
|
|
let completeKeys = new Set(keywordSpec.toLocaleLowerCase().split("|"));
|
|
|
|
|
|
let suffixKeys = new Set(ATTACHMENT_KEYWORDS_SUFFIX.split("|"));
|
|
|
|
|
|
|
|
|
|
|
|
// Check the subject line
|
|
|
|
|
|
if (ComposerPageState.containsKeywords(subject, completeKeys, suffixKeys)) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-07 23:49:12 +11:00
|
|
|
|
// Check the body text
|
|
|
|
|
|
let content = ComposerPageState.htmlToText(
|
|
|
|
|
|
this.bodyPart, ["blockquote"]
|
|
|
|
|
|
);
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
return ComposerPageState.containsKeywords(
|
2019-10-07 23:49:12 +11:00
|
|
|
|
content, completeKeys, suffixKeys
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
);
|
2017-01-26 13:31:08 +11:00
|
|
|
|
},
|
2017-01-05 13:12:14 +11:00
|
|
|
|
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
|
2017-01-19 01:48:03 +11:00
|
|
|
|
// text cursor is tab, delete it.
|
2017-01-05 13:12:14 +11:00
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2017-01-26 19:09:19 +11:00
|
|
|
|
breakBlockquotes: function() {
|
|
|
|
|
|
// Do this in two phases to avoid in-line mutations caused by
|
|
|
|
|
|
// execCommand affecting the DOM srtcuture
|
|
|
|
|
|
let count = 0;
|
|
|
|
|
|
let node = SelectionUtil.getCursorElement();
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
while (node != document.body) {
|
2017-01-26 19:09:19 +11:00
|
|
|
|
if (node.nodeName == "BLOCKQUOTE") {
|
|
|
|
|
|
count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
node = node.parentNode;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (count > 0) {
|
|
|
|
|
|
document.execCommand("outdent", false, null);
|
|
|
|
|
|
count--;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
cleanContent: function() {
|
2018-06-13 17:41:55 +10:00
|
|
|
|
// Prevent any modification signals being sent when mutating
|
2019-11-08 10:39:46 +11:00
|
|
|
|
// the document
|
2018-06-13 17:41:55 +10:00
|
|
|
|
this.stopBodyObserver();
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
ComposerPageState.linkify(this.bodyPart);
|
2019-11-08 10:39:46 +11:00
|
|
|
|
this.startBodyObserver();
|
2017-01-26 16:31:03 +11:00
|
|
|
|
},
|
2019-11-08 10:39:46 +11:00
|
|
|
|
getHtml: function(removeEmpty) {
|
|
|
|
|
|
if (removeEmpty === undefined) {
|
|
|
|
|
|
removeEmpty = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
let parent = document.createElement("DIV");
|
|
|
|
|
|
parent.appendChild(
|
2019-11-08 10:39:46 +11:00
|
|
|
|
ComposerPageState.cleanPart(this.bodyPart.cloneNode(true))
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
);
|
|
|
|
|
|
|
2019-11-08 10:39:46 +11:00
|
|
|
|
if (this.signaturePart != null &&
|
|
|
|
|
|
(!removeEmpty || this.signaturePart.innerText.trim() != "")) {
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
parent.appendChild(
|
2019-11-08 10:39:46 +11:00
|
|
|
|
ComposerPageState.cleanPart(this.signaturePart.cloneNode(true))
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-08 10:39:46 +11:00
|
|
|
|
if (this.quotePart != null &&
|
|
|
|
|
|
(!removeEmpty || this.quotePart.innerText.trim() != "")) {
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
parent.appendChild(
|
2019-11-08 10:39:46 +11:00
|
|
|
|
ComposerPageState.cleanPart(this.quotePart.cloneNode(true))
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return parent.innerHTML;
|
2016-12-02 01:08:07 +11:00
|
|
|
|
},
|
|
|
|
|
|
getText: function() {
|
2019-01-01 17:55:28 -07:00
|
|
|
|
let text = ComposerPageState.htmlToText(document.body);
|
|
|
|
|
|
return ComposerPageState.replaceNonBreakingSpace(text);
|
2016-12-02 19:49:35 +11:00
|
|
|
|
},
|
|
|
|
|
|
setRichText: function(enabled) {
|
|
|
|
|
|
if (enabled) {
|
|
|
|
|
|
document.body.classList.remove("plain");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
document.body.classList.add("plain");
|
|
|
|
|
|
}
|
2016-12-03 11:20:00 +11:00
|
|
|
|
},
|
2017-01-04 20:11:01 +11:00
|
|
|
|
selectionChanged: function() {
|
|
|
|
|
|
PageState.prototype.selectionChanged.apply(this, []);
|
|
|
|
|
|
|
2017-01-19 01:48:03 +11:00
|
|
|
|
let cursor = SelectionUtil.getCursorElement();
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
|
|
|
|
|
|
// Update cursor context
|
2017-01-19 01:48:03 +11:00
|
|
|
|
if (cursor != null) {
|
|
|
|
|
|
let newContext = new EditContext(cursor);
|
|
|
|
|
|
if (!newContext.equals(this.cursorContext)) {
|
|
|
|
|
|
this.cursorContext = newContext;
|
|
|
|
|
|
window.webkit.messageHandlers.cursorContextChanged.postMessage(
|
|
|
|
|
|
newContext.encode()
|
2017-01-04 20:11:01 +11:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
|
|
|
|
|
|
while (cursor != null) {
|
|
|
|
|
|
let parent = cursor.parentNode;
|
|
|
|
|
|
if (parent == document.body) {
|
|
|
|
|
|
this.updateFocusClass(cursor);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
cursor = parent;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Work around WebKit note yet supporting :focus-inside pseudoclass.
|
|
|
|
|
|
*/
|
|
|
|
|
|
updateFocusClass: function(newFocus) {
|
|
|
|
|
|
if (this.focusedPart != null) {
|
|
|
|
|
|
this.focusedPart.classList.remove("geary-focus");
|
|
|
|
|
|
this.focusedPart = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (newFocus == this.bodyPart ||
|
|
|
|
|
|
newFocus == this.signaturePart ||
|
|
|
|
|
|
newFocus == this.quotePart) {
|
|
|
|
|
|
this.focusedPart = newFocus;
|
|
|
|
|
|
this.focusedPart.classList.add("geary-focus");
|
|
|
|
|
|
}
|
2017-11-16 15:49:51 +11:00
|
|
|
|
},
|
|
|
|
|
|
containedInPart: function(target) {
|
|
|
|
|
|
let inPart = false;
|
|
|
|
|
|
for (let part of [this.bodyPart, this.quotePart, this.signaturePart]) {
|
|
|
|
|
|
if (part != null && (part == target || part.contains(target))) {
|
|
|
|
|
|
inPart = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return inPart;
|
2019-09-18 12:24:01 +02:00
|
|
|
|
},
|
|
|
|
|
|
handleFileDrop: function(dropEvent) {
|
|
|
|
|
|
dropEvent.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < dropEvent.dataTransfer.files.length; i++) {
|
|
|
|
|
|
const file = dropEvent.dataTransfer.files[i];
|
|
|
|
|
|
|
|
|
|
|
|
if (!file.type.startsWith('image/'))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
|
reader.onload = (function(filename, imageType) { return function(loadEvent) {
|
2019-10-26 19:27:54 +02:00
|
|
|
|
// Remove prefixed file type and encoding type
|
|
|
|
|
|
var parts = loadEvent.target.result.split(",");
|
|
|
|
|
|
if (parts.length < 2)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
window.webkit.messageHandlers.dragDropReceived.postMessage({
|
|
|
|
|
|
fileName: encodeURIComponent(filename),
|
|
|
|
|
|
fileType: imageType,
|
|
|
|
|
|
content: parts[1]
|
|
|
|
|
|
});
|
2019-09-18 12:24:01 +02:00
|
|
|
|
}; })(file.name, file.type);
|
|
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
|
|
}
|
2016-11-30 22:56:01 +11:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-01-26 13:31:08 +11:00
|
|
|
|
/**
|
|
|
|
|
|
* Determines if any keywords are present in a string.
|
|
|
|
|
|
*/
|
2019-10-07 23:46:33 +11:00
|
|
|
|
ComposerPageState.containsKeywords = function(line, wordKeys, suffixKeys) {
|
|
|
|
|
|
let lastToken = -1;
|
|
|
|
|
|
let lastSpace = -1;
|
|
|
|
|
|
for (var i = 0; i <= line.length; i++) {
|
|
|
|
|
|
let char = (i < line.length) ? line[i] : " ";
|
|
|
|
|
|
|
|
|
|
|
|
if (char.match(ComposerPageState.WORD_CHAR_REGEX)) {
|
|
|
|
|
|
if (lastToken + 1 < i) {
|
|
|
|
|
|
let wordToken = line.substring(lastToken + 1, i).toLocaleLowerCase();
|
|
|
|
|
|
let isWordMatch = wordKeys.has(wordToken);
|
|
|
|
|
|
let isSuffixMatch = suffixKeys.has(wordToken);
|
|
|
|
|
|
if (isWordMatch || isSuffixMatch) {
|
|
|
|
|
|
let spaceToken = line.substring(lastSpace + 1, i);
|
|
|
|
|
|
let isUrl = (spaceToken.match(ComposerPageState.URL_REGEX) != null);
|
|
|
|
|
|
|
|
|
|
|
|
// Matches a token if it is a word that isn't in a
|
|
|
|
|
|
// URL. I.e. this gets "some attachment." but not
|
|
|
|
|
|
// "http://attachment.com"
|
|
|
|
|
|
if (isWordMatch && !isUrl) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Matches a token if it is a suffix that isn't a
|
|
|
|
|
|
// URL and such that the space-delimited token
|
|
|
|
|
|
// ends with ".SUFFIX". I.e. this matches "see
|
|
|
|
|
|
// attachment.pdf." but not
|
|
|
|
|
|
// "http://example.com/attachment.pdf" or "see the
|
|
|
|
|
|
// pdf."
|
|
|
|
|
|
if (isSuffixMatch &&
|
|
|
|
|
|
!isUrl &&
|
|
|
|
|
|
spaceToken.length != (1 + wordToken.length) &&
|
|
|
|
|
|
spaceToken.endsWith("." + wordToken)) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2017-01-26 13:31:08 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-07 23:46:33 +11:00
|
|
|
|
lastToken = i;
|
|
|
|
|
|
|
|
|
|
|
|
if (char.match(ComposerPageState.SPACE_CHAR_REGEX)) {
|
|
|
|
|
|
lastSpace = i;
|
|
|
|
|
|
}
|
2017-01-26 13:31:08 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
/**
|
2019-11-08 10:39:46 +11:00
|
|
|
|
* Removes internal attributes from a composer part.
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
*/
|
2019-11-08 10:39:46 +11:00
|
|
|
|
ComposerPageState.cleanPart = function(part) {
|
Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.
* src/client/composer/composer-web-view.vala (ComposerWebView): Move
composer CSS into composer-web-view.css resource file, load it when
loading JS resource and add it to the view's user content manager.
(ComposerWebView::load_html): Split up body, signature and quote into a
DIV container for each.
(ComposerWebView::linkify_content): Replaced with ::clean_content,
which will also tidy up internal markup before sending. Update call
site and unit test.
* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
more obtrusive white space when sending replies/forwards.
* test/client/composer/composer-web-view-test.vala,
test/js/composer-page-state-test.vala: Update tests to expect new HTML
and text output from ComposerWebView and use of individual parts for
composer markup.
* ui/composer-web-view.js (ComposerPageState): Replace messageBody
property and uses with bodyPart, signaturePart and quotePart. Set these
content-editable on load. Move listeners from messageBody back to the
document.body so they also listen for events on the additional
parts. Keep track of text cursor location within the parts and set a
class if so, to work around the lack of :focus-inside support.
(ComposerPageState::updateSignature): Implement by updating the inner
content of the signature part.
(ComposerPageState::deleteQuotedMessage): Implement by removing the
quote part from the DOM tree.
(ComposerPageState::containsAttachmentKeyword): Consider only the
bodyPart when scanning for attachments, remove hacks for ignoring the
signature any any quoted message.
(ComposerPageState::linkifyContent): Mirror ClientWebView change and
replace with ::cleanContent. Ensure existing parts have contenteditable
and focus class removed, remove signature and quote parts if empty.
(ComposerPageState::getHtml): Generate HTML using clones of the three
parts, so we can rmeove contenteditable and focus classes without
modifying the actual DOM.
(ComposerPageState::selectionChanged): Update focus class on parts as
needed.
2017-01-31 23:55:44 +11:00
|
|
|
|
if (part != null) {
|
|
|
|
|
|
part.removeAttribute("class");
|
|
|
|
|
|
part.removeAttribute("contenteditable");
|
|
|
|
|
|
}
|
|
|
|
|
|
return part;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-12-31 11:36:41 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Gets plain text that adequately represents the information in the HTML
|
|
|
|
|
|
*
|
|
|
|
|
|
* Asterisks are inserted around bold text, slashes around italic text, and
|
|
|
|
|
|
* underscores around underlined text. Link URLs are inserted after the link
|
|
|
|
|
|
* text.
|
|
|
|
|
|
*
|
2019-01-01 17:55:28 -07:00
|
|
|
|
* Each line of a blockquote is prefixed with
|
|
|
|
|
|
* `ComposerPageState.QUOTE_MARKER`, where the number of markers indicates
|
|
|
|
|
|
* the depth of nesting of the quote.
|
2018-12-31 11:36:41 -07:00
|
|
|
|
*/
|
2019-10-07 23:42:49 +11:00
|
|
|
|
ComposerPageState.htmlToText = function(root, blacklist = []) {
|
2018-12-31 11:36:41 -07:00
|
|
|
|
let parentStyle = window.getComputedStyle(root);
|
|
|
|
|
|
let text = "";
|
|
|
|
|
|
|
|
|
|
|
|
for (let node of (root.childNodes || [])) {
|
2019-10-07 23:42:49 +11:00
|
|
|
|
let nodeName = node.nodeName.toLowerCase();
|
|
|
|
|
|
if (blacklist.includes(nodeName)) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-31 11:36:41 -07:00
|
|
|
|
let isBlock = (
|
|
|
|
|
|
node instanceof Element
|
|
|
|
|
|
&& window.getComputedStyle(node).display == "block"
|
|
|
|
|
|
&& node.innerText
|
|
|
|
|
|
);
|
|
|
|
|
|
if (isBlock) {
|
|
|
|
|
|
// Make sure there's a newline before the element
|
|
|
|
|
|
if (text != "" && text.substr(-1) != "\n") {
|
|
|
|
|
|
text += "\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-07 23:42:49 +11:00
|
|
|
|
switch (nodeName) {
|
2018-12-31 11:36:41 -07:00
|
|
|
|
case "#text":
|
|
|
|
|
|
let nodeText = node.nodeValue;
|
|
|
|
|
|
switch (parentStyle.whiteSpace) {
|
|
|
|
|
|
case 'normal':
|
|
|
|
|
|
case 'nowrap':
|
|
|
|
|
|
case 'pre-line':
|
2019-01-14 19:54:14 -07:00
|
|
|
|
// 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)))
|
2018-12-31 11:36:41 -07:00
|
|
|
|
break; // There's already whitespace here
|
|
|
|
|
|
if (node == root.firstChild)
|
|
|
|
|
|
nodeText = nodeText.replace(/^ /, "");
|
|
|
|
|
|
if (node == root.lastChild)
|
|
|
|
|
|
nodeText = nodeText.replace(/ $/, "");
|
|
|
|
|
|
// Fall through
|
|
|
|
|
|
default:
|
|
|
|
|
|
text += nodeText;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "a":
|
2019-02-08 23:16:01 -07:00
|
|
|
|
if (node.closest("body.plain")) {
|
2019-10-07 23:42:49 +11:00
|
|
|
|
text += ComposerPageState.htmlToText(node, blacklist);
|
2019-02-08 23:16:01 -07:00
|
|
|
|
} else if (node.textContent == node.href) {
|
2018-12-31 11:36:41 -07:00
|
|
|
|
text += "<" + node.href + ">";
|
|
|
|
|
|
} else {
|
2019-10-07 23:42:49 +11:00
|
|
|
|
text += ComposerPageState.htmlToText(node, blacklist);
|
2018-12-31 11:36:41 -07:00
|
|
|
|
text += " <" + node.href + ">";
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "b":
|
|
|
|
|
|
case "strong":
|
2019-02-08 23:16:01 -07:00
|
|
|
|
if (node.closest("body.plain")) {
|
2019-10-07 23:42:49 +11:00
|
|
|
|
text += ComposerPageState.htmlToText(node, blacklist);
|
2019-02-08 23:16:01 -07:00
|
|
|
|
} else {
|
2019-10-07 23:42:49 +11:00
|
|
|
|
text += "*" + ComposerPageState.htmlToText(node, blacklist) + "*";
|
2019-02-08 23:16:01 -07:00
|
|
|
|
}
|
2018-12-31 11:36:41 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "blockquote":
|
2019-10-07 23:42:49 +11:00
|
|
|
|
let bqText = ComposerPageState.htmlToText(node, blacklist);
|
2019-01-01 17:55:28 -07:00
|
|
|
|
// If there is a newline at the end of the quote, remove it
|
|
|
|
|
|
// After this switch we ensure that there is a newline after the quote
|
|
|
|
|
|
bqText = bqText.replace(/\n$/, "");
|
|
|
|
|
|
let lines = bqText.split("\n");
|
|
|
|
|
|
for (let i = 0; i < lines.length; i++)
|
|
|
|
|
|
lines[i] = ComposerPageState.QUOTE_MARKER + lines[i];
|
|
|
|
|
|
text += lines.join("\n");
|
2018-12-31 11:36:41 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "br":
|
|
|
|
|
|
text += "\n";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "i":
|
|
|
|
|
|
case "em":
|
2019-02-08 23:16:01 -07:00
|
|
|
|
if (node.closest("body.plain")) {
|
2019-10-07 23:42:49 +11:00
|
|
|
|
text += ComposerPageState.htmlToText(node, blacklist);
|
2019-02-08 23:16:01 -07:00
|
|
|
|
} else {
|
2019-10-07 23:42:49 +11:00
|
|
|
|
text += "/" + ComposerPageState.htmlToText(node, blacklist) + "/";
|
2019-02-08 23:16:01 -07:00
|
|
|
|
}
|
2018-12-31 11:36:41 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "u":
|
2019-02-08 23:16:01 -07:00
|
|
|
|
if (node.closest("body.plain")) {
|
2019-10-07 23:42:49 +11:00
|
|
|
|
text += ComposerPageState.htmlToText(node, blacklist);
|
2019-02-08 23:16:01 -07:00
|
|
|
|
} else {
|
2019-10-07 23:42:49 +11:00
|
|
|
|
text += "_" + ComposerPageState.htmlToText(node, blacklist) + "_";
|
2019-02-08 23:16:01 -07:00
|
|
|
|
}
|
2018-12-31 11:36:41 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "#comment":
|
2019-10-07 23:42:49 +11:00
|
|
|
|
case "style":
|
2018-12-31 11:36:41 -07:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2019-10-07 23:42:49 +11:00
|
|
|
|
text += ComposerPageState.htmlToText(node, blacklist);
|
2018-12-31 11:36:41 -07:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (isBlock) {
|
|
|
|
|
|
// Ensure that the last character is a newline
|
|
|
|
|
|
if (text.substr(-1) != "\n") {
|
|
|
|
|
|
text += "\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (node.nodeName.toLowerCase() == "p") {
|
|
|
|
|
|
// Ensure that the last two characters are newlines
|
|
|
|
|
|
if (text.substr(-2, 1) != "\n") {
|
|
|
|
|
|
text += "\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return text;
|
2019-03-22 01:52:07 +03:00
|
|
|
|
};
|
2018-12-31 11:36:41 -07:00
|
|
|
|
|
2017-01-26 16:31:03 +11:00
|
|
|
|
// Linkifies "plain text" link
|
|
|
|
|
|
ComposerPageState.linkify = function(node) {
|
|
|
|
|
|
if (node.nodeType == Node.TEXT_NODE) {
|
2019-10-22 18:53:18 -06:00
|
|
|
|
while (node.nodeValue) {
|
|
|
|
|
|
// Examine text node for something that looks like a URL
|
|
|
|
|
|
let urlRegex = new RegExp(ComposerPageState.URL_REGEX);
|
|
|
|
|
|
let url;
|
|
|
|
|
|
do {
|
|
|
|
|
|
let urlMatch = urlRegex.exec(node.nodeValue);
|
|
|
|
|
|
if (!urlMatch) {
|
|
|
|
|
|
return;
|
2017-01-26 16:31:03 +11:00
|
|
|
|
}
|
2019-10-22 18:53:18 -06:00
|
|
|
|
url = urlMatch[0];
|
|
|
|
|
|
} while (!url.match(ComposerPageState.PROTOCOL_REGEX));
|
|
|
|
|
|
|
|
|
|
|
|
// We got one! Now split the text and swap in a new anchor.
|
|
|
|
|
|
let before = node.nodeValue.substring(0, urlRegex.lastIndex - url.length);
|
|
|
|
|
|
let after = node.nodeValue.substring(urlRegex.lastIndex);
|
|
|
|
|
|
|
|
|
|
|
|
let beforeNode = document.createTextNode(before);
|
|
|
|
|
|
let linkNode = document.createElement("A");
|
|
|
|
|
|
linkNode.href = url;
|
|
|
|
|
|
linkNode.textContent = url;
|
|
|
|
|
|
let afterNode = document.createTextNode(after);
|
|
|
|
|
|
|
|
|
|
|
|
let parentNode = node.parentNode;
|
|
|
|
|
|
parentNode.insertBefore(beforeNode, node);
|
|
|
|
|
|
parentNode.insertBefore(linkNode, node);
|
|
|
|
|
|
parentNode.insertBefore(afterNode, node);
|
|
|
|
|
|
parentNode.removeChild(node);
|
|
|
|
|
|
|
|
|
|
|
|
// Keep searching for URLs after this one
|
|
|
|
|
|
node = afterNode;
|
2017-01-26 16:31:03 +11:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Recurse
|
|
|
|
|
|
let child = node.firstChild;
|
|
|
|
|
|
while (child != null) {
|
|
|
|
|
|
// Save the child and get its next sibling early since if
|
|
|
|
|
|
// it does actually contain a URL, it will be removed from
|
|
|
|
|
|
// the tree
|
|
|
|
|
|
let target = child;
|
|
|
|
|
|
child = child.nextSibling;
|
|
|
|
|
|
// Don't attempt to linkify existing links
|
|
|
|
|
|
if (target.nodeName != "A") {
|
|
|
|
|
|
ComposerPageState.linkify(target);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-01-02 10:23:35 +11:00
|
|
|
|
/**
|
|
|
|
|
|
* Converts all non-breaking space chars to plain spaces.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ComposerPageState.replaceNonBreakingSpace = function(text) {
|
|
|
|
|
|
// XXX this is a separate function for unit testing - since when
|
|
|
|
|
|
// running as a unit test, HTMLElement.innerText appears to not
|
|
|
|
|
|
// convert   into U+00A0.
|
|
|
|
|
|
return text.replace(new RegExp(" ", "g"), " ");
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-12-05 10:07:23 +11:00
|
|
|
|
|
2017-01-19 01:48:03 +11:00
|
|
|
|
/**
|
|
|
|
|
|
* Encapsulates editing-related state for a specific DOM node.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This must be kept in sync with the vala object of the same name.
|
|
|
|
|
|
*/
|
|
|
|
|
|
let EditContext = function() {
|
|
|
|
|
|
this.init.apply(this, arguments);
|
|
|
|
|
|
};
|
|
|
|
|
|
EditContext.LINK_MASK = 1 << 0;
|
|
|
|
|
|
|
|
|
|
|
|
EditContext.prototype = {
|
|
|
|
|
|
init: function(node) {
|
Replace composer link dialog with a popover.
* src/client/composer/composer-link-popover.vala: New GtkPopover subclass
for creating/editing links.
* src/client/composer/composer-web-view.vala (EditContext): Add is_link
and link_uri properties, decode them from the message string, add
decoding tests.
(ComposerWebView): Add some as-yet un-implemented methods for
inserting/deleting links.
* src/client/composer/composer-widget.vala (ComposerWidget): Add
cursor_url for storing current text cursor link, update it from the
cursor_context_changed signal param, rename hover_url to pointer_url to
match. Add link_activated signal to let user's open links they are
adding, hook that up in the controller. Rename
::update_selection_actions to ::update_cursor_actions, since that's a
little more apt now, also enable insert link action if there is a
cursor_url set as well as a selection. Remove ::link_dialog, replace
with ::new_link_popover, hook up the new popover's signals there as
appropriate.
(ComposerWidget::on_insert_link): Create and show a lin popover instead
of a dialog.
* ui/composer-web-view.js: Take note of whther the context node is a link
and if so, also it's href. Include both when serialsing for the
cursorContextChanged message. Add serialisation tests.
* ui/composer-link-popover.ui: New UI for link popover.
2017-01-19 02:23:57 +11:00
|
|
|
|
this.context = 0;
|
|
|
|
|
|
this.linkUrl = "";
|
|
|
|
|
|
|
|
|
|
|
|
if (node.nodeName == "A") {
|
|
|
|
|
|
this.context |= EditContext.LINK_MASK;
|
|
|
|
|
|
this.linkUrl = node.href;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-19 01:48:03 +11:00
|
|
|
|
let styles = window.getComputedStyle(node);
|
|
|
|
|
|
let fontFamily = styles.getPropertyValue("font-family");
|
2017-11-16 10:48:42 +11:00
|
|
|
|
if (["'", "\""].indexOf(fontFamily.charAt()) != -1) {
|
2017-01-19 01:48:03 +11:00
|
|
|
|
fontFamily = fontFamily.substr(1, fontFamily.length - 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.fontFamily = fontFamily;
|
|
|
|
|
|
this.fontSize = styles.getPropertyValue("font-size").replace("px", "");
|
2020-01-14 22:35:18 -06:00
|
|
|
|
this.fontColor = styles.getPropertyValue("color");
|
2017-01-19 01:48:03 +11:00
|
|
|
|
},
|
|
|
|
|
|
equals: function(other) {
|
|
|
|
|
|
return other != null
|
Replace composer link dialog with a popover.
* src/client/composer/composer-link-popover.vala: New GtkPopover subclass
for creating/editing links.
* src/client/composer/composer-web-view.vala (EditContext): Add is_link
and link_uri properties, decode them from the message string, add
decoding tests.
(ComposerWebView): Add some as-yet un-implemented methods for
inserting/deleting links.
* src/client/composer/composer-widget.vala (ComposerWidget): Add
cursor_url for storing current text cursor link, update it from the
cursor_context_changed signal param, rename hover_url to pointer_url to
match. Add link_activated signal to let user's open links they are
adding, hook that up in the controller. Rename
::update_selection_actions to ::update_cursor_actions, since that's a
little more apt now, also enable insert link action if there is a
cursor_url set as well as a selection. Remove ::link_dialog, replace
with ::new_link_popover, hook up the new popover's signals there as
appropriate.
(ComposerWidget::on_insert_link): Create and show a lin popover instead
of a dialog.
* ui/composer-web-view.js: Take note of whther the context node is a link
and if so, also it's href. Include both when serialsing for the
cursorContextChanged message. Add serialisation tests.
* ui/composer-link-popover.ui: New UI for link popover.
2017-01-19 02:23:57 +11:00
|
|
|
|
&& this.context == other.context
|
|
|
|
|
|
&& this.linkUrl == other.linkUrl
|
2017-01-19 01:48:03 +11:00
|
|
|
|
&& this.fontFamily == other.fontFamily
|
2020-01-14 22:35:18 -06:00
|
|
|
|
&& this.fontSize == other.fontSize
|
|
|
|
|
|
&& this.fontColor == other.fontColor;
|
2017-01-19 01:48:03 +11:00
|
|
|
|
},
|
|
|
|
|
|
encode: function() {
|
|
|
|
|
|
return [
|
Replace composer link dialog with a popover.
* src/client/composer/composer-link-popover.vala: New GtkPopover subclass
for creating/editing links.
* src/client/composer/composer-web-view.vala (EditContext): Add is_link
and link_uri properties, decode them from the message string, add
decoding tests.
(ComposerWebView): Add some as-yet un-implemented methods for
inserting/deleting links.
* src/client/composer/composer-widget.vala (ComposerWidget): Add
cursor_url for storing current text cursor link, update it from the
cursor_context_changed signal param, rename hover_url to pointer_url to
match. Add link_activated signal to let user's open links they are
adding, hook that up in the controller. Rename
::update_selection_actions to ::update_cursor_actions, since that's a
little more apt now, also enable insert link action if there is a
cursor_url set as well as a selection. Remove ::link_dialog, replace
with ::new_link_popover, hook up the new popover's signals there as
appropriate.
(ComposerWidget::on_insert_link): Create and show a lin popover instead
of a dialog.
* ui/composer-web-view.js: Take note of whther the context node is a link
and if so, also it's href. Include both when serialsing for the
cursorContextChanged message. Add serialisation tests.
* ui/composer-link-popover.ui: New UI for link popover.
2017-01-19 02:23:57 +11:00
|
|
|
|
this.context.toString(16),
|
|
|
|
|
|
this.linkUrl,
|
2017-01-19 01:48:03 +11:00
|
|
|
|
this.fontFamily,
|
2020-01-14 22:35:18 -06:00
|
|
|
|
this.fontSize,
|
|
|
|
|
|
this.fontColor
|
|
|
|
|
|
].join(";");
|
2017-01-19 01:48:03 +11:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Utility methods for managing the DOM Selection.
|
|
|
|
|
|
*/
|
|
|
|
|
|
let SelectionUtil = {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Returns the element immediately under the text cursor.
|
|
|
|
|
|
*
|
|
|
|
|
|
* If there is a non-empty selection, the element at the end of the
|
|
|
|
|
|
* selection is returned.
|
|
|
|
|
|
*/
|
|
|
|
|
|
getCursorElement: function() {
|
|
|
|
|
|
let selection = window.getSelection();
|
|
|
|
|
|
let node = selection.focusNode;
|
2017-01-26 13:31:08 +11:00
|
|
|
|
if (node != null && node.nodeType != Node.ELEMENT_NODE) {
|
2017-01-19 01:48:03 +11:00
|
|
|
|
node = node.parentNode;
|
|
|
|
|
|
}
|
|
|
|
|
|
return node;
|
2017-01-19 02:26:42 +11:00
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Modifies the selection so that it contains the given target node.
|
|
|
|
|
|
*/
|
|
|
|
|
|
selectNode: function(target) {
|
|
|
|
|
|
let newRange = new Range();
|
|
|
|
|
|
newRange.selectNode(target);
|
|
|
|
|
|
|
|
|
|
|
|
let selection = window.getSelection();
|
|
|
|
|
|
selection.removeAllRanges();
|
|
|
|
|
|
selection.addRange(newRange);
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Saves the current selection so it can be restored with `restore`.
|
|
|
|
|
|
*/
|
|
|
|
|
|
save: function() {
|
|
|
|
|
|
let selection = window.getSelection();
|
|
|
|
|
|
var ranges = [];
|
|
|
|
|
|
let len = selection.rangeCount;
|
|
|
|
|
|
for (let i = 0; i < len; ++i) {
|
|
|
|
|
|
ranges.push(selection.getRangeAt(i));
|
|
|
|
|
|
}
|
|
|
|
|
|
return ranges;
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Restores the selection saved with `save`.
|
|
|
|
|
|
*/
|
|
|
|
|
|
restore: function(saved) {
|
|
|
|
|
|
let selection = window.getSelection();
|
|
|
|
|
|
selection.removeAllRanges();
|
|
|
|
|
|
for (let i = 0; i < saved.length; i++) {
|
|
|
|
|
|
selection.addRange(saved[i]);
|
|
|
|
|
|
}
|
2017-01-19 01:48:03 +11:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-30 22:56:01 +11:00
|
|
|
|
var geary = new ComposerPageState();
|