From d695fca30166f51b57f0ec8cead3e752ddb21cc1 Mon Sep 17 00:00:00 2001 From: Simon Huber Date: Wed, 27 Oct 2021 12:37:40 +0200 Subject: [PATCH] Add `focus-editor` text operation and use it where sensible (#6012) * add and use focus-editor text operation * add docs --- .../editor/operations/text/focus-editor.js | 17 +++++++++++++++++ core/ui/EditorToolbar/link-dropdown.tid | 2 +- .../WidgetMessage_ tm-edit-text-operation.tid | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 core/modules/editor/operations/text/focus-editor.js diff --git a/core/modules/editor/operations/text/focus-editor.js b/core/modules/editor/operations/text/focus-editor.js new file mode 100644 index 000000000..0b36f731c --- /dev/null +++ b/core/modules/editor/operations/text/focus-editor.js @@ -0,0 +1,17 @@ +/*\ +title: $:/core/modules/editor/operations/text/focus-editor.js +type: application/javascript +module-type: texteditoroperation +Simply focus the Text editor +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports["focus-editor"] = function(event,operation) { + operation = null; +}; + +})(); \ No newline at end of file diff --git a/core/ui/EditorToolbar/link-dropdown.tid b/core/ui/EditorToolbar/link-dropdown.tid index 96dd99b2a..eacb17547 100644 --- a/core/ui/EditorToolbar/link-dropdown.tid +++ b/core/ui/EditorToolbar/link-dropdown.tid @@ -13,7 +13,7 @@ title: $:/core/ui/EditorToolbar/link-dropdown <$set name="userInput" value={{{ [get[text]] }}}><$list filter="[get[text]!match]" emptyMessage="""<$action-deletetiddler $filter="[] [] [] []"/>"""><$action-setfield $tiddler=<> text=<>/><$action-setfield $tiddler=<> text="yes"/> \end -\define cancel-search-actions() <$list filter="[!has[text]] +[!has[text]]" emptyMessage="""<>"""><$action-sendmessage $message="tm-edit-text-operation" $param="wrap-selection" prefix="" suffix=""/> +\define cancel-search-actions() <$list filter="[!has[text]] +[!has[text]]" emptyMessage="""<>"""><$action-sendmessage $message="tm-edit-text-operation" $param="focus-editor"/> \define external-link() <$button class="tc-btn-invisible" style="width: auto; display: inline-block; background-colour: inherit;" actions=<>> diff --git a/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-edit-text-operation.tid b/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-edit-text-operation.tid index ab8d61e6d..8788ceac0 100644 --- a/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-edit-text-operation.tid +++ b/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-edit-text-operation.tid @@ -115,6 +115,8 @@ Inserts the text specified in <<.param "text">> at the caret position. If there \end +\define focusEditorDescription() Simply focuses the Text Editor + A `tm-edit-text-operation` invokes one of the available operations on a __surrounding__ text editor. Therefore the message has to be dispatched within the editor in order for it to catch it. The following properties on the `event` object are required: |!Name |!Description | @@ -137,6 +139,7 @@ At this point the following text operations have been implemented: |<<.def "save-selection">>|<> | |<<.def "make-link">>|<> | |<<.def "insert-text">>|<>| +|<<.def "focus-editor">>|<<.from-version 5.2.0>> <> | !Example