summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/summernote.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2016-06-02 15:38:19 +0200
committerqsm-odoo <qsm@odoo.com>2016-07-04 17:23:59 +0200
commit906875fc78cb80f6c3d5f1f14f997008cd406473 (patch)
treed45dbfcd22f6c6b4b9e490dce1e7c21795d530ec /addons/web_editor/static/src/js/summernote.js
parent62fb1bb92493b00bd45ed3f4eced5ca8b23f81d6 (diff)
[IMP] web_editor: user text copy/paste
Users copy/past text from various king of document into the editor. These texts contain useless line breaks that should be removed before pasting. Also, the editor currently add a paragraph element between each line. To correct this behaviour the onPaste callback of the summernote lib is used. However for some reason, this is triggered after the text is pasted (we should update and refactor the lib in a better way). So this commit uses a hack: undo the past thanks to the undo command then paste the formatted text we want.
Diffstat (limited to 'addons/web_editor/static/src/js/summernote.js')
-rw-r--r--addons/web_editor/static/src/js/summernote.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js
index 6fbfc69c234..6e52936cc27 100644
--- a/addons/web_editor/static/src/js/summernote.js
+++ b/addons/web_editor/static/src/js/summernote.js
@@ -2302,6 +2302,15 @@ eventHandler.modules.popover.update = function ($popover, oStyle, isAirMode) {
}
};
+options.onPaste = function (e) {
+ e.preventDefault(); // FIXME this does not work with our custom out-dated summernote.
+ document.execCommand("undo"); // FIXME ... so use this hack until we decide to do something about it.
+
+ var pastedText = ((e.originalEvent || e).clipboardData || window.clipboardData).getData('Text');
+ var formattedText = pastedText.replace(/([^.!?:;])\r?\n/g, "$1").trim(); // Remove linebreaks which are not at the end of a sentence
+ document.execCommand("insertText", false, formattedText);
+};
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////
var fn_attach = eventHandler.attach;