Skip to content

Commit 74019b2

Browse files
authored
Merge pull request #141 from sh1vam31/feat/focus-title-bar-after-template_#67
feat: add option to focus title bar after creating note from template
2 parents fc207ea + 9c3e6a0 commit 74019b2

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/actions.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import joplin from "api";
22
import { NewNote, NOTE_ID_PLACEHOLDER } from "./parser";
33
import { getSelectedFolder } from "./utils/folders";
44
import { applyTagToNote, getAnyTagWithTitle } from "./utils/tags";
5-
import { ApplyTagsWhileInsertingSetting } from "./settings";
5+
import { ApplyTagsWhileInsertingSetting, FocusTitleAfterCreateSetting } from "./settings";
66

77
export enum TemplateAction {
88
NewNote = "newNote",
@@ -47,6 +47,17 @@ const performNewNoteAction = async (template: NewNote, isTodo: 0 | 1) => {
4747
}
4848

4949
await joplin.commands.execute("openNote", note.id);
50+
51+
// Focus title bar if the user has enabled the setting
52+
const focusTitle = await FocusTitleAfterCreateSetting.get();
53+
if (focusTitle) {
54+
try {
55+
await joplin.commands.execute("focusElement", "noteTitle");
56+
} catch {
57+
// focusElement may not be available in all Joplin versions — fail silently
58+
}
59+
}
60+
5061
for (const tag of template.tags) {
5162
const tagId = (await getAnyTagWithTitle(tag)).id;
5263
await applyTagToNote(tagId, note.id);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { SettingItemType } from "api/types";
2+
import { createSimpleSetting } from "./base";
3+
4+
export const FocusTitleAfterCreateSetting = createSimpleSetting<boolean>("focusTitleAfterCreate", {
5+
public: true,
6+
type: SettingItemType.Bool,
7+
value: false,
8+
label: "Focus title bar after creating a note from template",
9+
description: "When enabled, the cursor will be placed in the title bar instead of the note body after creating a note or to-do from a template.",
10+
section: "templatesPlugin"
11+
});

src/settings/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export { DefaultNoteTemplateIdSetting } from "./defaultNoteTemplateId";
44
export { DefaultTemplatesConfigSetting } from "./defaultTemplatesConfig";
55
export { DefaultTodoTemplateIdSetting } from "./defaultTodoTemplateId";
66
export { TemplatesSourceSetting } from "./templatesSource";
7+
export { FocusTitleAfterCreateSetting } from "./focusTitleAfterCreate";
78

89
// Export registry
910
export { PluginSettingsRegistry } from "./registry";

src/settings/registry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DefaultNoteTemplateIdSetting } from "./defaultNoteTemplateId";
66
import { DefaultTemplatesConfigSetting } from "./defaultTemplatesConfig";
77
import { DefaultTodoTemplateIdSetting } from "./defaultTodoTemplateId";
88
import { TemplatesSourceSetting } from "./templatesSource";
9+
import { FocusTitleAfterCreateSetting } from "./focusTitleAfterCreate";
910

1011
import { PluginSetting } from "./base";
1112

@@ -16,6 +17,7 @@ export class PluginSettingsRegistry {
1617
DefaultTemplatesConfigSetting,
1718
DefaultTodoTemplateIdSetting,
1819
TemplatesSourceSetting,
20+
FocusTitleAfterCreateSetting,
1921
];
2022

2123
public static async registerSettings(): Promise<void> {

0 commit comments

Comments
 (0)