Skip to content

Commit

Permalink
New Feature: Open new tab when creating new file (#176)
Browse files Browse the repository at this point in the history
* Add new option to open note as new tab, alternative to split

* Update docs for new tab option

* Update handlers.ts

Remove leftover code

---------

Co-authored-by: Sam <sam@sbgood.ca>
  • Loading branch information
0snug0 and shabegom authored Jan 31, 2024
1 parent e439bb9 commit cc722dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The quickest way to get started with Buttons is to use the Button Maker. You can
- **Prepend Template:** Click the Button to prepend a template into the current note.
- **Append Template:** Click the Button to append a template into the current note.
- **Add Template at Line:** Click the Button to add a template into the current note at the specified line.
- **New Note From Template:** Choose the Template, write the name of the new note, choose whether the new note should open in a split pane.
- **New Note From Template:** Choose the Template, write the name of the new note, choose whether the new note should replace the existing tab, open a new tab or split pane.
- **Text:** Choose Prepend, Append, New Note, or Line and the text you want to use:
- **Prepend Template:** Click the Button to prepend text into the current note.
- **Append Template:** Click the Button to append text into the current note.
Expand Down Expand Up @@ -230,7 +230,7 @@ Say you want the weather to appear at a specific place in your note that isn't d
^button-weatherLine

#### New Note From Template
Create a new note for an upcoming meeting based on a Meeting Note Template:
Create a new note in a new split pane for an upcoming meeting based on a Meeting Note Template:

```button
name New Meeting
Expand All @@ -239,11 +239,11 @@ Create a new note for an upcoming meeting based on a Meeting Note Template:
```
^button-meeting

Dynamically add the hour and minute to the note title:
Dynamically add the hour and minute to the note title and open as a new tab:

```button
name New Meeting
type note(Meeting-<%tp.date.now("HH-MM") %>, split) template
type note(Meeting-<%tp.date.now("HH-MM") %>, tab) note
action Meeting Note Template
templater true
```
Expand Down
10 changes: 7 additions & 3 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ export const createNote = async (
filePath?: TFile,
templater?: string
): Promise<void> => {
const path = type.match(/\(([\s\S]*?),?\s?(split)?\)/);
const path = type.match(/\(([\s\S]*?),?\s?(split|tab)?\)/);
if (path) {
try {
if (filePath) {
await app.vault.create(`${path[1]}.md`, "");
await app.vault.create(`${path[1]}.md`, content);
const file = app.vault.getAbstractFileByPath(`${path[1]}.md`) as TFile;
if (path[2] == "split") {
await app.workspace.splitActiveLeaf().openFile(file);
} else if (path[2] == "tab") {
await app.workspace.getLeaf(!0).openFile(file);
} else {
await app.vault.create(`${path[1]}.md`, content);
}
Expand Down

0 comments on commit cc722dc

Please sign in to comment.