From 67cf0e1bb8bfca90c51489f10ae65f33a41e1e82 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 8 Feb 2022 16:16:44 +0100 Subject: [PATCH] Add new wrap action to default RTE --- src/canvas/view/FrameView.js | 4 +-- src/rich_text_editor/config/config.js | 2 +- src/rich_text_editor/model/RichTextEditor.js | 29 +++++++++++++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/canvas/view/FrameView.js b/src/canvas/view/FrameView.js index 00f3774ff..b08ef5abd 100644 --- a/src/canvas/view/FrameView.js +++ b/src/canvas/view/FrameView.js @@ -330,8 +330,8 @@ export default Backbone.View.extend({ } .${ppfx}selected { - outline: 3px solid #3b97e3 !important; - outline-offset: -3px; + outline: 2px solid #3b97e3 !important; + outline-offset: -2px; } .${ppfx}selected-parent { diff --git a/src/rich_text_editor/config/config.js b/src/rich_text_editor/config/config.js index da6a38f84..2c24c3c40 100644 --- a/src/rich_text_editor/config/config.js +++ b/src/rich_text_editor/config/config.js @@ -6,5 +6,5 @@ export default { adjustToolbar: 1, // Default RTE actions - actions: ['bold', 'italic', 'underline', 'strikethrough', 'link'] + actions: ['bold', 'italic', 'underline', 'strikethrough', 'link', 'wrap'], }; diff --git a/src/rich_text_editor/model/RichTextEditor.js b/src/rich_text_editor/model/RichTextEditor.js index bcea64cde..2f83e9836 100644 --- a/src/rich_text_editor/model/RichTextEditor.js +++ b/src/rich_text_editor/model/RichTextEditor.js @@ -43,18 +43,16 @@ const defActions = { result: rte => rte.exec('strikeThrough'), }, link: { - icon: `⫘`, + icon: ` + + `, name: 'link', attributes: { style: 'font-size:1.4rem;padding:0 4px 2px;', title: 'Link', }, - state: (rte, doc) => { - if (rte && rte.selection()) { - return isValidAnchor(rte) ? btnState.ACTIVE : btnState.INACTIVE; - } else { - return btnState.INACTIVE; - } + state: rte => { + return rte && rte.selection() && isValidAnchor(rte) ? btnState.ACTIVE : btnState.INACTIVE; }, result: rte => { if (isValidAnchor(rte)) { @@ -64,6 +62,23 @@ const defActions = { } }, }, + wrap: { + icon: ` + + `, + attributes: { title: 'Wrap for style' }, + result: rte => { + rte.insertHTML(`${rte.selection()}`); + const sel = editor.getSelected(); + sel.once('rte:disable', () => { + const toSel = sel.find('[data-selectme]')[0]; + toSel.removeAttributes('data-selectme'); + toSel.set('selectable', true); + editor.select(toSel); + }); + sel.trigger('disable'); + }, + }, }; export default class RichTextEditor {