From 92588032c4f124f822b6beece9ac520a38931483 Mon Sep 17 00:00:00 2001
From: "Nasreddin Boulif (bon)" <bon@odoo.com>
Date: Mon, 18 Oct 2021 15:56:54 +0000
Subject: [PATCH] [FIX] web_editor: Focus on composer if no anchor selected

Steps to reproduce:

  - Go to any chatter
  - Click on "Send message"
  - Open the Full Composer
  - Click directly on the "Link" button of the composer
  - Add label and url then save

Issue:

  Link not added to composer.

Solution:

  Restore the "old range" only when selection is cancelled by focus.

Related fixes:
https://github.com/odoo/odoo/commit/da14e4449e5e318eb72e1b9f268fb797adb0c6a6
https://github.com/odoo/odoo/commit/d2f3c9e7975188753fa17c06db3fc5c73c773944

opw-2544149

closes odoo/odoo#78583

Signed-off-by: Nasreddin Boulif (bon) <bon@odoo.com>
---
 .../static/lib/summernote/src/js/module/Editor.js           | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Editor.js b/addons/web_editor/static/lib/summernote/src/js/module/Editor.js
index 40b7c95e98d2..9028ba12db1b 100644
--- a/addons/web_editor/static/lib/summernote/src/js/module/Editor.js
+++ b/addons/web_editor/static/lib/summernote/src/js/module/Editor.js
@@ -696,8 +696,10 @@ define([
       // ODOO MODIFICATION START
       if (currentSelection && document.getSelection) {
         selection = document.getSelection();
-        selection.removeAllRanges();
-        selection.addRange(currentSelection);
+        if (!selection || selection.rangeCount === 0) {
+          selection.removeAllRanges();
+          selection.addRange(currentSelection);
+        }
       }
       // ODOO MODIFICATION END
 
-- 
GitLab