diff --git a/app/js/lib/utils.js b/app/js/lib/utils.js index 4f78773e..7750d429 100644 --- a/app/js/lib/utils.js +++ b/app/js/lib/utils.js @@ -189,6 +189,7 @@ function getRichElementValue(node, lines, line, selNode, selOffset) { if (node.nodeType != 1) { // NON-ELEMENT return; } + var isSelected = (selNode === node); var isBlock = node.tagName == 'DIV' || node.tagName == 'P'; var curChild; if (isBlock && line.length || node.tagName == 'BR') { @@ -200,12 +201,15 @@ function getRichElementValue(node, lines, line, selNode, selOffset) { line.push(node.alt); } } + if (isSelected && !selOffset) { + line.push('\001'); + } var curChild = node.firstChild; while (curChild) { getRichElementValue(curChild, lines, line, selNode, selOffset); curChild = curChild.nextSibling; } - if (selNode === node) { + if (isSelected && selOffset) { line.push('\001'); } if (isBlock && line.length) { diff --git a/app/js/message_composer.js b/app/js/message_composer.js index 4b48a3e6..c53d0469 100644 --- a/app/js/message_composer.js +++ b/app/js/message_composer.js @@ -695,6 +695,10 @@ MessageComposer.prototype.checkAutocomplete = function (forceFull) { var valueCaret = getRichValueWithCaret(textarea); var value = valueCaret[0]; var pos = valueCaret[1] >= 0 ? valueCaret[1] : value.length; + + if (!pos) { + this.cleanRichTextarea(value, true); + } } else { var textarea = this.textareaEl[0]; var pos = getFieldSelection(textarea); @@ -799,6 +803,7 @@ MessageComposer.prototype.onFocusBlur = function (e) { this.isActive = e.type == 'focus'; if (!this.isActive) { + this.cleanRichTextarea(); this.hideSuggestions(); } else { setTimeout(this.checkAutocomplete.bind(this), 100); @@ -832,6 +837,24 @@ MessageComposer.prototype.onRichPaste = function (e) { return true; } +MessageComposer.prototype.cleanRichTextarea = function (value, focused) { + if (value === undefined) { + value = getRichValue(this.richTextareaEl[0]); + } + if (value.match(/^\s*$/) && this.richTextareaEl.html().length > 0) { + this.richTextareaEl.html(''); + this.lastLength = 0; + this.wasEmpty = true; + + if (focused) { + var self = this; + setZeroTimeout(function () { + self.focus(); + }); + } + } +} + MessageComposer.prototype.onRichPasteNode = function (e) { var element = (e.originalEvent || e).target, src = (element || {}).src || '', diff --git a/app/less/app.less b/app/less/app.less index 488b1387..5ebd30cf 100644 --- a/app/less/app.less +++ b/app/less/app.less @@ -2723,20 +2723,15 @@ a.composer_command_option.composer_autocomplete_option_active .composer_command_ &:empty:before { content: attr(placeholder); color: #9aa2ab; + display: block; + margin-top: -1px; + margin-left: 1px; } - - &:active:before, - &:focus:before { - content: none; - } - - /* &:empty:active:before, &:empty:focus:before { - content: attr(placeholder); - color: #9aa2ab; + opacity: 0.75; } - */ + img { width: 20px;