From f1097a823033e341030f697b7572c40b53477829 Mon Sep 17 00:00:00 2001 From: jonathan68 Date: Sun, 18 Feb 2018 13:27:29 +1000 Subject: [PATCH 1/6] Add ability to set font family --- RichEditorView/Assets/editor/rich_editor.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/RichEditorView/Assets/editor/rich_editor.js b/RichEditorView/Assets/editor/rich_editor.js index 6fc55d4e..635c3a75 100644 --- a/RichEditorView/Assets/editor/rich_editor.js +++ b/RichEditorView/Assets/editor/rich_editor.js @@ -134,7 +134,17 @@ RE.removeFormat = function() { }; RE.setFontSize = function(size) { - RE.editor.style.fontSize = size; + RE.restorerange(); + document.execCommand("styleWithCSS", null, true); + document.execCommand('fontSize', false, size); + document.execCommand("styleWithCSS", null, false); +}; + +RE.setFontFamily = function(font) { + RE.restorerange(); + document.execCommand("styleWithCSS", null, true); + document.execCommand('fontName', false, font); + document.execCommand("styleWithCSS", null, false); }; RE.setBackgroundColor = function(color) { From 3a8f4fb7577df4fbe9662751a9bab670cd5b3c95 Mon Sep 17 00:00:00 2001 From: jonathan68 Date: Sun, 18 Feb 2018 13:31:43 +1000 Subject: [PATCH 2/6] Add swift function to set font family --- RichEditorView/Classes/RichEditorView.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RichEditorView/Classes/RichEditorView.swift b/RichEditorView/Classes/RichEditorView.swift index e25e2a6c..0a578ae1 100644 --- a/RichEditorView/Classes/RichEditorView.swift +++ b/RichEditorView/Classes/RichEditorView.swift @@ -233,6 +233,10 @@ import UIKit runJS("RE.setFontSize('\(size)px');") } + public func setFontFamily(_ font: String) { + runJS("RE.setFontFamily('\(font)');") + } + public func setEditorBackgroundColor(_ color: UIColor) { runJS("RE.setBackgroundColor('\(color.hex)');") } From 0b9c4ab78a9aa24ab497203be68e96835bf04a55 Mon Sep 17 00:00:00 2001 From: jonathan68 Date: Mon, 19 Feb 2018 12:09:41 +1000 Subject: [PATCH 3/6] Revert setFontSize function that blocks heading --- RichEditorView/Assets/editor/rich_editor.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/RichEditorView/Assets/editor/rich_editor.js b/RichEditorView/Assets/editor/rich_editor.js index 635c3a75..df252dc1 100644 --- a/RichEditorView/Assets/editor/rich_editor.js +++ b/RichEditorView/Assets/editor/rich_editor.js @@ -134,10 +134,7 @@ RE.removeFormat = function() { }; RE.setFontSize = function(size) { - RE.restorerange(); - document.execCommand("styleWithCSS", null, true); - document.execCommand('fontSize', false, size); - document.execCommand("styleWithCSS", null, false); + RE.editor.style.fontSize = size; }; RE.setFontFamily = function(font) { From d859c09b474083476f264776b0572024d0bc9b0e Mon Sep 17 00:00:00 2001 From: wagng Date: Tue, 1 May 2018 04:00:52 +1000 Subject: [PATCH 4/6] Apply padding to text view --- RichEditorView/Assets/editor/style.css | 1 + 1 file changed, 1 insertion(+) diff --git a/RichEditorView/Assets/editor/style.css b/RichEditorView/Assets/editor/style.css index f7484847..de027f54 100644 --- a/RichEditorView/Assets/editor/style.css +++ b/RichEditorView/Assets/editor/style.css @@ -23,6 +23,7 @@ html { body { min-height: 100%; overflow: auto; + padding: 20px; } body, h1, p { From 623db0c8434ead2ddd6fce671f2e4117a0e9f2ed Mon Sep 17 00:00:00 2001 From: moblaunch Date: Sat, 22 Sep 2018 08:56:50 +1000 Subject: [PATCH 5/6] Update padding size --- RichEditorView/Assets/editor/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RichEditorView/Assets/editor/style.css b/RichEditorView/Assets/editor/style.css index de027f54..92f1d679 100644 --- a/RichEditorView/Assets/editor/style.css +++ b/RichEditorView/Assets/editor/style.css @@ -23,7 +23,7 @@ html { body { min-height: 100%; overflow: auto; - padding: 20px; + padding: 10px; } body, h1, p { From 40d7a0fe1576f1083adef5ad46ed10b5eb000e36 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 9 Oct 2018 21:55:03 +0300 Subject: [PATCH 6/6] ormatting to 'p' because removeFormat cannot deal with headers --- RichEditorView/Assets/editor/rich_editor.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RichEditorView/Assets/editor/rich_editor.js b/RichEditorView/Assets/editor/rich_editor.js index df252dc1..a526414f 100644 --- a/RichEditorView/Assets/editor/rich_editor.js +++ b/RichEditorView/Assets/editor/rich_editor.js @@ -130,6 +130,10 @@ RE.updatePlaceholder = function() { }; RE.removeFormat = function() { + // https://stackoverflow.com/a/52137754/4514671 + // https://stackoverflow.com/questions/14028773/javascript-execcommandremoveformat-doesnt-strip-h2-tag + // formatting to 'p' because removeFormat cannot deal with headers (h1, h2, ...) + document.execCommand('formatBlock', false, 'p'); document.execCommand('removeFormat', false, null); };