summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2018-01-23 16:16:20 +0100
committerqsm-odoo <qsm@odoo.com>2018-01-25 12:44:36 +0100
commit2fad2e43b855e728f0534012012ec3720035768c (patch)
tree979d0051641b61120bea60e211918b50f87ab9f0 /addons/web_editor/static/src/js
parent78a556601e6b1e72c6d1ac776e31588dd2ffa28f (diff)
[FIX] web_editor: solve all triple-click issues
... hopefully. This *must* be forward-ported. Depending on the browser, the triple-click behavior is different. This is especially problematic on Chrome, where blank characters at the start of the neighbor of the clicked element are selected. A weak attempt to solve that was made by commit https://github.com/odoo/odoo/commit/b85bd358234684974f9af63bc5f28cfabb527767 This commit hopes to solve all the issues once and for all by fully reimplementing the triple-click for all browsers. The concept is simple: when a triple-click occurs, select the whole *inner* content of the deepest DOM *element* that was clicked.
Diffstat (limited to 'addons/web_editor/static/src/js')
-rw-r--r--addons/web_editor/static/src/js/rte.js34
1 files changed, 12 insertions, 22 deletions
diff --git a/addons/web_editor/static/src/js/rte.js b/addons/web_editor/static/src/js/rte.js
index 7748ccf7762..adbc7d4bd49 100644
--- a/addons/web_editor/static/src/js/rte.js
+++ b/addons/web_editor/static/src/js/rte.js
@@ -583,8 +583,8 @@ var RTE = Widget.extend({
onEnableEditableArea: function ($editable) {
},
- onMouseup: function (event) {
- var $target = $(event.target);
+ onMouseup: function (ev) {
+ var $target = $(ev.target);
var $editable = $target.closest('.o_editable');
if (!$editable.size()) {
@@ -596,26 +596,16 @@ var RTE = Widget.extend({
self.historyRecordUndo($target, 'activate', true);
},0);
- // To Fix Google Chrome Tripleclick Issue, which selects the ending
- // whitespace characters (so Tripleclicking then typing text will remove
- // the whole paragraph instead of its content).
- // http://stackoverflow.com/questions/38467334/why-does-google-chrome-always-add-space-after-selected-text
- if ($.browser.chrome === true && event.originalEvent.detail === 3) {
- var currentSelection = range.create();
- if (currentSelection.sc.parentNode === currentSelection.ec) {
- _selectSC(currentSelection);
- } else if (currentSelection.eo === 0) {
- var $hasNext = $(currentSelection.sc).parent();
- while (!$hasNext.next().length && !$hasNext.is('body')) {
- $hasNext = $hasNext.parent();
- }
- if ($hasNext.next()[0] === currentSelection.ec) {
- _selectSC(currentSelection);
- }
- }
- }
- function _selectSC(selection) {
- range.create(selection.sc, selection.so, selection.sc, selection.sc.length).select();
+ // Browsers select different content from one to another after a
+ // triple click (especially: if triple-clicking on a paragraph on
+ // Chrome, blank characters of the element following the paragraph are
+ // selected too)
+ //
+ // The triple click behavior is reimplemented for all browsers here
+ if (ev.originalEvent.detail === 3) {
+ // Select the whole content inside the deepest DOM element that was
+ // triple-clicked
+ range.create(ev.target, 0, ev.target, ev.target.childNodes.length).select();
}
},