How can I get the title of the tiddler created after an excision?

I’m rewriting the topic for clarity, I’ve removed superfluous information.

In a nutshell I’m creating an alternative version of the excise EditorToolbar button.
I’m at a good place and I would also know how to continue, except that I don’t know how I can get the title of the tiddler just created.

I would need this, for example to be able to add some actions to the “Perform excision” button, for example:

<$action-navigate $to=???/>

To open automatically the tiddler just created. (Once I know how to write the tiddler name I could do other things too, this is just the simplest example.)


• It might be useful:

  1. As Mark_S suggests, “excisionTitle” can be found in the js, but I don’t know if it’s usable in the tiddler where I define the excise dropdown (or rather, maybe it’s usable but I couldn’t)

  2. The code of the dropdown and of the js ($:/core/modules/editor/operations/text/excise.js):

Code of the dropdown
\define lingo-base() $:/language/Buttons/Excise/

\define body(config-title)
\whitespace trim
''<<lingo Hint>>''

<style>
.EditText-width {
  width:17em;
}
</style>
<hr>
<$tiddler tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown">
<$radio field="radio" value="" default="$:/sob/">&thinsp;None</$radio>&nbsp;
<$radio field="radio" value="$:/sob/" default="$:/sob/">&thinsp;Sobriety</$radio>&nbsp;
</$tiddler>

''&#x276F;''&thinsp;<<lingo Caption/NewTitle>>&#32;<$edit-text focus="yes" focusSelectFromStart="20" class="s EditText-width" tag="input" tiddler="$config-title$/new-title" default={{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!radio}}/>

<$set name="new-title" value={{$config-title$/new-title}}>
<$list filter="""[<new-title>is[tiddler]]""">
<div class="tc-error">
<<lingo Caption/TiddlerExists>>
</div>
</$list>
</$set>

<$checkbox tiddler="""$config-title$/tagnew""" field="text" checked="yes" unchecked="no" default="false">&#32;<<lingo Caption/Tag>></$checkbox>

<$checkbox tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" field="icon+on" checked="on" unchecked="off" default="false">&#32;{{$:/core/images/link}}Add link "+"</$checkbox>

<hr>
''&#x276F;''&thinsp;<<lingo Caption/Replace>>&#32;<$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>
<option value="macro"><<lingo Caption/Replace/Macro>></option>
</$select>

<$reveal state="""$config-title$/type""" type="match" text="macro">
<<lingo Caption/MacroName>>&#32;<$edit-text tag="input" tiddler="""$config-title$/macro-title""" default="translink"/>
</$reveal>

<$button>
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="excise"
	title={{$config-title$/new-title}}
	type={{$config-title$/type}}
	macro={{$config-title$/macro-title}}
	tagnew={{$config-title$/tagnew}}
/>
<$action-deletetiddler
	$tiddler="$config-title$/new-title"
/>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="radio" $value="$:/sob/"
/>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[icon+on]] +[match[on]]">
<!-- TO INSERT AFTER THE TRANSCLUSION A LINK TO THE TRANSCLUDED TIDDLER IF A CHECKBOX IS CHEKED -->
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="insert-text"
	text=NAME???
/></$list>
<!-- TO NAVIGATE TO THE NEWLY CREATED TIDDLER -->
<$action-navigate $to=NAME???
/>
<<lingo Caption/Excise>>
</$button>
\end

<$macrocall $name="body" config-title=<<qualify "$:/state/Excise/">>/>


Modified code of $:/core/modules/editor/operations/text/excise.js
/*\
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;
		case "macro":
			operation.replacement = "<<" + (event.paramObject.macro || "translink") + " \"\"\"" + operation.replacement + "\"\"\">>";
			break;
	}
	operation.cutStart = operation.selStart;
	operation.cutEnd = operation.selEnd;
	operation.newSelStart = operation.selStart;
	operation.newSelEnd = operation.selStart + operation.replacement.length;
};

})();


Old post

Hi, I’m working on an alternate version of the excise button that’s in the EditorToolbar, and I’m adding these features:

  1. The possibility to choose a prefix with a radio to add to the title of the tiddler that will be created following the excise action with a small change to the $edit-text widget.

  2. A checkbox that allows to insert after the excise a link that leads to the new tiddler you just created

  3. Depending on the value of the $radio, insert a tag to the new tiddler created

  4. The ability to replace excised text also with the $transclude widget (in span or block mode)

  5. And finally, when the tiddler is created, put it into focus

I’ve managed to do almost everything I wanted, but I’m stuck on a small detail.


  • To better understand the situation, I’ll explain what I did: (Scroll down if you want to see the code)

In the dropdown of the EditorToolbar button:

First of all, using $radio widgets, set as the value of the “radio” field what will be the prefixes of the tiddler in which the selected text will be transported (either no prefix or my custom prefix “$:/sob/”) This field will be used also to give the custom tag to the tiddler as listed in point 3 (since the suffix is ​​the same as the tag)

Then I transclude the value of this “radio” field as the default value of the $edit-text widget so to give to the new tiddler the prefix I want

I add a couple of new options for the “Replace excised text with” feature: ($Transclude mode-block and $transclude mode-span). To do this I edit the tiddler $:/core/modules/editor/operations/text/excise.js


  • I would also know how to continue, except that I don’t know how to write/get the title of the new tiddler that will be created.

If I knew it, then inserting the link would be easy (as written in point 2): An $action-sendmessage wrapped in a $list widget, which is activated based on the filter contained in the $list (and therefore based on the checkbox)
-The same goes for putting it into focus (5), a simple $action-navigate $to… But to what, idk sadly.

And, I’m not sure, but I could give the tag (like in point 3) which is equal to the value of the “radio” field with an $action-setfield, but again I don’t know how to point to the new tiddler.

So how do I write/get the name of tiddler where the excised text will go?

or (probably better wording): How can I get the title of tiddler after running the js?

Code of the dropdown
\define lingo-base() $:/language/Buttons/Excise/

\define body(config-title)
\whitespace trim
''<<lingo Hint>>''

<style>
.EditText-width {
  width:17em;
}
</style>
<hr>
<$tiddler tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown">
<$radio field="radio" value="" default="$:/sob/">&thinsp;None</$radio>&nbsp;
<$radio field="radio" value="$:/sob/" default="$:/sob/">&thinsp;Sobriety</$radio>&nbsp;
</$tiddler>

''&#x276F;''&thinsp;<<lingo Caption/NewTitle>>&#32;<$edit-text focus="yes" focusSelectFromStart="20" class="s EditText-width" tag="input" tiddler="$config-title$/new-title" default={{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!radio}}/>

<$set name="new-title" value={{$config-title$/new-title}}>
<$list filter="""[<new-title>is[tiddler]]""">
<div class="tc-error">
<<lingo Caption/TiddlerExists>>
</div>
</$list>
</$set>

<$checkbox tiddler="""$config-title$/tagnew""" field="text" checked="yes" unchecked="no" default="false">&#32;<<lingo Caption/Tag>></$checkbox>

<$checkbox tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" field="icon+on" checked="on" unchecked="off" default="false">&#32;{{$:/core/images/link}}Add link "+"</$checkbox>

<hr>
''&#x276F;''&thinsp;<<lingo Caption/Replace>>&#32;<$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>
<option value="macro"><<lingo Caption/Replace/Macro>></option>
</$select>

<$reveal state="""$config-title$/type""" type="match" text="macro">
<<lingo Caption/MacroName>>&#32;<$edit-text tag="input" tiddler="""$config-title$/macro-title""" default="translink"/>
</$reveal>

<$button>
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="excise"
	title={{$config-title$/new-title}}
	type={{$config-title$/type}}
	macro={{$config-title$/macro-title}}
	tagnew={{$config-title$/tagnew}}
tagradio={{$config-title$/tagradio}}
/>
<$action-deletetiddler
	$tiddler="$config-title$/new-title"
/>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="radio" $value="$:/sob/"
/>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[icon+on]] +[match[on]]">
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="insert-text"
	text=""[[+|NAME]]""
/></$list>
<$action-navigate $to="$:/ControlPanel"
/>
<<lingo Caption/Excise>>
</$button>
\end

<$macrocall $name="body" config-title=<<qualify "$:/state/Excise/">>/>


Modified code of $:/core/modules/editor/operations/text/excise.js
/*\
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;
		case "macro":
			operation.replacement = "<<" + (event.paramObject.macro || "translink") + " \"\"\"" + operation.replacement + "\"\"\">>";
			break;
	}
	operation.cutStart = operation.selStart;
	operation.cutEnd = operation.selEnd;
	operation.newSelStart = operation.selStart;
	operation.newSelEnd = operation.selStart + operation.replacement.length;
};

})();

P.S.
Sorry for the wall of text, hope it’s not too heavy. If I haven’t been clear or you need more info, please tell me, I tried to be brief (but with little success) and maybe I left some important details along the way

I’ve been working on a improved excise tool as well! But I’ve been pretty distracted lately. This works well with @Mohammad 's selection patches. My idea is that the user can use a template that contains additional info ( tags, fields, prefixes). Also, you can use the first line of text of the selection (minus any heading symbols) as the title of the excision.

I guess you mean, how can you get the title of tiddler after running the js ? Because you already have the title inside the js (exciseTitle). I think you could just navigate to the most recent tiddler, since it would have to be the excised tiddler.

image

Edit: Code showing a way to fetch most recently modified tiddler (ignoring drafts, temp, and state tiddlers) :

<$vars noList="[[$:/HistoryList]] [[$:/StoryList]] TestTiddler">
{{{ [all[tiddlers]!has[draft.of]!prefix[$:/state]!prefix[$:/temp]]-[enlist<noList>]+[!sort[modified]]+[nth[1]] }}}

</$vars>

Cool, it’s very interesting what I see from the picture, even if I have more modest goals

Yes, I guess that’s my problem. It’s probably better worded this way.

Interesting approach, but unfortunately I don’t like timestamps, so I’m afraid I wouldn’t make much of it.

You said I can use “excisionTitle”, can you tell me more about it?
I tried to insert it in the dropdown, but I didn’t understand how to do it/if it’s possible, because “excisionTitle” is something that is present in the js tiddler and not in the dropdown tiddler.

In any case, thank you for the answer @Mark_S, interesting stuff

What’s wrong with timestamps? Almost all tiddlers have a modified date field. It’s not something you have to do manually.

If you’re receiving updates by email, you may not have seen my edit:

<$vars noList="[[$:/HistoryList]] [[$:/StoryList]] TestTiddler">
{{{ [all[tiddlers]!has[draft.of]!prefix[$:/state]!prefix[$:/temp]]-[enlist<noList>]+[!sort[modified]]+[nth[1]] }}}

</$vars>

So in your wiki code, right after calling the excision, you could set a variable to capture the title of the most recently modified tiddler. Then use the ActionNavigateWidget to scroll to the new excised tiddler.

However, to insert the link, I would modify the dropdown selection to say “Transclusion & Link” and then have excise.js check for that response and write out the link at the same time as it does the transclusion. I don’t think you can depend on coming back from the Excise dialog and having the cursor be at the same spot.

1 Like

I don’t know, but I’ve always preferred not to use them, especially when working on system tiddlers and when coding. Indeed there would be nothing wrong with your approach, but if an alternative is possible, I would go with that, I’m sorry :sweat_smile:. But thank you all the same.

Here is something interesting, I hadn’t thought of that, it might make things easier. I’ll do some experiments, thank you again!

@Sobriety I have only looked at the standard dropdown but the title of the transclusion is what the user provides, if an existing title is used a red warning is displayed. The title is thus what is entered nothing else. The dropdown in $:/core/ui/EditorToolbar/excise-dropdown creates and deletes a tiddler containing this title.

  • Inside the modified excise tool you can make use of the state tiddler generated to get the title provide.
  • You could save this title out before deleting it, if you wanted to save it beyond the excise tool. eg “last excise title” or even a list/db for a history list of excise tiddlers.

In short the excise title is known, before creation and the excising of content, and is equal to the title provided. So that is where you get the title.

2 Likes

That’s right! Thanks, I think I’m getting closer and closer to the solution :grin:

Consider also other “learnings”

In editor toolbar items we commonly make use of a single tm-edit-text-operation but editor toolbar buttons can contain any and multiple valid actions you want to trigger.

  • Most tm-edit-text-operation’s are designed to act on the selected text
  • If you want to reference the selection in your own code/actions use the tm-edit-text-operation save-selection to store the selection for subsequent use, temporary or otherwise.
  • In the case of the excise button and others that use a dropdown, it is the code within the dropdown that determines the outcome, including naming your new tiddlers etc… from the selection (or autogenerated?)
  • However keep in mind when inside a dropdown that dropdown has the focus, so if something there changes the focus you will leave the dropdown, such as your <$action-navigate $to=???/>, perhaps you best open without scrolling <$action-navigate $to="ActionWidgets" $scroll=no/> the tiddler will open below, and the excise retain focus.

Best of luck, don’t hesitate to ask more questions and please share back.

Thanks again @TW_Tones, and thanks for the explanations. I think I’m almost at the finsih line now, just a couple of corrections and in half an hour I think I’ll share the result.

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>
&#x276F;&thinsp;__Prefix:__
<div class="center">
<$tiddler tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown">
<$radio field="radio" value="" default="$:/sob/">&thinsp;None</$radio>&nbsp;
<$radio field="radio" value="$:/sob/" default="$:/sob/">&thinsp;Sobriety</$radio>&nbsp;
</$tiddler>
</div>

&#x276F;&thinsp;__Add suffix:__&ensp;<$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">&nbsp;
<$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">&#32;Tag new tiddler with the title of this tiddler</$checkbox>

<div class="frame-A2px">
''&#x276F;''&thinsp;Replace with:&#32;<$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">&#32;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)

2023-04-18 233442


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.

  • What I’m missing is:
  1. 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>
  1. 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;
};

})();

I don’t have time to give a full solution but perhaps these tips will help here.

The tags can be set in a few different ways including;

  • In the create tiddler widget if in use
  • If you know the title, use WidgetMessage: tm-add-tag
    • Remember to wrap with fieldmangler.

When adding tags, Either you use a tag or list aware action or construct the whole tags field yourself and set it eg tags=“one two [[three with space]]”.

  • One code pattern you can use is roughly tags={{{ [{!!tags}] [[add tag]] }}}

Checkboxes could add one or more tags to a named tiddlers tags using listField="tags"

  • even a temporary tiddler you then use to set on your new tiddler. tags={{temp!!tags}}
1 Like

I’ve made a few small helper macros to perform a “Tag new tiddler with the title of this tiddler” type operation and I ended up using the form:

<$fieldmangler tiddler=<<actionTiddler>>>
<$action-sendmessage $message="tm-add-tag" $param=<<currentTiddler>>/>
</$fieldmangler>

for tiddlers dropped into a droppable dropzone.

Just another option for adding tags.

/Mike

1 Like
Code:
\define lingo-base() $:/language/Buttons/Excise/

\define body(config-title)
\whitespace trim
''<<lingo Hint>>''
<hr>
<$set name="NewExcisionPrefix" value="{{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!radio}}{{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!part-of-title}}">
<$set name="NewExcisionSuffix" value="{{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!grab}}">
<$wikify name=Prefix-wikified text=<<NewExcisionPrefix>>>
<$wikify name=Suffix-wikified text=<<NewExcisionSuffix>>>
<div class="NewTitleDisplay">&nbsp;
<span class="PrefixStyle">
<$text name=Prefix-Text text=<<Prefix-wikified>>>
<text src=<<Prefix-Text>>/>
</$text>
</span>
<span class="SuffixStyle">
<$text name=Suffix-Text text=<<Suffix-wikified>>>
<text src=<<Suffix-Text>>/>
</$text>
</span>
</div>
</$wikify>
</$wikify>
</$set>
</$set>


<$wikify name=excision-title-wikified text={{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!excision-title}}>
<$set name="new-title" value=<<excision-title-wikified>>>
<$list filter="""[<new-title>is[tiddler]]""">
<div class="tc-error">
<<lingo Caption/TiddlerExists>>
</div>
</$list>
</$set>
</$wikify>

&#x276F;&thinsp;__Prefix:__
<div class="centered">
<$tiddler tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown">
<$radio field="radio" value="" default="$:/sob/">&thinsp;None</$radio>&nbsp;
<$radio field="radio" value="$:/sob/" default="$:/sob/">&thinsp;Sobriety</$radio>&nbsp;
<$radio field="radio" value="$:/sob/ex/" default="$:/sob/">&thinsp;Sobriety ex</$radio>
</$tiddler>
</div>
<div class="centered">
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[part-of-title]count[]match[0]]">
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]part-of-title-on[off]]">
,,Can't add part of title,,
</$list>
</$list>
<br>
<$fieldmangler>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]part-of-title-on[on]]" variable=null>
 <$set name="id-trim-prefix+slash" value="<<id-trim-prefix>>/">
  <$button><$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="part-of-title-on" $value="off"/><$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="part-of-title" $value=<<id-trim-prefix+slash>>/>
    Add part of title
  </$button>
 </$set>
</$list>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]part-of-title-on[off]]" variable=null>
  <$button><$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="part-of-title-on" $value="on"/><$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="part-of-title" $value=""/>
    Remove part of title
  </$button>
</$list>
</$fieldmangler>
</div>

&#x276F;&thinsp;__Add suffix:__&ensp;<$edit-text focus="yes" class="s EditTextStyle" tag="input" tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" field="grab" />

<$wikify name=excision-title-wikified text={{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!excision-title}}>
<$list filter="""[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[grab]count[]match[0]]""">
<div class="centered">''&#9652;''&nbsp;//Enter a suffix//&nbsp;''&#9652;''</div>
</$list>
</$wikify>

<hr>
{{$:/core/images/tag-button}}&thinsp;//The tiddler will be tagged with://

<div class="EmptySpace1em"></div>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[radio]] +[match[$:/sob/]]">
`$:/sob/`&ensp;
</$list>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[radio]] +[match[$:/sob/ex/]]">
`$:/sob/ex/`&ensp;
</$list>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[tag-with-title]] +[match[on]]">
`The title of this tiddler`
</$list>

<div class="EmptySpace1em"></div>
<$checkbox tiddler="""$config-title$/tagnew""" field="text" checked="yes" unchecked="no" default="false" checkactions="""<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="tag-with-title" $value="on"/>""" uncheckactions="""<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="tag-with-title" $value="off"/>""">&#32; Tag new tiddler with the title of this tiddler</$checkbox>

<div class="Frame2px">
''&#x276F;''&thinsp;Replace with:&#32;<$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="EmptySpace1em"></div>

<$checkbox tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" field="icon+on" checked="on" unchecked="off" default="off">&#32;Add link +</$checkbox>
<div class="EmptySpace1em"></div>

<$wikify name=excision-title-wikified text={{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!excision-title}}>
<$set name="new-title" value=<<excision-title-wikified>>>
<$list filter="""[<new-title>is[tiddler]] [[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[grab]count[]match[0]]""">
<$button tooltip="You can't make the excision yet" disabled>
~~<<lingo Caption/Excise>>~~
</$button>
</$list>
</$set>
</$wikify>

<$wikify name=excision-title-wikified text={{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!excision-title}}>
<$set name="new-title" value=<<excision-title-wikified>>>
<$list filter="""[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[grab]count[]!match[0]]""">
<$list filter="""[<new-title>!is[tiddler]]""">
<$button>
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="excise"
	title=<<excision-title-wikified>>
	type={{$config-title$/type}}
	macro={{$config-title$/macro-title}}
	tagnew={{$config-title$/tagnew}}
/>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[icon+on]] +[match[on]]">
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="wrap-selection"
	prefix=""
	suffix="?????"
/></$list>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[radio]] +[match[$:/sob/ex/]]">
<$fieldmangler tiddler=<<excision-title-wikified>>>
<$action-sendmessage $message="tm-add-tag" $param="$:/sob/ex/"/>
</$fieldmangler>
</$list>
<$list filter="[[$:/sob/Btn/EditorToolbar/Excise/Dropdown]get[radio]] +[match[$:/sob/]]">
<$fieldmangler tiddler=<<excision-title-wikified>>>
<$action-sendmessage $message="tm-add-tag" $param="$:/sob/"/>
</$fieldmangler>
</$list>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="grab" $value=""
/>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="icon+on" $value="off"
/>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="part-of-title" $value=""
/>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="radio" $value="$:/sob/"
/>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="tag-with-title" $value=""
/>
<$action-setfield $tiddler="$:/sob/Btn/EditorToolbar/Excise/Dropdown" $field="part-of-title-on" $value="on"
/>
<$action-navigate $to=<<excision-title-wikified>>
/>
<<lingo Caption/Excise>>
</$button>
</$list>
</$list>
</$set>
</$wikify>
</div>
\end

<$macrocall $name="body" config-title=<<qualify "$:/state/Excise/">>/>



Style:
.EditTextStyle {
  min-width: 18em;
  border: none;
  border: 1px solid <<colour foreground>>;
  border-bottom: 2px solid <<colour tiddler-title-foreground>>;
}
.EmptySpace1em {
  content: " ";
  display: block;
  border-bottom: 0px solid #000;
  margin-top: 1em;
  margin-bottom: 1em;;
}
.Frame2px {
  border: 2px solid <<colour table-header-background>>;
  padding: 0.3rem;
}
.centered {
  text-align: center;
}
.NewTitleDisplay {
  border: 2px solid <<colour table-header-background>>;
  padding: 0.3rem;
}
.PrefixStyle {
  color: <<colour tiddler-title-foreground>>;
  font-weight: bold;
}
.SuffixStyle {
  color: <<colour tiddler-title-foreground>>;
  font-weight: bold;
  text-decoration: underline;  
}

Illustrative image:

One step closer, one last remaining. (ouch, I meant two)

The last things I miss:

  1. How do I get the title of the tiddler I’m editing from within the dropdown?
    (i.e. if I’m editing “HelloThere” how can I get the title of “HelloThere” from within the dropdown of an EditorToolbar button)

    I tried with {{!!title}} but it gives me the title of the dropdown EditorToolbar, and <<currentTiddler>> doesn’t seem to work.
    An idea that maybe could help (but I haven’t been able to implement it): Make it so that when the “Excise” button (the one that opens the dropdown) is clicked, the title of the tiddler I’m editing is saved in a field.

  2. Unfortunately I’m still stuck on this piece of code: (What can I put in place of the ???)
    I would like to insert instead of ??? something like this:
    [[+|New excision title]] The new title is contained in the “excision-title” field, whose value is the sum of some transclusions (that’s why it needs to first pass through a $wikify widget)
    Since the title of the new tiddler is the combinatio of three parts (two prefixes and a suffix), its value is:
    {{$:/sob/...!!radio}}{{$:/sob/...!!part-of-title}}{{$:/sob/..!!grab}}

<$wikify name=excision-title-wikified text={{$:/sob/Btn/EditorToolbar/Excise/Dropdown!!excision-title}}>
<$set name="new-title" value=<<excision-title-wikified>>>
<$button>

<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="wrap-selection"
	prefix=""
	suffix="?????"
/>

<<lingo Caption/Excise>></$button>
</$set>
</$wikify>
</div>
\end

(Tiddlers:)
$ _sob_Btn_EditorToolbar_Excise.json (366 Bytes)
$ _sob_Styles_Test.json (874 Bytes)
$ _sob_Btn_EditorToolbar_Excise_Dropdown.json (7.8 KB)

Once everything is finished I will share tiddlers with comments in the code itself so if anyone wants to make changes they can do it comfortably. (I don’t know if anyone might be interested, but since I’ve taken a lot from this site myself, I’ll give anything I can give.)

  • When a list or macro is making use of the current tiddler variable, we can instead make use of the <<storytTiddler>> variable which is the tiddlername in the story we are viewing, in edit mode it becomes the draft title.
  • Since we use the excise tool whilst editing a tiddler, we are in fact editing the draft version of the tiddler. In fact the excise tool operates on this draft tiddler, thus if we cancel the edit the original is restored.
  • As you may have seen <<currentTiddler>> has the value of the dropdown tiddler, not the tiddler we are editing.

In similar cases where I need to form some content that is itself wikitext, I use the join operator, of importiantce is characters used in filters need to be defined in strings.

\define open-link() [[+|
\define close-link() ]]
...
suffix={{{ [<open-link>] [{$:/sob/...!!radio}] [{$:/sob/...!!part-of-title}] [{$:/sob/..!!grab}]  [<close-link>] +[join[]] }}}
...
1 Like

I’m happy to say that everything works! Great, soon I’ll share the result with a lot of commented code.
A very big and heartfelt thank you @TW_Tones! :grin:

1 Like

Completed. Here are the tiddlers, if anyone wants to use them:
$ _core_modules_editor_operations_text_excise.js(4).json (2.1 KB)
$ _sob_Styles_EditorToolbar_Excise_Dropdown.json (930 Bytes)
$ _sob_Btn_EditorToolbar_Excise(2).json (366 Bytes)
$ _sob_Btn_EditorToolbar_Excise_Dropdown(3).json (11.9 KB)

The latter’s code ($:/sob/Btn/EditorToolbar/Excise/Dropdown) is commented and there are instructions to customize it.


  • Brief overview of the functionality of this custom made button:




Added features compared to the normal excise button:

  1. The ability to use $transclude widget in addition to the shorter form of {{}}. (In block or span mode)
  2. You can see which tags will be added to the new tiddler during the excision process
  3. With $radio you can add a predefined prefix to the new tiddler
  4. In addition to this you can add part of the title of the tiddler you are editing to the title of the tiddler you are about to create
  5. Manually enter the end of the title (as you would in the regular “excise” button)
  6. The possibility, using a checkbox, to add a link after the excision (e.g. {{NewExcision}}[[+|NewExcison]] )
  7. Finally the newly created tiddler is put into focus in the Story River

(Thanks again to @TW_Tones)

5 Likes

Thank you @Sobriety for sharing back. I am looking forward to using it.

I have just reviewed this, good work. However it is quite specific to your needs. Perhaps you could generalise it for a broader audience, it would be a useful tool?

  • allow the prefix to be edited
  • Let use excise without a suffix

In a similar vein I created this package to wrap selections in tags, try it on tiddlywiki.com and see how it is generalised. You may also find the mechanisium to add and reuse custom tags useful. In your case for prefix/suffix and or tag.

  • I have a similar one for macros.

EditorToolbar-wrapper.json (5.4 KB)

Thank you :slight_smile:

I had thought about it, but I was afraid that for now I was not yet good enough to attempt such a thing. But I’m learning fast, a couple of months ago I hardly knew what a transclusion was.

My hope for now is that if anyone is interested they can manually customize the code to suit their needs.

However I will make attempts. (I’ll also take some inspiration from what you just provided)
But unfortunately I can not guarantee anything. In case I don’t make it, I’ll set myself a reminder for a couple of months down the line when I’ll hopefully be better at TiddlyWiki.

But let’s see what I can do for now.

While I doubt for now I can manage to make it general without not needing to modify the code (for example the suffix $:/sob/ which I use I believe can only let it be manually modified) the two edits you proposed I could succeed to solve them. (The first is a direct improvement so it would be a change common to all custom versions, the second would vary according to preferences, so for the moment for the second I can only add a comment to the code with an explanation of how to do it.)

For now this I should be able to do. (will update later)


As for making it even more customizable, perhaps with a tiddler from which one could manage the value of the prefixes and the trim mechanism without having to open the excise tiddler editor, I’ll let you know later if I can do it.