From b35165e257ed5412e157159cafe2899cc79e8860 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 5 Oct 2018 11:46:41 +0530 Subject: [PATCH 1/2] fix(Text Editor): Set div as the default block --- frappe/public/js/frappe/form/controls/text_editor.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frappe/public/js/frappe/form/controls/text_editor.js b/frappe/public/js/frappe/form/controls/text_editor.js index 05a7301ac4..72085b3b6f 100644 --- a/frappe/public/js/frappe/form/controls/text_editor.js +++ b/frappe/public/js/frappe/form/controls/text_editor.js @@ -3,6 +3,11 @@ import { ImageDrop } from 'quill-image-drop-module'; Quill.register('modules/imageDrop', ImageDrop); +// replace

tag with

+const Block = Quill.import('blots/block'); +Block.tagName = 'DIV'; +Quill.register(Block, true); + frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({ make_input() { this.has_input = true; From 9b6851c9705104e33b1c34b1fdc406d2d0d1bad4 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 5 Oct 2018 12:46:55 +0530 Subject: [PATCH 2/2] fix(Text Editor): Treat values set from api as non dirty --- .../js/frappe/form/controls/text_editor.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/frappe/public/js/frappe/form/controls/text_editor.js b/frappe/public/js/frappe/form/controls/text_editor.js index 72085b3b6f..cba40706b1 100644 --- a/frappe/public/js/frappe/form/controls/text_editor.js +++ b/frappe/public/js/frappe/form/controls/text_editor.js @@ -22,10 +22,10 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({ }, bind_events() { - this.quill.on('text-change', frappe.utils.debounce(() => { - const input_value = this.get_input_value(); - if (this.value === input_value) return; + this.quill.on('text-change', frappe.utils.debounce((delta, oldDelta, source) => { + if (!this.is_quill_dirty(source)) return; + const input_value = this.get_input_value(); this.parse_validate_and_set_in_model(input_value); }, 300)); @@ -65,6 +65,12 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({ }); }, + is_quill_dirty(source) { + if (source === 'api') return false; + let input_value = this.get_input_value(); + return this.value !== input_value; + }, + get_quill_options() { return { modules: { @@ -96,9 +102,10 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({ }, set_formatted_input(value) { - if (!this.quill) return; + if (!(this.quill && value)) return; if (value === this.get_input_value()) return; - this.quill.setContents(this.quill.clipboard.convert(value)); + this.quill.setText(''); + this.quill.clipboard.dangerouslyPasteHTML(0, value); }, get_input_value() {