Text pasting fix
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pulse-signage",
|
"name": "pulse-signage",
|
||||||
"version": "1.1.3",
|
"version": "1.1.5",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "Pulse Signage application with MySQL and media uploads",
|
"description": "Pulse Signage application with MySQL and media uploads",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
BlockQuote,
|
BlockQuote,
|
||||||
Bold,
|
Bold,
|
||||||
ClassicEditor,
|
ClassicEditor,
|
||||||
|
ClipboardPipeline,
|
||||||
Essentials,
|
Essentials,
|
||||||
FontBackgroundColor,
|
FontBackgroundColor,
|
||||||
FontColor,
|
FontColor,
|
||||||
@@ -142,6 +143,26 @@ import {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ForcePlainTextPaste extends Plugin {
|
||||||
|
static get pluginName() {
|
||||||
|
return 'ForcePlainTextPaste';
|
||||||
|
}
|
||||||
|
|
||||||
|
static get requires() {
|
||||||
|
return [ClipboardPipeline];
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
var editor = this.editor;
|
||||||
|
var clipboardPipeline = editor.plugins.get(ClipboardPipeline);
|
||||||
|
|
||||||
|
this.listenTo(clipboardPipeline, 'inputTransformation', function (_event, data) {
|
||||||
|
var plainText = data.dataTransfer.getData('text/plain');
|
||||||
|
data.content = editor.data.processor.toView(plainTextToHtml(plainText));
|
||||||
|
}, { priority: 'high' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function escapeHtml(value) {
|
function escapeHtml(value) {
|
||||||
return String(value ?? '')
|
return String(value ?? '')
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
@@ -151,6 +172,32 @@ import {
|
|||||||
.replace(/'/g, ''');
|
.replace(/'/g, ''');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function plainTextToHtml(value) {
|
||||||
|
var lines = String(value ?? '').replace(/\r\n?/g, '\n').split('\n');
|
||||||
|
var paragraphs = [];
|
||||||
|
var currentParagraph = [];
|
||||||
|
|
||||||
|
lines.forEach(function (line) {
|
||||||
|
if (line === '') {
|
||||||
|
if (currentParagraph.length) {
|
||||||
|
paragraphs.push('<p>' + currentParagraph.join('<br />') + '</p>');
|
||||||
|
currentParagraph = [];
|
||||||
|
} else {
|
||||||
|
paragraphs.push('<p></p>');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentParagraph.push(escapeHtml(line));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (currentParagraph.length) {
|
||||||
|
paragraphs.push('<p>' + currentParagraph.join('<br />') + '</p>');
|
||||||
|
}
|
||||||
|
|
||||||
|
return paragraphs.length ? paragraphs.join('') : '<p></p>';
|
||||||
|
}
|
||||||
|
|
||||||
function getTemplateById(id) {
|
function getTemplateById(id) {
|
||||||
return templates.find(function (item) { return Number(item.id) === Number(id); }) || null;
|
return templates.find(function (item) { return Number(item.id) === Number(id); }) || null;
|
||||||
}
|
}
|
||||||
@@ -608,6 +655,7 @@ import {
|
|||||||
BlockQuote,
|
BlockQuote,
|
||||||
Bold,
|
Bold,
|
||||||
Essentials,
|
Essentials,
|
||||||
|
ForcePlainTextPaste,
|
||||||
FontBackgroundColor,
|
FontBackgroundColor,
|
||||||
FontColor,
|
FontColor,
|
||||||
FontFamily,
|
FontFamily,
|
||||||
|
|||||||
Reference in New Issue
Block a user