Skip to content
Permalink
Browse files

clean + long press delete

  • Loading branch information...
Gorash committed Mar 25, 2019
1 parent 41cf7d8 commit e7fcdf3891fd92aa463491f394cf6b18211e8ce2
Showing with 55 additions and 48 deletions.
  1. +55 −48 addons/web_editor/static/src/js/wysiwyg/plugin/keyboard.js
@@ -1032,8 +1032,10 @@ var KeyboardPlugin = AbstractPlugin.extend({
$(accentPlaceholder).remove();
callback(text, baseRange);
this._onAccentedAndVirtualKeyCallback = null;

};
this._onAccentedAndVirtualKeyTimer = setTimeout(this._onAccentedAndVirtualKeyCallback.bind(this));

$(accentPlaceholder).on('DOMSubtreeModified', this._onAccentedAndVirtualKeyCallback.bind(this));
},

//--------------------------------------------------------------------------
@@ -1315,62 +1317,67 @@ var KeyboardPlugin = AbstractPlugin.extend({
* @returns {Boolean} true if case is handled and event default must be prevented
*/
_onAndroidVirtualKeyboard: function (e) {
var self = this;
e.preventDefault();

if (!e.originalEvent.isComposing) {
return;
console.log("isComposing", e.originalEvent.isComposing);
if (e.originalEvent.isComposing) {
this._onAccentedAndVirtualKey(this._onAndroidVirtualKeyboardInsertComposition.bind(this));
return true;
}

this._onAccentedAndVirtualKey(function (text, range) {
// get the previous word to complete or correct
var previousText = '';
var point = dom.nextPoint(dom.prevPointUntil(range.getStartPoint(), function (point) {
if (dom.isBlock(point.node.childNodes[point.offset] || point.node)) {
},
_onAndroidVirtualKeyboardInsertComposition: function (text, range) {
var self = this;
console.log("-->", text);
// get the previous word to complete or correct
var previousText = '';
var point = dom.nextPoint(dom.prevPointUntil(range.getStartPoint(), function (point) {
if (dom.isBlock(point.node.childNodes[point.offset] || point.node)) {
return true;
}
if (dom.isText(point.node)) {
var char = point.node.textContent.slice(point.offset, point.offset+1);
if (char === ' ' || char === '\u00A0') {
return true;
}
if (dom.isText(point.node)) {
var char = point.node.textContent.slice(point.offset, point.offset+1);
if (char === ' ' || char === '\u00A0') {
return true;
}
previousText = char + previousText;
}
}));
previousText = char + previousText;
}
}));
var length = previousText.length;

// complete the word
if (!text.indexOf(previousText)) {
text = text.slice(previousText.length);
} else {
// autocorrect the word (change only the updated char, and keep the format for previous chars)
var length = previousText.length;
var remove = false;
while (point && point.node && length) {
if (dom.isText(point.node)) {
var char = point.node.textContent.slice(point.offset, point.offset + 1);
if (char.length) {
length--;
if (!remove && text[0] === char) {
text = text.slice(1);
} else {
point.node.textContent = point.node.textContent.slice(0, point.offset) + point.node.textContent.slice(point.offset + 1);
remove = true;
continue;
}
// complete the word
if (!text.indexOf(previousText)) {
text = text.slice(length);
} else {
if (length === (text.length + 1) && !previousText.indexOf(text)) {
// long press delete
text = '';
}

// autocorrect the word (change only the updated char, and keep the format for previous chars)
var remove = false;
while (point && point.node && length) {
if (dom.isText(point.node)) {
var char = point.node.textContent.slice(point.offset, point.offset + 1);
if (char.length) {
length--;
if (!remove && text[0] === char) {
text = text.slice(1);
} else {
point.node.textContent = point.node.textContent.slice(0, point.offset) + point.node.textContent.slice(point.offset + 1);
remove = true;
continue;
}
}
point = dom.nextPoint(point);
}
range.sc = range.ec = point.node;
range.so = range.eo = point.offset;
range.select();
}
if (text.length) {
range.select();
self.context.invoke('HelperPlugin.insertTextInline', text);
point = dom.nextPoint(point);
}
});
return true;
range.sc = range.ec = point.node;
range.so = range.eo = point.offset;
range.select();
}
if (text.length) {
range.select();
self.context.invoke('HelperPlugin.insertTextInline', text);
}
},
});

0 comments on commit e7fcdf3

Please sign in to comment.
You can’t perform that action at this time.