diff src/sceditor.js @ 46:ab2dc8736d88

fix paste html and cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 30 Aug 2022 14:33:27 -0600
parents bc1bce78276d
children
line wrap: on
line diff
--- a/src/sceditor.js	Tue Aug 30 02:03:50 2022 -0600
+++ b/src/sceditor.js	Tue Aug 30 14:33:27 2022 -0600
@@ -2595,7 +2595,7 @@
 					perLine = Math.sqrt(Object.keys(emoticons).length);
 
 					onEvent1(content, 'click', 'img', function (target, e) {
-						editor.insert(targetToHtml(target), null, false);
+						editor.insert(targetToHtml(target));
 						editor.closeDropDown(true);
 
 						e.preventDefault();
@@ -4763,7 +4763,7 @@
 					}
 
 					let shortcut = command.shortcut;
-					let icon = command.icon || '';
+					let icon = command.icon || '&nbsp;'+commandName+'&nbsp;';
 					let button = '<button>' + icon + '</button>';
 					button = parseHTML(button).firstChild;
 					button._sceTxtMode = !!command.txtExec;
@@ -5590,21 +5590,26 @@
 				pasteArea.innerHTML = entities(data.text || '');
 			}
 
-			var paste = {
+			let paste = {
 				val: pasteArea.innerHTML
 			};
 
-			if ('fragmentToSource' in format) {
+			if ('toSource' in format) {
 				paste.val = format
-					.fragmentToSource(paste.val, wysiwygDocument, currentNode);
+					.toSource(paste.val, wysiwygDocument, currentNode, true);
 			}
 
 			pluginManager.call('paste', paste);
 			trigger(editorContainer, 'paste', paste);
 
+			if ('toHtml' in format) {
+				paste.val = format
+					.toHtml(paste.val, currentNode, true);
+			}
+
 			pluginManager.call('pasteHtml', paste);
 
-			var parent = rangeHelper.getFirstBlockParent();
+			let parent = rangeHelper.getFirstBlockParent();
 			base.wysiwygEditorInsertHtml(paste.val, null, true);
 			merge(parent);
 		};
@@ -5897,15 +5902,13 @@
 		 *
 		 * @param {string} start
 		 * @param {string} [end=null]
-		 * @param {boolean} [filter=true]
-		 * @param {boolean} [allowMixed=false]
 		 * @since 1.4.3
 		 * @function
 		 * @name insert^2
 		 */
 		// eslint-disable-next-line max-params
 		base.insert = function (
-			start, end, filter, allowMixed
+			start, end
 		) {
 			if (base.inSourceMode()) {
 				base.sourceEditorInsertText(start, end);
@@ -5914,23 +5917,10 @@
 
 			// Add the selection between start and end
 			if (end) {
-				var	html = rangeHelper.selectedHtml();
-
-				if (filter !== false && 'fragmentToSource' in format) {
-					html = format
-						.fragmentToSource(html, wysiwygDocument, currentNode);
-				}
-
+				let	html = rangeHelper.selectedHtml();
 				start += html + end;
 			}
 
-			// Convert any escaped HTML back into HTML if mixed is allowed
-			if (filter !== false && allowMixed === true) {
-				start = start.replace(/&lt;/g, '<')
-					.replace(/&gt;/g, '>')
-					.replace(/&amp;/g, '&');
-			}
-
 			base.wysiwygEditorInsertHtml(start);
 		};