Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 8b841c5

Browse files
authored
feat(autocomplete): support specifying path when creating a new note (#2342)
2 parents a37af29 + a78e4d7 commit 8b841c5

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

apps/client/src/services/note_autocomplete.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,11 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
289289
}
290290

291291
if (suggestion.action === "create-note") {
292-
const { success, noteType, templateNoteId } = await noteCreateService.chooseNoteType();
293-
292+
const { success, noteType, templateNoteId, notePath } = await noteCreateService.chooseNoteType();
294293
if (!success) {
295294
return;
296295
}
297-
298-
const { note } = await noteCreateService.createNote(suggestion.parentNoteId, {
296+
const { note } = await noteCreateService.createNote( notePath || suggestion.parentNoteId, {
299297
title: suggestion.noteTitle,
300298
activate: false,
301299
type: noteType,

apps/client/src/services/note_create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async function chooseNoteType() {
116116
}
117117

118118
async function createNoteWithTypePrompt(parentNotePath: string, options: CreateNoteOpts = {}) {
119-
const { success, noteType, templateNoteId } = await chooseNoteType();
119+
const { success, noteType, templateNoteId, notePath } = await chooseNoteType();
120120

121121
if (!success) {
122122
return;
@@ -125,7 +125,7 @@ async function createNoteWithTypePrompt(parentNotePath: string, options: CreateN
125125
options.type = noteType;
126126
options.templateNoteId = templateNoteId;
127127

128-
return await createNote(parentNotePath, options);
128+
return await createNote(notePath || parentNotePath, options);
129129
}
130130

131131
/* If the first element is heading, parse it out and use it as a new heading. */

apps/client/src/translations/en/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@
233233
"move_success_message": "Selected notes have been moved into "
234234
},
235235
"note_type_chooser": {
236+
"change_path_prompt": "Change where to create the new note:",
237+
"search_placeholder": "search path by name (default if empty)",
236238
"modal_title": "Choose note type",
237239
"close": "Close",
238240
"modal_body": "Choose note type / template of the new note:",

apps/client/src/widgets/dialogs/note_type_chooser.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { CommandNames } from "../../components/app_context.js";
22
import type { MenuCommandItem } from "../../menus/context_menu.js";
33
import { t } from "../../services/i18n.js";
44
import noteTypesService from "../../services/note_types.js";
5+
import noteAutocompleteService from "../../services/note_autocomplete.js";
56
import BasicWidget from "../basic_widget.js";
67
import { Dropdown, Modal } from "bootstrap";
78

@@ -13,6 +14,11 @@ const TPL = /*html*/`
1314
z-index: 1100 !important;
1415
}
1516
17+
.note-type-chooser-dialog .input-group {
18+
margin-top: 15px;
19+
margin-bottom: 15px;
20+
}
21+
1622
.note-type-chooser-dialog .note-type-dropdown {
1723
position: relative;
1824
font-size: large;
@@ -30,6 +36,12 @@ const TPL = /*html*/`
3036
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="${t("note_type_chooser.close")}"></button>
3137
</div>
3238
<div class="modal-body">
39+
${t("note_type_chooser.change_path_prompt")}
40+
41+
<div class="input-group">
42+
<input class="choose-note-path form-control" placeholder="${t("note_type_chooser.search_placeholder")}">
43+
</div>
44+
3345
${t("note_type_chooser.modal_body")}
3446
3547
<div class="dropdown" style="display: flex;">
@@ -48,6 +60,7 @@ export interface ChooseNoteTypeResponse {
4860
success: boolean;
4961
noteType?: string;
5062
templateNoteId?: string;
63+
notePath?: string;
5164
}
5265

5366
type Callback = (data: ChooseNoteTypeResponse) => void;
@@ -57,6 +70,7 @@ export default class NoteTypeChooserDialog extends BasicWidget {
5770
private dropdown!: Dropdown;
5871
private modal!: Modal;
5972
private $noteTypeDropdown!: JQuery<HTMLElement>;
73+
private $autoComplete!: JQuery<HTMLElement>;
6074
private $originalFocused: JQuery<HTMLElement> | null;
6175
private $originalDialog: JQuery<HTMLElement> | null;
6276

@@ -71,7 +85,8 @@ export default class NoteTypeChooserDialog extends BasicWidget {
7185
doRender() {
7286
this.$widget = $(TPL);
7387
this.modal = Modal.getOrCreateInstance(this.$widget[0]);
74-
88+
89+
this.$autoComplete = this.$widget.find(".choose-note-path");
7590
this.$noteTypeDropdown = this.$widget.find(".note-type-dropdown");
7691
this.dropdown = Dropdown.getOrCreateInstance(this.$widget.find(".note-type-dropdown-trigger")[0]);
7792

@@ -116,9 +131,20 @@ export default class NoteTypeChooserDialog extends BasicWidget {
116131
});
117132
}
118133

134+
async refresh() {
135+
noteAutocompleteService
136+
.initNoteAutocomplete(this.$autoComplete, {
137+
allowCreatingNotes: false,
138+
hideGoToSelectedNoteButton: true,
139+
allowJumpToSearchNotes: false,
140+
})
141+
}
142+
119143
async chooseNoteTypeEvent({ callback }: { callback: Callback }) {
120144
this.$originalFocused = $(":focus");
121145

146+
await this.refresh();
147+
122148
const noteTypes = await noteTypesService.getNoteTypeItems();
123149

124150
this.$noteTypeDropdown.empty();
@@ -153,12 +179,14 @@ export default class NoteTypeChooserDialog extends BasicWidget {
153179
const $item = $(e.target).closest(".dropdown-item");
154180
const noteType = $item.attr("data-note-type");
155181
const templateNoteId = $item.attr("data-template-note-id");
182+
const notePath = this.$autoComplete.getSelectedNotePath() || undefined;
156183

157184
if (this.resolve) {
158185
this.resolve({
159186
success: true,
160187
noteType,
161-
templateNoteId
188+
templateNoteId,
189+
notePath
162190
});
163191
}
164192
this.resolve = null;

0 commit comments

Comments
 (0)