Skip to content

Commit 72eacb1

Browse files
committed
Add rename handler
1 parent d923432 commit 72eacb1

5 files changed

+58
-6
lines changed

tiddlers/$__supp-info_core_sidebar_supp-info.tid renamed to tiddlers/$__supp-info_core_sidebar_notes.tid

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
caption: Supp
22
created: 20251113195712539
3-
modified: 20251117202206225
3+
modified: 20251117224618716
44
tags: $:/tags/SideBar
5-
title: $:/supp-info/core/sidebar/supp-info
5+
title: $:/supp-info/core/sidebar/notes
66
type: text/vnd.tiddlywiki
77

88
----------
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
caption: Supp Notes Content
22
created: 20251107151758434
3-
modified: 20251117211714179
3+
modified: 20251117224811306
44
tags: $:/tags/SupplementaryInfo
55
title: $:/supp-info/notes/content
66
type: application/json
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*\
2+
title: $:/supp-info/notes/modules/startup/rename
3+
type: application/javascript
4+
module-type: startup
5+
6+
Add hook for renames to update 'Renamed' text field
7+
\*/
8+
9+
"use strict";
10+
11+
// Export name and synchronous status
12+
exports.name = "rename";
13+
exports.platforms = ["browser"];
14+
exports.after = ["startup"];
15+
exports.synchronous = true;
16+
17+
const replaceKey = (oldKey, newKey) => (obj) =>
18+
Object.fromEntries(Object.entries(obj).map(
19+
([k, v]) => [k == oldKey ? newKey : k, v]
20+
))
21+
22+
exports.startup= function() {
23+
24+
$tw.hooks.addHook("th-saving-tiddler", function (newTiddler, oldTiddler) {
25+
if (
26+
newTiddler?.fields?.title === oldTiddler?.fields?.['draft.title']
27+
&& newTiddler?.fields?.created === oldTiddler?.fields?.created
28+
&& newTiddler?.fields?.title !== oldTiddler?.fields?.['draft.of']
29+
) {
30+
// We're in a rename scenario
31+
$tw.wiki.setText(
32+
'$:/supp-info/notes/content',
33+
'text',
34+
null,
35+
JSON.stringify(
36+
replaceKey(oldTiddler.fields["draft.of"] || oldTiddler.fields.title, newTiddler.fields.title)(
37+
JSON.parse($tw.wiki.getTiddler('$:/supp-info/notes/content').fields.text)
38+
),
39+
null,
40+
4
41+
)
42+
)
43+
}
44+
return newTiddler;
45+
});
46+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
caption: rename
2+
created: 20251117214415595
3+
modified: 20251117223838638
4+
module-type: startup
5+
tags:
6+
title: $:/supp-info/notes/modules/startup/rename
7+
type: application/javascript

tiddlers/$__supp-info_notes_view-template.tid

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
caption: Supp Notes Template
22
created: 20251107152410791
3-
modified: 20251117211857042
3+
modified: 20251117224954668
44
query: [prefix[$:/supp-info]]
55
tags: $:/tags/ViewTemplate
66
title: $:/supp-info/notes/view-template
@@ -9,7 +9,6 @@ type: text/vnd.tiddlywiki
99
\procedure add-note()
1010
<$let count={{{ [{$:/supp-info/notes/content}jsonindexes<currentTiddler>last[]add[1]] }}} css-index={{{ [<count>else[0]add[1]] }}}>
1111
<% if [{$:/supp-info/notes/content}jsonindexes<currentTiddler>count[]match[0]] %>
12-
<$action-log message="AAA" count=<<count>> css-index=<<css-index>> />
1312
<$action-setfield
1413
$tiddler="$:/supp-info/notes/content"
1514
$value={{{ [{$:/supp-info/notes/content}jsonset:array<currentTiddler>format:json[2]] }}}
@@ -18,7 +17,7 @@ type: text/vnd.tiddlywiki
1817
<% endif %>
1918
<$action-setfield
2019
$tiddler="$:/supp-info/notes/content"
21-
$value={{{ [{$:/supp-info/notes/content}jsonset<currentTiddler>,<count>,[Dummy text]format:json[2]] }}}
20+
$value={{{ [{$:/supp-info/notes/content}jsonset<currentTiddler>,<count>,[]format:json[2]] }}}
2221
/>
2322
<$action-setfield $tiddler=`$:/temp/supp-info/notes/$(currentTiddler)$` $field="state" $value="show" />
2423
<$let key={{{ [<count>else[0]add[1]subtract[1]] }}}> <!-- TODO: fix this ridiculous hack! -->

0 commit comments

Comments
 (0)