[FIX] web_editor: prevent focus change on recording undos

Part of https://github.com/odoo/odoo/pull/38959
task-2066614
This commit is contained in:
qsm-odoo
2019-11-18 09:56:07 +00:00
parent 466203311e
commit 0cbc188a71
@@ -423,6 +423,10 @@ var RTEWidget = Widget.extend({
* @param {boolean} internal_history
*/
historyRecordUndo: function ($target, event, internal_history) {
const initialActiveElement = document.activeElement;
const initialSelectionStart = initialActiveElement && initialActiveElement.selectionStart;
const initialSelectionEnd = initialActiveElement && initialActiveElement.selectionEnd;
$target = $($target);
var rng = range.create();
var $editable = $(rng && rng.sc).closest('.o_editable');
@@ -442,6 +446,12 @@ var RTEWidget = Widget.extend({
console.log('error', e);
}
history.recordUndo($editable, event, internal_history);
if (initialActiveElement && initialActiveElement !== document.activeElement) {
initialActiveElement.focus();
initialActiveElement.selectionStart = initialSelectionStart;
initialActiveElement.selectionEnd = initialSelectionEnd;
}
},
/**
* Searches all the dirty element on the page and saves them one by one. If