Skip to content

Commit c7ba29e

Browse files
author
luginf
committed
We're making the new-note-namer script upgrade-safe for existing users. The code and README are
updated with backward-compatible migration logic for the renamed heading setting.
1 parent 7c62dbe commit c7ba29e

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

‎new-note-namer/README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,18 @@ The two dialog options are independent: each defaults to the search term, regard
3535
- Check only _title_ to write a custom heading while keeping the file name equal to the search term.
3636
- The heading style applies in all cases, including when no dialog is shown.
3737
- All settings require a **script engine reload** to take effect after being changed.
38+
39+
## Upgrading from v0.0.2
40+
41+
v0.0.2 had a single boolean setting **Underline heading** that chose between ATX (`# Title`) and Setext (`Title / =====`).
42+
This was replaced by the **Heading style** selection in v0.0.3.
43+
44+
Your stored preference is migrated automatically:
45+
46+
| v0.0.2 setting | Effective heading style after upgrade |
47+
| -------------- | ------------------------------------- |
48+
| Unchecked (default) | ATX (`# Title`) — no change |
49+
| Checked | Setext (`Title / =====`) — preserved via the deprecated toggle |
50+
51+
The deprecated **Underline heading (deprecated)** entry remains visible in the script settings so QOwnNotes can still read your stored value.
52+
Once you have set **Heading style** to your preferred option you can safely uncheck the deprecated toggle.

‎new-note-namer/new-note-namer.qml‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ QtObject {
1313
property string _searchTerm: ""
1414
property string customHeadingOpen
1515
property string customHeadingClose
16+
property bool underlineHeading // deprecated — kept so existing stored settings still load
1617
property variant settingsVariables: [
1718
{
1819
'identifier': 'extraDialogForTitle',
@@ -54,6 +55,13 @@ QtObject {
5455
'type': 'string',
5556
'default': ''
5657
},
58+
{
59+
'identifier': 'underlineHeading',
60+
'name': 'Underline heading (deprecated)',
61+
'description': 'Deprecated: use "Heading style" above instead. Kept so that users upgrading from v0.0.2 automatically keep their Setext-heading preference without needing to change settings.',
62+
'type': 'boolean',
63+
'default': 'false'
64+
},
5765
]
5866

5967
function handleNewNoteHeadlineHook(headline) {
@@ -70,26 +78,36 @@ QtObject {
7078
}
7179
return buildHeadline(name);
7280
}
81+
// Migration helper: underlineHeading=true from v0.0.2 maps to Setext ("1").
82+
// headingStyle "1" or "2" set explicitly always wins.
83+
function effectiveHeadingStyle() {
84+
if (headingStyle === "0" && underlineHeading) {
85+
return "1";
86+
}
87+
return headingStyle;
88+
}
7389
function buildHeadline(name) {
74-
if (headingStyle === "2") {
90+
var style = effectiveHeadingStyle();
91+
if (style === "2") {
7592
return customHeadingOpen + name + customHeadingClose;
7693
}
77-
if (headingStyle === "1") {
94+
if (style === "1") {
7895
return name + "\n" + "=".repeat(name.length);
7996
}
8097
return "# " + name; // "0" (ATX) or unset
8198
}
8299
function extractTitle(noteText) {
83100
var firstLine = (noteText || "").split("\n")[0];
84-
if (headingStyle === "2") {
101+
var style = effectiveHeadingStyle();
102+
if (style === "2") {
85103
var t = firstLine.slice(customHeadingOpen.length);
86104
var closeLen = customHeadingClose.length;
87105
if (closeLen > 0 && t.slice(-closeLen) === customHeadingClose) {
88106
t = t.slice(0, t.length - closeLen);
89107
}
90108
return t;
91109
}
92-
if (headingStyle === "1") {
110+
if (style === "1") {
93111
return firstLine; // setext: first line is the bare title
94112
}
95113
return firstLine.slice(2); // ATX: remove "# "

0 commit comments

Comments
 (0)