Skip to content

Commit

Permalink
shift-enter while creating new scenes keeps focus
Browse files Browse the repository at this point in the history
fixes #214
  • Loading branch information
kevboh committed Jan 28, 2024
1 parent 9764e07 commit 8463632
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/model/draft-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ type SceneInsertionLocation = {
export async function createScene(
app: App,
path: string,
draft: MultipleSceneDraft
draft: MultipleSceneDraft,
open: boolean
): Promise<void> {
const template = draft.sceneTemplate ?? get(pluginSettings).sceneTemplate;
createNoteWithPotentialTemplate(app, path, template);
app.workspace.openLinkText(path, "/", false);
if (open) {
app.workspace.openLinkText(path, "/", false);
}
}

export async function insertScene(
Expand All @@ -31,7 +34,8 @@ export async function insertScene(
draft: MultipleSceneDraft,
sceneName: string,
vault: Vault,
location: SceneInsertionLocation
location: SceneInsertionLocation,
open: boolean
) {
const newScenePath = scenePath(sceneName, draft, vault);

Expand Down Expand Up @@ -59,7 +63,7 @@ export async function insertScene(
return d;
});
});
await createScene(app, newScenePath, draft);
await createScene(app, newScenePath, draft, open);
}

export function setDraftOnFrontmatterObject(
Expand Down
21 changes: 15 additions & 6 deletions src/view/explorer/ExplorerPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,15 @@ export class ExplorerPane extends ItemView {
);

// Context function for creating new scene notes given a path
context.set("onNewScene", async (name: string) => {
context.set("onNewScene", async (name: string, open: boolean) => {
await insertScene(
this.app,
drafts,
get(selectedDraft) as MultipleSceneDraft,
name,
this.app.vault,
{ at: "end", relativeTo: null }
{ at: "end", relativeTo: null },
open
);
});

Expand Down Expand Up @@ -160,10 +161,18 @@ export class ExplorerPane extends ItemView {
.indexOf(file.name.split(".md")[0]);

if (relativeTo >= 0) {
insertScene(this.app, drafts, draft, sceneName, this.app.vault, {
at,
relativeTo,
});
insertScene(
this.app,
drafts,
draft,
sceneName,
this.app.vault,
{
at,
relativeTo,
},
true
);
}
};

Expand Down
9 changes: 5 additions & 4 deletions src/view/explorer/NewSceneField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
}
}
const onNewScene: (name: string) => void = getContext("onNewScene");
function onNewSceneEnter() {
const onNewScene: (name: string, open: boolean) => void =
getContext("onNewScene");
function onNewSceneEnter(open: boolean) {
if (newSceneName.length > 0 && !error) {
onNewScene(newSceneName);
onNewScene(newSceneName, open);
newSceneName = "";
}
}
Expand All @@ -42,7 +43,7 @@
bind:this={newSceneInput}
on:keydown={(e) => {
if (e.key === "Enter") {
onNewSceneEnter();
onNewSceneEnter(!e.shiftKey);
} else if (e.key === "Escape") {
newSceneName = "";
newSceneInput.blur();
Expand Down

0 comments on commit 8463632

Please sign in to comment.