Skip to content

Commit 9416f7c

Browse files
committed
make opening to existing tab default behavior
1 parent 3cef188 commit 9416f7c

File tree

9 files changed

+8
-57
lines changed

9 files changed

+8
-57
lines changed

src/engine/CaptureChoiceEngine.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
9090
}
9191

9292
if (this.choice.openFile && file) {
93-
let openExistingTab = false;
94-
if (this.choice.focusExistingFileTab) {
95-
openExistingTab = await openExistingFileTab(this.app, file);
96-
}
93+
const openExistingTab = await openExistingFileTab(this.app, file);
9794

9895
if (!openExistingTab) {
9996
await openFile(this.app, file, {

src/engine/TemplateChoiceEngine.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ export class TemplateChoiceEngine extends TemplateEngine {
147147
}
148148

149149
if (this.choice.openFile && createdFile) {
150-
let openExistingTab = false;
151-
if (this.choice.focusExistingFileTab) {
152-
openExistingTab = await openExistingFileTab(this.app, createdFile);
153-
}
150+
const openExistingTab = await openExistingFileTab(
151+
this.app,
152+
createdFile,
153+
);
154154

155155
if (!openExistingTab) {
156156
await openFile(this.app, createdFile, {

src/gui/ChoiceBuilder/captureChoiceBuilder.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
5858
this.addOpenFileSetting();
5959

6060
if (this.choice.openFile) {
61-
this.addFocusExistingTabSetting();
62-
63-
if (!this.choice.focusExistingFileTab) {
64-
this.addOpenFileInNewTabSetting();
65-
}
61+
this.addOpenFileInNewTabSetting();
6662
}
6763
}
6864

@@ -435,20 +431,6 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
435431
});
436432
}
437433

438-
private addFocusExistingTabSetting(): void {
439-
const existingTabSetting = new Setting(this.contentEl);
440-
existingTabSetting
441-
.setName("Focus Existing Tab")
442-
.setDesc("Focus the tab that have already opened the file.")
443-
.addToggle((toggle) => {
444-
toggle.setValue(this.choice?.focusExistingFileTab);
445-
toggle.onChange((value) => {
446-
this.choice.focusExistingFileTab = value;
447-
this.reload();
448-
});
449-
});
450-
}
451-
452434
private addOpenFileInNewTabSetting(): void {
453435
const newTabSetting = new Setting(this.contentEl);
454436
newTabSetting

src/gui/ChoiceBuilder/templateChoiceBuilder.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
5151
this.addOpenFileSetting();
5252

5353
if (this.choice.openFile) {
54-
this.addFocusExistingTabSetting();
55-
56-
if (!this.choice.focusExistingFileTab) {
57-
this.addOpenFileInNewTabSetting();
58-
}
54+
this.addOpenFileInNewTabSetting();
5955
}
6056
}
6157

@@ -339,20 +335,6 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
339335
});
340336
}
341337

342-
private addFocusExistingTabSetting(): void {
343-
const existingTabSetting = new Setting(this.contentEl);
344-
existingTabSetting
345-
.setName("Focus Existing Tab")
346-
.setDesc("Focus the tab that have already opened the file.")
347-
.addToggle((toggle) => {
348-
toggle.setValue(this.choice?.focusExistingFileTab);
349-
toggle.onChange((value) => {
350-
this.choice.focusExistingFileTab = value;
351-
this.reload();
352-
});
353-
});
354-
}
355-
356338
private addOpenFileInNewTabSetting(): void {
357339
const newTabSetting = new Setting(this.contentEl);
358340
newTabSetting

src/types/choices/CaptureChoice.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export class CaptureChoice extends Choice implements ICaptureChoice {
2323
};
2424
prepend: boolean;
2525
task: boolean;
26-
focusExistingFileTab: boolean;
2726
openFileInNewTab: {
2827
enabled: boolean;
2928
direction: NewTabDirection;
@@ -61,7 +60,6 @@ export class CaptureChoice extends Choice implements ICaptureChoice {
6160
};
6261
this.openFile = false;
6362
this.openFileInMode = "default";
64-
this.focusExistingFileTab = true;
6563
}
6664

6765
public static Load(choice: ICaptureChoice): CaptureChoice {

src/types/choices/ICaptureChoice.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export default interface ICaptureChoice extends IChoice {
2323
createIfNotFound: boolean;
2424
createIfNotFoundLocation: string;
2525
};
26-
focusExistingFileTab: boolean;
2726
openFileInNewTab: {
2827
enabled: boolean;
2928
direction: NewTabDirection;

src/types/choices/ITemplateChoice.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default interface ITemplateChoice extends IChoice {
1515
fileNameFormat: { enabled: boolean; format: string };
1616
appendLink: boolean;
1717
openFile: boolean;
18-
focusExistingFileTab: boolean;
1918
openFileInNewTab: {
2019
enabled: boolean;
2120
direction: NewTabDirection;

src/types/choices/TemplateChoice.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export class TemplateChoice extends Choice implements ITemplateChoice {
1414
createInSameFolderAsActiveFile: boolean;
1515
chooseFromSubfolders: boolean;
1616
};
17-
focusExistingFileTab: boolean;
1817
openFileInNewTab: {
1918
enabled: boolean;
2019
direction: NewTabDirection;
@@ -48,7 +47,6 @@ export class TemplateChoice extends Choice implements ITemplateChoice {
4847
this.openFileInMode = "default";
4948
this.fileExistsMode = "Increment the file name";
5049
this.setFileExistsBehavior = false;
51-
this.focusExistingFileTab = true;
5250
}
5351

5452
public static Load(choice: ITemplateChoice): TemplateChoice {

src/utilityObsidian.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type { CaptureChoice } from "./types/choices/CaptureChoice";
1414
import type { MacroChoice } from "./types/choices/MacroChoice";
1515
import type IChoice from "./types/choices/IChoice";
1616
import { log } from "./logger/logManager";
17-
import { resolve } from "path";
1817

1918
export function getTemplater(app: App) {
2019
return app.plugins.plugins["templater-obsidian"];
@@ -177,10 +176,7 @@ export async function openExistingFileTab(
177176
const view = m_leaf.view;
178177
if (view instanceof FileView) {
179178
if (view.file) {
180-
const normalizedOpeningPath = resolve(file.path);
181-
const normalizedCurrentPath = resolve(view.file.path);
182-
183-
if (normalizedOpeningPath === normalizedCurrentPath) {
179+
if (file.path === view.file.path) {
184180
leaf = m_leaf;
185181
return;
186182
}

0 commit comments

Comments
 (0)