mirror of
https://github.com/jesse-r-s-hines/obsidian-open-tab-settings.git
synced 2026-07-22 05:43:41 +00:00
Add more options for ctrl click
This commit is contained in:
parent
3d198292cb
commit
ccba100789
3 changed files with 51 additions and 51 deletions
|
|
@ -239,8 +239,8 @@ export default class OpenTabSettingsPlugin extends Plugin {
|
|||
isModEvent(oldMethod: any) {
|
||||
return function(this: any, ...args) {
|
||||
let result = oldMethod.call(this, ...args);
|
||||
if (plugin.settings.openInNewTab && plugin.settings.openInSameTabOnModClick && result == 'tab') {
|
||||
result = 'same';
|
||||
if (result == "tab") {
|
||||
result = plugin.settings.modClickBehavior;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -250,11 +250,6 @@ export default class OpenTabSettingsPlugin extends Plugin {
|
|||
|
||||
async loadSettings() {
|
||||
const dataFile = await this.loadData() ?? {};
|
||||
// backwards compat for setting
|
||||
if (dataFile.openNewTabsInOtherTabGroup !== undefined) {
|
||||
dataFile.newTabTabGroupPlacement = dataFile.openNewTabsInOtherTabGroup ? 'last' : 'same';
|
||||
delete dataFile.openNewTabsInOtherTabGroup;
|
||||
}
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, dataFile);
|
||||
|
||||
if (Object.keys(dataFile).length == 0) {
|
||||
|
|
|
|||
|
|
@ -15,10 +15,16 @@ export const NEW_TAB_TAB_GROUP_PLACEMENTS = {
|
|||
"last": "In last tab group",
|
||||
};
|
||||
|
||||
export const MOD_CLICK_BEHAVIOR = {
|
||||
"tab": "In new tab",
|
||||
"same": "In same tab",
|
||||
"allow-duplicate": "In duplicate tab",
|
||||
}
|
||||
|
||||
export interface OpenTabSettingsPluginSettings {
|
||||
openInNewTab: boolean,
|
||||
deduplicateTabs: boolean,
|
||||
openInSameTabOnModClick: boolean,
|
||||
modClickBehavior: keyof typeof MOD_CLICK_BEHAVIOR,
|
||||
newTabPlacement: keyof typeof NEW_TAB_PLACEMENTS,
|
||||
newTabTabGroupPlacement: "same"|"opposite"|"first"|"last",
|
||||
}
|
||||
|
|
@ -26,7 +32,7 @@ export interface OpenTabSettingsPluginSettings {
|
|||
export const DEFAULT_SETTINGS: OpenTabSettingsPluginSettings = {
|
||||
openInNewTab: true,
|
||||
deduplicateTabs: true,
|
||||
openInSameTabOnModClick: false,
|
||||
modClickBehavior: "tab",
|
||||
newTabPlacement: "after-active",
|
||||
newTabTabGroupPlacement: "same",
|
||||
}
|
||||
|
|
@ -41,14 +47,6 @@ export class OpenTabSettingsPluginSettingTab extends PluginSettingTab {
|
|||
|
||||
display(): void {
|
||||
this.containerEl.empty();
|
||||
|
||||
const update = () => {
|
||||
openInSameTabOnModClickSetting.settingEl.setCssStyles({
|
||||
opacity: this.plugin.settings.openInNewTab ? "" : "50%",
|
||||
});
|
||||
openInSameTabOnModClickSetting.setDisabled(!this.plugin.settings.openInNewTab);
|
||||
}
|
||||
|
||||
new Setting(this.containerEl)
|
||||
.setName('Always open in new tab')
|
||||
.setDesc('Open files in a new tab by default.')
|
||||
|
|
@ -56,8 +54,12 @@ export class OpenTabSettingsPluginSettingTab extends PluginSettingTab {
|
|||
toggle
|
||||
.setValue(this.plugin.settings.openInNewTab)
|
||||
.onChange(async (value) => {
|
||||
await this.plugin.updateSettings({openInNewTab: value});
|
||||
update();
|
||||
const modClickBehavior = this.plugin.settings.modClickBehavior;
|
||||
await this.plugin.updateSettings({
|
||||
openInNewTab: value,
|
||||
modClickBehavior: (!value && modClickBehavior == "same") ? "tab" : modClickBehavior,
|
||||
});
|
||||
this.display();
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -68,22 +70,35 @@ export class OpenTabSettingsPluginSettingTab extends PluginSettingTab {
|
|||
toggle
|
||||
.setValue(this.plugin.settings.deduplicateTabs)
|
||||
.onChange(async (value) => {
|
||||
await this.plugin.updateSettings({deduplicateTabs: value});
|
||||
const modClickBehavior = this.plugin.settings.modClickBehavior;
|
||||
await this.plugin.updateSettings({
|
||||
deduplicateTabs: value,
|
||||
modClickBehavior: (!value && modClickBehavior == "allow-duplicate") ? "tab" : modClickBehavior,
|
||||
});
|
||||
this.display();
|
||||
})
|
||||
);
|
||||
|
||||
const openInSameTabOnModClickSetting = new Setting(this.containerEl)
|
||||
.setName('Open in same tab on ctrl/middle click')
|
||||
.setDesc(
|
||||
'When "Always open in new tab" is enabled, open in same tab when using Ctrl click or middle click.'
|
||||
)
|
||||
.addToggle(toggle =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.openInSameTabOnModClick)
|
||||
.onChange(async (value) => {
|
||||
await this.plugin.updateSettings({openInSameTabOnModClick: value});
|
||||
new Setting(this.containerEl)
|
||||
.setName('Mod click behavior')
|
||||
.setDesc('On Ctrl/Cmd/middle click open links...')
|
||||
.addDropdown(dropdown => {
|
||||
dropdown.addOption("tab", MOD_CLICK_BEHAVIOR['tab']);
|
||||
if (this.plugin.settings.openInNewTab) {
|
||||
dropdown.addOption("same", MOD_CLICK_BEHAVIOR['same'])
|
||||
}
|
||||
if (this.plugin.settings.deduplicateTabs) {
|
||||
dropdown.addOption("allow-duplicate", MOD_CLICK_BEHAVIOR['allow-duplicate'])
|
||||
}
|
||||
dropdown
|
||||
.setValue(this.plugin.settings.modClickBehavior)
|
||||
.onChange(async value => {
|
||||
console.log("modClickBehavior onChange")
|
||||
await this.plugin.updateSettings({
|
||||
modClickBehavior: value as keyof typeof MOD_CLICK_BEHAVIOR,
|
||||
});
|
||||
})
|
||||
);
|
||||
})
|
||||
|
||||
new Setting(this.containerEl)
|
||||
.setName('Focus explicit new tabs')
|
||||
|
|
@ -127,7 +142,5 @@ export class OpenTabSettingsPluginSettingTab extends PluginSettingTab {
|
|||
});
|
||||
})
|
||||
);
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { obsidianPage } from 'wdio-obsidian-service';
|
|||
describe('Misc', function() {
|
||||
beforeEach(async function() {
|
||||
await workspacePage.loadPlatformWorkspaceLayout("empty");
|
||||
await workspacePage.setSettings({ openInNewTab: true, deduplicateTabs: true, openInSameTabOnModClick: true });
|
||||
await workspacePage.setSettings({ openInNewTab: true, deduplicateTabs: true });
|
||||
});
|
||||
|
||||
it('should update focusNewTab on boot', async function() {
|
||||
|
|
@ -61,11 +61,11 @@ describe("Mod click", function() {
|
|||
})
|
||||
beforeEach(async function() {
|
||||
await workspacePage.loadPlatformWorkspaceLayout("empty");
|
||||
await workspacePage.setSettings({ openInNewTab: true, deduplicateTabs: true, openInSameTabOnModClick: true });
|
||||
await workspacePage.setSettings({ openInNewTab: true, deduplicateTabs: true });
|
||||
});
|
||||
|
||||
it('Test mod click', async function() {
|
||||
await workspacePage.setSettings({ openInSameTabOnModClick: true });
|
||||
it('Test mod click same', async function() {
|
||||
await workspacePage.setSettings({ modClickBehavior: "same" });
|
||||
await workspacePage.openFile("A.md");
|
||||
await (await workspacePage.getLink("B")).click({"button": "middle"});
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ describe("Mod click", function() {
|
|||
});
|
||||
|
||||
it('Test mod click off', async function() {
|
||||
await workspacePage.setSettings({ openInSameTabOnModClick: false });
|
||||
await workspacePage.setSettings({ modClickBehavior: "tab" });
|
||||
await workspacePage.openFile("A.md");
|
||||
await (await workspacePage.getLink("B")).click({"button": "middle"});
|
||||
|
||||
|
|
@ -85,24 +85,16 @@ describe("Mod click", function() {
|
|||
]]);
|
||||
});
|
||||
|
||||
it('Test mod click no new tab', async function() {
|
||||
await workspacePage.setSettings({ openInNewTab: false, openInSameTabOnModClick: true });
|
||||
it('Test mod click duplicate', async function() {
|
||||
await workspacePage.setSettings({ deduplicateTabs: true, modClickBehavior: "allow-duplicate" });
|
||||
|
||||
await workspacePage.openFile("B.md");
|
||||
await workspacePage.openFile("A.md");
|
||||
await (await workspacePage.getLink("B")).click({"button": "middle"});
|
||||
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "B.md"},
|
||||
{type: "markdown", file: "A.md"},
|
||||
{type: "markdown", file: "B.md", active: true},
|
||||
]]);
|
||||
});
|
||||
|
||||
it('Test mod new tab disabled', async function() {
|
||||
await workspacePage.setSettings({ openInNewTab: false, openInSameTabOnModClick: true });
|
||||
await workspacePage.openFile("A.md");
|
||||
await (await workspacePage.getLink("B")).click({"button": "middle"});
|
||||
|
||||
await workspacePage.matchWorkspace([[
|
||||
{type: "markdown", file: "A.md"}, {type: "markdown", file: "B.md"},
|
||||
]]);
|
||||
});
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue