Skip to content

Commit b7278b4

Browse files
committed
enhance: link pane type setting
1 parent c0220a0 commit b7278b4

12 files changed

Lines changed: 112 additions & 21 deletions

File tree

src/lang/lang.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ export const lang = {
303303
settings_layout: 'Layout',
304304
settings_reset: 'Reset',
305305

306+
// general settings
307+
settings_general_link_split: 'Open in a new split',
308+
settings_general_link_tab: 'Open in a new tab',
309+
settings_general_link_behavior: 'Default link behavior',
310+
306311
// hotkeys
307312
modals_hk_input_placeholder: 'Filter',
308313
modals_hk_editor_cancel: 'Cancel',

src/stores/settings/default-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const DEFAULT_SETTINGS = (): Settings => ({
3737
},
3838
general: {
3939
defaultDocumentFormat: 'sections',
40+
linkPaneType: 'tab',
4041
},
4142
styleRules: {
4243
documents: {},

src/stores/settings/settings-reducer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
DocumentPreferences,
44
LeftSidebarTab,
55
LineageDocumentFormat,
6+
LinkPaneType,
67
RulesTab,
78
Settings,
89
ViewType,
@@ -188,6 +189,12 @@ export type SettingsActions =
188189
id: ToolbarButton;
189190
hide: boolean;
190191
};
192+
}
193+
| {
194+
type: 'settings/general/set-link-pane-type';
195+
payload: {
196+
position: LinkPaneType;
197+
};
191198
};
192199

193200
export type PersistCollapsedSectionsAction = {
@@ -452,6 +459,8 @@ const updateState = (store: Settings, action: SettingsActions) => {
452459
}
453460
} else if (action.type === 'settings/style-rules/set-active-tab') {
454461
store.styleRules.settings.activeTab = action.payload.tab;
462+
} else if (action.type === 'settings/general/set-link-pane-type') {
463+
store.general.linkPaneType = action.payload.position;
455464
} else if (action.type.startsWith('settings/style-rules')) {
456465
updateStyleRules(store, action);
457466
}

src/stores/settings/settings-type.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type LeftSidebarTab = 'pinned-cards' | 'recent-cards';
4141

4242
export type RulesTab = 'global-rules' | 'document-rules';
4343

44+
export type LinkPaneType = 'split' | 'tab';
4445
export type Settings = {
4546
documents: Record<string, DocumentPreferences>;
4647
hotkeys: {
@@ -69,6 +70,7 @@ export type Settings = {
6970
};
7071
general: {
7172
defaultDocumentFormat: LineageDocumentFormat;
73+
linkPaneType: LinkPaneType;
7274
};
7375
styleRules: {
7476
documents: { [path: string]: { rules: StyleRule[] } };
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { SettingsStore } from 'src/main';
2+
import { Setting } from 'obsidian';
3+
import { LinkPaneType as TLinkPaneType } from 'src/stores/settings/settings-type';
4+
import { lang } from 'src/lang/lang';
5+
import { isMacLike } from 'src/view/actions/keyboard-shortcuts/helpers/keyboard-events/mod-key';
6+
7+
export const LinkPaneType = (
8+
element: HTMLElement,
9+
settingsStore: SettingsStore,
10+
) => {
11+
const settingsState = settingsStore.getValue();
12+
const setting = new Setting(element).setName(
13+
lang.settings_general_link_behavior,
14+
);
15+
setting.setDesc(
16+
`Press '${isMacLike ? 'cmd' : 'control'}' to use the other option`,
17+
);
18+
setting.addDropdown((cb) => {
19+
const value = settingsState.general.linkPaneType;
20+
21+
cb.addOptions({
22+
split: lang.settings_general_link_split,
23+
tab: lang.settings_general_link_tab,
24+
} satisfies Record<TLinkPaneType, string>)
25+
.setValue(value)
26+
.onChange((value) => {
27+
settingsStore.dispatch({
28+
type: 'settings/general/set-link-pane-type',
29+
payload: {
30+
position: value as TLinkPaneType,
31+
},
32+
});
33+
});
34+
});
35+
};

src/view/actions/settings/render-settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import { ActiveBranchColor } from 'src/view/actions/settings/components/active-b
1515
import { AlwaysShowCardButtons } from 'src/view/actions/settings/components/always-show-card-buttons';
1616
import { ControlsBarButtons } from 'src/view/actions/settings/components/controls-bar-buttons/controls-bar-buttons';
1717
import { HeadingsFontSize } from 'src/view/actions/settings/components/headings-font-size';
18+
import { LinkPaneType } from 'src/view/actions/settings/components/link-pane-type';
1819

1920
export const renderSettings = (element: HTMLElement) => {
2021
const view = getView();
2122
const settingsStore = view.plugin.settings;
2223
const render = () => {
2324
DefaultDocumentFormat(element, settingsStore);
25+
LinkPaneType(element, settingsStore);
2426
MaintainEditMode(element, settingsStore);
2527
AlwaysShowCardButtons(element, settingsStore);
2628
ControlsBarButtons(element, view);

src/view/components/container/column/components/group/components/card/components/content/event-handlers/handle-links/block-link/handle-block-link.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { LineageView } from 'src/view/view';
22
import { handleLocalBlockLink } from 'src/view/components/container/column/components/group/components/card/components/content/event-handlers/handle-links/block-link/handle-local-block-link';
33
import { handleGlobalBlockLink } from 'src/view/components/container/column/components/group/components/card/components/content/event-handlers/handle-links/block-link/handle-global-block-link';
44

5-
export const handleBlockLink = (view: LineageView, link: string) => {
5+
export const handleBlockLink = (
6+
view: LineageView,
7+
link: string,
8+
modKey: boolean,
9+
) => {
610
const viewFilePath = view.file!.basename;
711
const match = /(.*)#\^(\S{4,})$/.exec(link);
812
if (match) {
@@ -11,7 +15,7 @@ export const handleBlockLink = (view: LineageView, link: string) => {
1115
if (!file.trim() || file === viewFilePath) {
1216
handleLocalBlockLink(view, id);
1317
} else {
14-
handleGlobalBlockLink(view, link);
18+
handleGlobalBlockLink(view, link, modKey);
1519
}
1620
}
1721
};
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
import { LineageView } from 'src/view/view';
22

3-
export const handleGlobalBlockLink = (view: LineageView, link: string) => {
4-
view.plugin.app.workspace.openLinkText(link, view.file!.basename, 'split');
3+
export const getLinkPaneType = (view: LineageView, modKey: boolean) => {
4+
const linkPaneType = view.plugin.settings.getValue().general.linkPaneType;
5+
if (modKey) {
6+
return linkPaneType === 'tab' ? 'split' : 'tab';
7+
} else {
8+
return linkPaneType;
9+
}
10+
};
11+
12+
export const handleGlobalBlockLink = (
13+
view: LineageView,
14+
link: string,
15+
modKey: boolean,
16+
) => {
17+
view.plugin.app.workspace.openLinkText(
18+
link,
19+
view.file!.basename,
20+
getLinkPaneType(view, modKey),
21+
);
522
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { LineageView } from 'src/view/view';
2+
import { openFileInExistingRightTabGroup } from 'src/view/components/container/column/components/group/components/card/components/content/event-handlers/handle-links/helpers/open-file-in-existing-right-tab-group';
3+
import { getLinkPaneType } from 'src/view/components/container/column/components/group/components/card/components/content/event-handlers/handle-links/block-link/handle-global-block-link';
4+
5+
export const handleFileLink = (
6+
view: LineageView,
7+
link: string,
8+
modKey: boolean,
9+
) => {
10+
const path = view.file?.path;
11+
if (!link || !path) return;
12+
const paneType = getLinkPaneType(view, modKey);
13+
if (paneType === 'tab') {
14+
view.plugin.app.workspace.openLinkText(link, path, 'tab');
15+
} else {
16+
const success = openFileInExistingRightTabGroup(view, link, path);
17+
if (!success) {
18+
view.plugin.app.workspace.openLinkText(link, path, 'split');
19+
}
20+
}
21+
};

src/view/components/container/column/components/group/components/card/components/content/event-handlers/handle-links/file-link/open-file-in-new-split.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)