From 0269f5122e114203586d6fbb1e795e2421fb679b Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 15 Oct 2022 15:47:34 +0100 Subject: [PATCH] Added wysiwyg code block edit tooltip For easier editing access on mobile devices where previous doubleclick does not work so well. For #2815 --- resources/js/wysiwyg/plugin-codeeditor.js | 17 +++++++++++++++++ resources/lang/en/editor.php | 1 + 2 files changed, 18 insertions(+) diff --git a/resources/js/wysiwyg/plugin-codeeditor.js b/resources/js/wysiwyg/plugin-codeeditor.js index 5377f564e..66441c87e 100644 --- a/resources/js/wysiwyg/plugin-codeeditor.js +++ b/resources/js/wysiwyg/plugin-codeeditor.js @@ -153,6 +153,14 @@ function register(editor, url) { } }); + editor.ui.registry.addButton('editcodeeditor', { + tooltip: 'Edit code block', + icon: 'edit-block', + onAction() { + editor.execCommand('codeeditor'); + } + }); + editor.addCommand('codeeditor', () => { const selectedNode = editor.selection.getNode(); const doc = selectedNode.ownerDocument; @@ -208,6 +216,15 @@ function register(editor, url) { }); }); + editor.ui.registry.addContextToolbar('codeeditor', { + predicate: function (node) { + return node.nodeName.toLowerCase() === 'code-block'; + }, + items: 'editcodeeditor', + position: 'node', + scope: 'node' + }); + editor.on('PreInit', () => { defineCodeBlockCustomElement(editor); }); diff --git a/resources/lang/en/editor.php b/resources/lang/en/editor.php index da7ffcf01..faf351da2 100644 --- a/resources/lang/en/editor.php +++ b/resources/lang/en/editor.php @@ -66,6 +66,7 @@ return [ 'insert_link_title' => 'Insert/Edit Link', 'insert_horizontal_line' => 'Insert horizontal line', 'insert_code_block' => 'Insert code block', + 'edit_code_block' => 'Edit code block', 'insert_drawing' => 'Insert/edit drawing', 'drawing_manager' => 'Drawing manager', 'insert_media' => 'Insert/edit media',