Fix compose focus/cursor

This commit is contained in:
RainLoop Team 2017-07-06 02:49:12 +03:00
parent ab374bbb71
commit a72b95a868
3 changed files with 60 additions and 37 deletions

View file

@ -280,7 +280,7 @@ class ContactsPopupView extends AbstractViewNext
{
this.bBackToCompose = false;
hideScreenPopup(require('View/Popup/Contacts'));
hideScreenPopup(ContactsPopupView);
switch (this.sLastComposeFocusedField)
{

View file

@ -2,6 +2,26 @@
(function() {
var
selectRange = function (el, start, end) {
if (!el) {
return;
}
if(end === undefined) {
end = start;
}
if('selectionStart' in el) {
el.selectionStart = start;
el.selectionEnd = end;
} else if(el.setSelectionRange) {
el.setSelectionRange(start, end);
} else if(el.createTextRange) {
var range = el.createTextRange();
range.collapse(true);
range.moveEnd('character', end);
range.moveStart('character', start);
range.select();
}
},
simplePlainToHtml = function (sPlain) {
return sPlain
.replace(/&/g, '&')
@ -50,10 +70,11 @@
hidpi: true,
init: function(editor)
{
if (editor.elementMode === CKEDITOR.ELEMENT_MODE_INLINE)
if (editor.elementMode === CKEDITOR.ELEMENT_MODE_INLINE) {
return;
}
editor.__plainUtils = {
editor.__textUtils = {
plainToHtml: function(data) {
return window.rainloop_Utils_plainToHtml ?
window.rainloop_Utils_plainToHtml(data, true) : simplePlainToHtml(data);
@ -94,11 +115,8 @@
editable.setData(editor.getData(1));
editor.__plain = editable;
editor.__textarea = textarea.$;
// Having to make <textarea> fixed sized to conquer the following bugs:
// 1. The textarea height/width='100%' doesn't constraint to the 'td' in IE6/7.
// 2. Unexpected vertical-scrolling behavior happens whenever focus is moving out of editor
// if text content within it has overflowed. (#4762)
if (CKEDITOR.env.ie) {
editable.attachListener(editor, 'resize', onResize, editable);
editable.attachListener(CKEDITOR.document.getWindow(), 'resize', onResize, editable);
@ -122,6 +140,12 @@
editor.on('mode', function() {
editor.getCommand('plain').setState(editor.mode === 'plain' ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF);
editor.editable().addClass('cke_enable_context_menu');
editor.focus();
if (editor.mode === 'plain') {
selectRange(editor.__textarea, 0);
}
});
function onResize() {
@ -137,7 +161,7 @@
base: CKEDITOR.editable,
proto: {
setData: function(data) {
this.setValue(this.editor.__plainUtils.htmlToPlain(data));
this.setValue(this.editor.__textUtils.htmlToPlain(data));
this.editor.fire('dataReady');
},
setRawData: function(data) {
@ -145,7 +169,7 @@
this.editor.fire('dataReady');
},
getData: function() {
return this.editor.__plainUtils.plainToHtml(this.getValue());
return this.editor.__textUtils.plainToHtml(this.getValue());
},
getRawData: function() {
return this.getValue();
@ -163,25 +187,24 @@
}
}
});
})();
CKEDITOR.plugins.plain = {
commands: {
plain: {
modes: {
wysiwyg: 1, plain: 1
},
editorFocus: false,
readOnly: 1,
exec: function(editor) {
if (editor.mode === 'wysiwyg') {
editor.fire('saveSnapshot');
}
editor.getCommand('plain').setState(CKEDITOR.TRISTATE_DISABLED);
editor.setMode(editor.mode === 'plain' ? 'wysiwyg' : 'plain');
},
canUndo: false
CKEDITOR.plugins.plain = {
commands: {
plain: {
modes: {
wysiwyg: 1, plain: 1
},
editorFocus: true,
readOnly: false,
exec: function(editor) {
if (editor.mode === 'wysiwyg') {
editor.fire('saveSnapshot');
}
editor.getCommand('plain').setState(CKEDITOR.TRISTATE_DISABLED);
editor.setMode(editor.mode === 'plain' ? 'wysiwyg' : 'plain');
},
canUndo: false
}
}
}
};
};
}());

View file

@ -10,7 +10,7 @@
isEmptyText = false,
newLine = (isHtml ? '<br />' : "\n"),
clearHtmlLine = function(html) {
return $.trim(editor.__plainUtils.htmlToPlain(html));
return $.trim(editor.__textUtils.htmlToPlain(html));
};
isEmptyText = '' === $.trim(text);
@ -23,12 +23,12 @@
{
if (isHtml && !editor.__previos_signature_is_html)
{
editor.__previos_signature = editor.__plainUtils.plainToHtml(editor.__previos_signature);
editor.__previos_signature = editor.__textUtils.plainToHtml(editor.__previos_signature);
editor.__previos_signature_is_html = true;
}
else if (!isHtml && editor.__previos_signature_is_html)
{
editor.__previos_signature = editor.__plainUtils.htmlToPlain(editor.__previos_signature);
editor.__previos_signature = editor.__textUtils.htmlToPlain(editor.__previos_signature);
editor.__previos_signature_is_html = false;
}
@ -104,13 +104,13 @@
try
{
if ('plain' === editor.mode && editor.__plain && editor.__plainUtils)
if ('plain' === editor.mode && editor.__plain && editor.__textUtils)
{
if (editor.__plainUtils && editor.__plainUtils.htmlToPlain)
if (editor.__textUtils && editor.__textUtils.htmlToPlain)
{
if (bIsHtml)
{
sResultSignature = editor.__plainUtils.htmlToPlain(sResultSignature);
sResultSignature = editor.__textUtils.htmlToPlain(sResultSignature);
}
}
@ -120,11 +120,11 @@
}
else
{
if (editor.__plainUtils && editor.__plainUtils.plainToHtml)
if (editor.__textUtils && editor.__textUtils.plainToHtml)
{
if (!bIsHtml)
{
sResultSignature = editor.__plainUtils.plainToHtml(sResultSignature);
sResultSignature = editor.__textUtils.plainToHtml(sResultSignature);
}
}