saveinme 1.3.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/editor.js +76 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saveinme",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "Your personal terminal notebook — save anything, permanently.",
5
5
  "type": "module",
6
6
  "main": "./bin/saveinme.js",
package/src/editor.js CHANGED
@@ -49,30 +49,55 @@ export async function saveFromClipboard(titleArg, notebookOverride) {
49
49
  }
50
50
  console.log(chalk.dim(' └──────────────────────────────────────────────────\n'));
51
51
 
52
- // Resolve title
53
- const title = (titleArg && titleArg.trim()) || `Clipboard Note - ${getTimestamp()}`;
54
- const existingNote = getNoteByTitle(title);
55
-
56
52
  // Resolve notebook target
57
53
  const defaultNotebook = getDefaultNotebook();
58
- const category = (notebookOverride !== null) ? notebookOverride.trim() : (existingNote?.category ?? defaultNotebook);
54
+ const tempCategory = (notebookOverride !== null) ? notebookOverride.trim() : defaultNotebook;
55
+
56
+ // Resolve title
57
+ let title = (titleArg && titleArg.trim()) || '';
58
+ let isAppend = false;
59
+
60
+ if (!title) {
61
+ if (tempCategory) {
62
+ title = tempCategory;
63
+ isAppend = true;
64
+ } else {
65
+ title = `Clipboard Note - ${getTimestamp()}`;
66
+ }
67
+ }
68
+
69
+ const existingNoteResolve = getNoteByTitle(title);
70
+ const category = (notebookOverride !== null) ? notebookOverride.trim() : (existingNoteResolve?.category ?? defaultNotebook);
71
+ let finalContent = clipboardContent;
72
+
73
+ if (existingNoteResolve && isAppend) {
74
+ finalContent = existingNoteResolve.content + '\n' + clipboardContent;
75
+ }
59
76
 
60
77
  saveNote({
61
- id: existingNote?.id, // updates if title matches exactly
78
+ id: existingNoteResolve?.id, // updates if title matches exactly
62
79
  title: title.trim(),
63
- content: clipboardContent,
80
+ content: finalContent,
64
81
  category: category.trim(),
65
- tags: existingNote?.tags ?? [],
66
- priority: existingNote?.priority ?? 'medium',
67
- pinned: existingNote?.pinned ?? false,
82
+ tags: existingNoteResolve?.tags ?? [],
83
+ priority: existingNoteResolve?.priority ?? 'medium',
84
+ pinned: existingNoteResolve?.pinned ?? false,
68
85
  });
69
86
 
70
87
  const wc = clipboardContent.split(/\s+/).filter(Boolean).length;
71
- showSuccess(
72
- `Clipboard note "${title.trim()}" saved!` +
73
- (category ? ` [Notebook: ${category.trim()}]` : '') +
74
- chalk.dim(` (${wc} words)`)
75
- );
88
+ if (existingNoteResolve && isAppend) {
89
+ showSuccess(
90
+ `Appended clipboard text to note "${title.trim()}"` +
91
+ (category ? ` in notebook "${category.trim()}"` : '') +
92
+ chalk.dim(` (+${wc} words)`)
93
+ );
94
+ } else {
95
+ showSuccess(
96
+ `Clipboard note "${title.trim()}" saved!` +
97
+ (category ? ` [Notebook: ${category.trim()}]` : '') +
98
+ chalk.dim(` (${wc} words)`)
99
+ );
100
+ }
76
101
  }
77
102
 
78
103
  // ─── Save piped stdin directly ────────────────────────────────────────────────
@@ -96,25 +121,49 @@ export async function savePipedInput(inputContent, titleArg, notebookOverride) {
96
121
  const category = (notebookOverride !== null) ? notebookOverride.trim() : defaultNotebook;
97
122
 
98
123
  // Resolve title
99
- const title = (titleArg && titleArg.trim()) || `Piped Note - ${getTimestamp()}`;
100
- const existingNote = getNoteByTitle(title);
124
+ let title = (titleArg && titleArg.trim()) || '';
125
+ let isAppend = false;
126
+
127
+ if (!title) {
128
+ if (category) {
129
+ title = category;
130
+ isAppend = true;
131
+ } else {
132
+ title = `Piped Note - ${getTimestamp()}`;
133
+ }
134
+ }
135
+
136
+ const existingNoteResolve = getNoteByTitle(title);
137
+ let finalContent = content;
138
+
139
+ if (existingNoteResolve && isAppend) {
140
+ finalContent = existingNoteResolve.content + '\n' + content;
141
+ }
101
142
 
102
143
  saveNote({
103
- id: existingNote?.id,
144
+ id: existingNoteResolve?.id,
104
145
  title: title.trim(),
105
- content: content,
146
+ content: finalContent,
106
147
  category: category,
107
- tags: existingNote?.tags ?? [],
108
- priority: existingNote?.priority ?? 'medium',
109
- pinned: existingNote?.pinned ?? false,
148
+ tags: existingNoteResolve?.tags ?? [],
149
+ priority: existingNoteResolve?.priority ?? 'medium',
150
+ pinned: existingNoteResolve?.pinned ?? false,
110
151
  });
111
152
 
112
153
  const wc = content.split(/\s+/).filter(Boolean).length;
113
- showSuccess(
114
- `Saved piped note "${title.trim()}"` +
115
- (category ? ` to notebook "${category}"` : '') +
116
- chalk.dim(` (${wc} words)`)
117
- );
154
+ if (existingNoteResolve && isAppend) {
155
+ showSuccess(
156
+ `Appended piped text to note "${title.trim()}"` +
157
+ (category ? ` in notebook "${category}"` : '') +
158
+ chalk.dim(` (+${wc} words)`)
159
+ );
160
+ } else {
161
+ showSuccess(
162
+ `Saved piped note "${title.trim()}"` +
163
+ (category ? ` to notebook "${category}"` : '') +
164
+ chalk.dim(` (${wc} words)`)
165
+ );
166
+ }
118
167
  }
119
168
 
120
169
  // ─── Main editor entry point ──────────────────────────────────────────────────