diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-03-16 17:08:04 +0100 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2017-03-17 11:44:28 +0100 |
| commit | 7401807510a103374fa8eb524ae5a5698ae21a39 (patch) | |
| tree | 55441db57fd5e63ccac788680d7edc564bcca7f8 /addons/web_editor/static/src | |
| parent | be9dce625c55e1b2d6039573c7035d61f762edc8 (diff) | |
[FIX] web_editor: copy/paste in the editor
Commit 906875fc78cb80f6c3d5f1f14f997008cd406473 (followed by commit
76be5eed449c78eaf0b4208c381169132492ab4a) tried to tweak to copy/paste
functionality of the editor.
Indeed, in PDF file, when copying a paragraph, a line feed is added at
each forced line break (page width end). This forced a line feed and
a new paragraph in the pasted text. The goal was to get rid of those
useless linebreaks when pasting.
The ideal solution would be to detect that the text was copied from
a PDF but it is not possible. However, this commit improves the
heuristic: if this is not plain text, then nothing is done, the content
is pasted normally. If it is plain text (like when copying from pdf),
then each line break which is surrounded by letters or numbers is
considered an useless line break and replaced by a space. This is
obviously not perfect but the previous implementation was really wrong
(it was removing line breaks which were not preceeded by punctuation in
all cases, which was removing lots of useful line breaks).
Note: this commit also fixes a bug -> text was not able to be pasted
with Internet Explorer.
opw-715920
Diffstat (limited to 'addons/web_editor/static/src')
| -rw-r--r-- | addons/web_editor/static/src/js/summernote.js | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js index 9d7304caf75..71647828cc6 100644 --- a/addons/web_editor/static/src/js/summernote.js +++ b/addons/web_editor/static/src/js/summernote.js @@ -2313,11 +2313,19 @@ eventHandler.modules.popover.update = function ($popover, oStyle, isAirMode) { eventHandler.modules.clipboard.attach = function(layoutInfo) { var $editable = layoutInfo.editable(); $editable.on('paste', function(e) { - e.preventDefault(); - $editable.data('NoteHistory').recordUndo($editable); - 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 clipboardData = ((e.originalEvent || e).clipboardData || window.clipboardData); + // Change nothing if pasting html (copy from text editor / web / ...) or + // if clipboardData is not available (IE / ...) + if (clipboardData && clipboardData.types && clipboardData.types.length === 1 && clipboardData.types[0] === "text/plain") { + e.preventDefault(); + $editable.data('NoteHistory').recordUndo($editable); // FIXME + var pastedText = clipboardData.getData("text/plain"); + // Try removing linebreaks which are not really linebreaks (in a PDF, + // when a sentence goes over the next line, copying it considers it + // a linebreak for example). + var formattedText = pastedText.replace(/([\w-])\r?\n([\w-])/g, "$1 $2").trim(); + document.execCommand("insertText", false, formattedText); + } }); }; |
