diff --git a/core/modules/editor/operations/text/insert-text.js b/core/modules/editor/operations/text/insert-text.js new file mode 100644 index 000000000..784714968 --- /dev/null +++ b/core/modules/editor/operations/text/insert-text.js @@ -0,0 +1,23 @@ +/*\ +title: $:/core/modules/editor/operations/text/insert-text.js +type: application/javascript +module-type: texteditoroperation + +Text editor operation insert text at the caret position. If there is a selection it is replaced. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports["insert-text"] = function(event,operation) { + operation.replacement = event.paramObject.text; + operation.cutStart = operation.selStart; + operation.cutEnd = operation.selEnd; + operation.newSelStart = operation.selStart + operation.replacement.length; + operation.newSelEnd = operation.newSelStart; +}; + +})(); diff --git a/core/ui/EditorToolbar/file-import.tid b/core/ui/EditorToolbar/file-import.tid index 742597102..d8024f3d8 100644 --- a/core/ui/EditorToolbar/file-import.tid +++ b/core/ui/EditorToolbar/file-import.tid @@ -16,7 +16,7 @@ condition: [!has[type]] [type[text/vnd.tiddlywiki] <$list filter="[links[]] :reduce[get[type]prefix[image]thenelsesearch-replace[$title$],addprefix]" variable="imageTitle"> <$action-sendmessage $message="tm-edit-text-operation" - $param="replace-selection" + $param="insert-text" text=<> /> 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 a41207120..ab8d61e6d 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 @@ -1,6 +1,6 @@ caption: tm-edit-text-operation created: 20160424211339792 -modified: 20180630073432471 +modified: 20210520053923011 tags: Messages title: WidgetMessage: tm-edit-text-operation type: text/vnd.tiddlywiki @@ -93,6 +93,27 @@ Saves the text of the current //selection// into the provided <<.param "tiddler" \end +\define makeLinkDescription() +
+ +Creates a wiki text link to the tiddler specified in <<.param "text">>. If there is a selection, it is used as the text of the link. + +|!Name |!Description | +|text |Tiddler title to which the link will be created | + +
+\end + +\define insertTextDescription() +
+ +Inserts the text specified in <<.param "text">> at the caret position. If there is a selection, it is replaced. + +|!Name |!Description | +|text |Text to be inserted | + +
+\end 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: @@ -114,6 +135,8 @@ At this point the following text operations have been implemented: |<<.def "wrap-lines">>|<> | |<<.def "wrap-selection">>|<> | |<<.def "save-selection">>|<> | +|<<.def "make-link">>|<> | +|<<.def "insert-text">>|<>| !Example