I had to step away from the computer so it’s been a while, but I can say I almost made it. I have only one problem though.
Some info: the tiddler is named $:/sob/Btn/EditorToolbar/Excise/Dropdown
, and has a field excision-title
with value:
{{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!radio}}{{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!grab}}
It’s not very elegant I think, but it all works quite well.
\define lingo-base() $:/language/Buttons/Excise/
\define body(config-title)
\whitespace trim
''<<lingo Hint>>''
<style>
.edit-text-width {
width:18em;
border:none;
border-bottom:1px dotted<<colour sidebar-foreground>>;
}
.center{
text-align: center;
}
.emptyspace {
content: " ";
display: block;
border-bottom: 0px solid #000;
margin-top: 1.5em;
margin-bottom: 1.5em;;
}
.frame-A2px {
border: 2px solid <<colour table-header-background>>;
padding: 0.3rem;
}
.new-title-window {
border: 2px solid <<colour table-header-background>>;
padding: 0.3rem;
background: <<colour select-tag-background>>
}
</style>
<div class="hr2"></div>
❯ __Prefix:__
<div class="center">
<$tiddler tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown">
<$radio field="radio" value="" default="$:/sob/"> None</$radio>
<$radio field="radio" value="$:/sob/" default="$:/sob/"> Sobriety</$radio>
</$tiddler>
</div>
❯ __Add suffix:__ <$edit-text focus="yes" class="edit-text-width" tag="input" tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" field="grab" />
<$wikify name=new-title-wikified text={{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!excision-title}}>
<$set name="new-title" value=<<new-title-wikified>>>
<$list filter="""[<new-title>is[tiddler]]""">
<div class="tc-error">
<<lingo Caption/TiddlerExists>>
</div>
</$list>
</$set>
<$list filter="""[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[grab]count[]match[0]]""">
//Insert a suffix//
</$list>
</$wikify>
<$wikify name=new-title-wikified text={{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!excision-title}}>
<div class="new-title-window">
<$text name=text-new-name text=<<new-title-wikified>>>
<text src=<<text-new-name>>/>
</$text></div>
</$wikify>
<$checkbox tiddler="""$config-title$/tagnew""" field="text" checked="yes" unchecked="no" default="false"> Tag new tiddler with the title of this tiddler</$checkbox>
<div class="frame-A2px">
''❯'' Replace with: <$select tiddler="""$config-title$/type""" default="transclude">
<option value="link"><<lingo Caption/Replace/Link>></option>
<option value="transclude"><<lingo Caption/Replace/Transclusion>></option>
<option value="TranscludeWidgetBlock">$transclude-block</option>
<option value="TranscludeWidgetSpan">$transclude-span</option>
</$select>
<div class="emptyspace "></div>
<$checkbox tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" field="link+on" checked="on" unchecked="off" default="off"> Add a link "+"</$checkbox>
<div class="emptyspace "></div>
<$list filter="""[<new-title>is[tiddler]] [[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[grab]count[]match[0]]""">
<$button disabled>
~~<<lingo Caption/Excise>>~~
</$button>
</$list>
<$wikify name=new-title-wikified text={{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!excision-title}}>
<$list filter="""[<new-title>!is[tiddler][$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[grab]count[]!match[0]]""">
<$button>
<$action-sendmessage
$message="tm-edit-text-operation"
$param="excise"
title=<<new-title-wikified>>
type={{$config-title$/type}}
macro={{$config-title$/macro-title}}
tagnew={{$config-title$/tagnew}}
/>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[link+on]] +[match[on]]">
<$action-sendmessage
$message="tm-edit-text-operation"
$param="wrap-selection"
prefix=""
suffix="HERE"
/></$list>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[radio]] +[match[$:/sob/]]">
<$action-listops $tiddler="<<new-title-wikified>>" $tags="$:/sobriety"
/></$list>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="grab" $value=""
/>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="radio" $value="$:/sob/"
/>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="link+on" $value="off"
/>
<$action-navigate $to=<<new-title-wikified>>
/>
<<lingo Caption/Excise>>
</$button>
</$list>
</$wikify>
</div>
\end
<$macrocall $name="body" config-title=<<qualify "$:/state/Excise/">>/>
Illustrative image:
(not shown here, if a tiddler with the same name as the one entered already exists or nothing is entered in the $edit-text, the button “Perform excision” is not shown, in its place a button disabled with strikethrough text formatting)

One thing I learned:
After the “operation.replacement” made by the js if you want to add some text after the replacement you can still do that with an $action-sendmessage $message="tm-edit-text-operation"
but not with $param="insert-text"
as I was tempted to do (and how I did it initially) because it works on the selection and it conflicted with what the js did.
So I used as parameter of the “tm-edit-text-operation” message $param="wrap-selection"
since it does not act on the selection but around it. I then left the prefix blank and entered just the suffix.
- A way to add tags to the newly created tiddler if a checkbox is checked. I know both how to make it activate only if the checkbox is checked (i.e. with a filter in a $list) and also I know also which tiddler to point to (using the wikified field
excision-title
)
The problem lies (I think) in the $action. But that’s all I know.
I started with $action-setfield
(I’m now using $action-listops
) but I think it was worse, because it overridden any tag given by the default function of the excise button “Tag new tiddler with the title of this tiddler”
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[radio]] +[match[$:/sob/]]">
<$action-listops $tiddler="<<new-title-wikified>>" $tags="$:/sobriety"
/></$list>
- The other thing I’m missing is how to get the suffix content I talked about earlier to be something like this:
[[+| <<new-title-wikified>>]]
Here <<new-title-wikified>>
would be the title of the tiddler just created.
Only since this has to be wrapped in " "
for the suffix definition, I don’t know how to make <<new-title-wikified>>
not interpreted literally.
Here I’m thinking of playing around with $wikify and $text like I already did to show the title of the tiddler which will be created as plain text (even if it starts with $:/… and would like to be shown as a link). Maybe if I’m in luck I can do it myself.
If anyone likes this and wants to copy it, I remind that $:/core/modules/editor/operations/text/excise.js has been modified to be able to transclude with $tranclude widget.
-If anyone wants them here are the Jsons:
$ _core_modules_editor_operations_text_excise.js.json (2.0 KB)
$ _sob_Btn_EditorToolbar_Excise.json (343 Bytes)
$ _sob_Btn_EditorToolbar_Excise_Dropdown.json (4.6 KB)
(Js code:)
/*\
title: $:/core/modules/editor/operations/text/excise.js
type: application/javascript
module-type: texteditoroperation
Text editor operation to excise the selection to a new tiddler
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports["excise"] = function(event,operation) {
var editTiddler = this.wiki.getTiddler(this.editTitle),
editTiddlerTitle = this.editTitle;
if(editTiddler && editTiddler.fields["draft.of"]) {
editTiddlerTitle = editTiddler.fields["draft.of"];
}
var excisionTitle = event.paramObject.title || this.wiki.generateNewTitle("New Excision");
this.wiki.addTiddler(new $tw.Tiddler(
this.wiki.getCreationFields(),
this.wiki.getModificationFields(),
{
title: excisionTitle,
text: operation.selection,
tags: event.paramObject.tagnew === "yes" ? [editTiddlerTitle] : []
}
));
operation.replacement = excisionTitle;
switch(event.paramObject.type || "transclude") {
case "transclude":
operation.replacement = "{{" + operation.replacement+ "}}";
break;
case "TranscludeWidgetBlock":
operation.replacement = '<$transclude tiddler="' + operation.replacement+ '" mode="block"/>';
break;
case "TranscludeWidgetSpan":
operation.replacement = '<$transclude tiddler="' + operation.replacement+ '" mode="span"/>';
break;
case "link":
operation.replacement = "[[" + operation.replacement+ "]]";
break;
}
operation.cutStart = operation.selStart;
operation.cutEnd = operation.selEnd;
operation.newSelStart = operation.selStart;
operation.newSelEnd = operation.selStart + operation.replacement.length;
};
})();