Skip to content

Commit 1d89929

Browse files
committed
tweak: move document history buttons to top left corner
1 parent 15ca5b8 commit 1d89929

7 files changed

Lines changed: 87 additions & 87 deletions

File tree

src/view/components/container/modals/snapshots-list/file-histoy.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
const history = historyStore(view)
99
</script>
1010

11-
<div class="lineage-modal" style="padding-left: 0; padding-right:0" tabindex="0">
11+
<div class="lineage-modal snapshots-modal" style="padding-left: 0; padding-right:0" tabindex="0">
1212
<div
1313
class="snapshots-list"
1414
use:updateRelativeTime
@@ -37,6 +37,10 @@
3737
padding-left: var(--size-4-2);
3838
padding-right: var(--size-4-2);
3939
}
40+
.snapshots-modal{
41+
left: var(--size-4-2);
42+
top: 50px;
43+
}
4044
@media (max-width: 720px) {
4145
.snapshots-list {
4246
width: initial;

src/view/components/container/toolbar-vertical/vertical-toolbar-actions.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
11
import { LineageView } from 'src/view/view';
2-
import { Notice } from 'obsidian';
3-
import { lang } from 'src/lang/lang';
42

53
export class VerticalToolbarActions {
64
constructor(private view: LineageView) {}
75

8-
handleNextClick = () => {
9-
if (this.view.viewStore.getValue().document.editing.activeNodeId)
10-
new Notice(lang.error_apply_snapshot_while_editing);
11-
else
12-
this.view.documentStore.dispatch({
13-
type: 'HISTORY/APPLY_NEXT_SNAPSHOT',
14-
});
15-
};
16-
17-
handlePreviousClick = () => {
18-
if (this.view.viewStore.getValue().document.editing.activeNodeId)
19-
new Notice(lang.error_apply_snapshot_while_editing);
20-
else
21-
this.view.documentStore.dispatch({
22-
type: 'HISTORY/APPLY_PREVIOUS_SNAPSHOT',
23-
});
24-
};
25-
266
toggleHelp = () => {
277
this.view.viewStore.dispatch({ type: 'UI/TOGGLE_HELP_SIDEBAR' });
288
};
@@ -63,11 +43,6 @@ export class VerticalToolbarActions {
6343
});
6444
};
6545

66-
toggleSnapshotsModal = () =>
67-
this.view.viewStore.dispatch({
68-
type: 'UI/TOGGLE_HISTORY_SIDEBAR',
69-
});
70-
7146
zoomIn = () => {
7247
this.view.plugin.settings.dispatch({
7348
type: 'UI/CHANGE_ZOOM_LEVEL',

src/view/components/container/toolbar-vertical/vertical-toolbar-buttons-list.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import { derived } from 'svelte/store';
44
import { ToolbarButton } from 'src/view/modals/vertical-toolbar-buttons/vertical-toolbar-buttons';
55
import { lang } from 'src/lang/lang';
66
import {
7-
HistoryIcon,
87
Keyboard,
98
Palette,
109
PanelRightInactive as PanelRight,
11-
Redo2 as RedoIcon,
1210
Settings,
13-
Undo2 as UndoIcon,
1411
} from 'lucide-svelte';
1512
import { CustomIcon, customIcons } from 'src/helpers/load-custom-icons';
1613
import { VerticalToolbarActions } from 'src/view/components/container/toolbar-vertical/vertical-toolbar-actions';
@@ -100,29 +97,6 @@ export const VerticalToolbarButtonsList = (view: LineageView) => {
10097
},
10198
],
10299
},
103-
{
104-
id: 'history',
105-
buttons: [
106-
{
107-
label: lang.controls_history,
108-
onClick: h.toggleSnapshotsModal,
109-
icon: HistoryIcon,
110-
id: 'snapshots-list',
111-
},
112-
{
113-
label: lang.controls_history_undo,
114-
onClick: h.handlePreviousClick,
115-
icon: UndoIcon,
116-
id: 'undo',
117-
},
118-
{
119-
label: lang.controls_history_redo,
120-
onClick: h.handleNextClick,
121-
icon: RedoIcon,
122-
id: 'redo',
123-
},
124-
],
125-
},
126100
];
127101

128102
return buttons

src/view/components/container/toolbar-vertical/vertical-toolbar.svelte

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { lang } from '../../../../lang/lang';
33
import { MoreVertical } from 'lucide-svelte';
44
import { getView } from '../context';
5-
import { historyStore } from '../../../../stores/document/derived/history-store';
65
import { derived, writable } from 'svelte/store';
76
import { uiControlsStore } from '../../../../stores/view/derived/ui-controls-store';
87
import Button from '../shared/button.svelte';
@@ -16,7 +15,7 @@
1615
1716
const view = getView();
1817
19-
const history = historyStore(view);
18+
2019
2120
const showControls = writable(false);
2221
const toggleShowControls = () => {
@@ -58,13 +57,7 @@
5857
},
5958
);
6059
61-
const disabledStates = derived([history], ([history]) => {
62-
return {
63-
'snapshots-list': history.items.length === 0,
64-
undo: !history.state.canGoBack,
65-
redo: !history.state.canGoForward,
66-
} as Partial<Record<ToolbarButton, boolean>>;
67-
});
60+
6861
</script>
6962

7063
<div class="controls-container">
@@ -91,7 +84,7 @@
9184
label={button.label}
9285
on:click={button.onClick}
9386
tooltipPosition="left"
94-
disabled={$disabledStates[button.id]}
87+
9588
>
9689
{#if 'svg' in button.icon}
9790
{@html button.icon.svg}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<script lang="ts">
2+
import { lang } from '../../../../../lang/lang';
3+
import { HistoryIcon, Redo2 as RedoIcon, Undo2 as UndoIcon } from 'lucide-svelte';
4+
import Button from '../../shared/button.svelte';
5+
import { historyStore } from '../../../../../stores/document/derived/history-store';
6+
import { getView } from '../../context';
7+
import { Notice } from 'obsidian';
8+
import { LineageView } from 'src/view/view';
9+
10+
const view = getView();
11+
const history = historyStore(view);
12+
13+
const isEditing = (view: LineageView) =>
14+
view.viewStore.getValue().document.editing.activeNodeId;
15+
16+
const toggleSnapshotsModal = () =>
17+
view.viewStore.dispatch({
18+
type: 'UI/TOGGLE_HISTORY_SIDEBAR',
19+
});
20+
21+
const selectNextSnapshot = () => {
22+
if (isEditing(view))
23+
new Notice(lang.error_apply_snapshot_while_editing);
24+
else
25+
view.documentStore.dispatch({
26+
type: 'HISTORY/APPLY_NEXT_SNAPSHOT',
27+
});
28+
};
29+
30+
const selectPreviousSnapshot = () => {
31+
if (isEditing(view))
32+
new Notice(lang.error_apply_snapshot_while_editing);
33+
else
34+
view.documentStore.dispatch({
35+
type: 'HISTORY/APPLY_PREVIOUS_SNAPSHOT',
36+
});
37+
};
38+
</script>
39+
40+
<div class="navigation-history buttons-group">
41+
<Button
42+
disabled={$history.items.length === 0}
43+
label={lang.controls_history}
44+
on:click={toggleSnapshotsModal}
45+
tooltipPosition="bottom"
46+
>
47+
<HistoryIcon class="svg-icon" size="12" />
48+
</Button>
49+
<Button
50+
disabled={!$history.state.canGoBack}
51+
label={lang.controls_history_undo}
52+
on:click={selectPreviousSnapshot}
53+
tooltipPosition="bottom"
54+
>
55+
<UndoIcon class="svg-icon" size="12" />
56+
</Button>
57+
<Button
58+
disabled={!$history.state.canGoForward}
59+
label={lang.controls_history_redo}
60+
on:click={selectNextSnapshot}
61+
tooltipPosition="bottom"
62+
>
63+
<RedoIcon class="svg-icon" size="12" />
64+
</Button>
65+
</div>
66+
67+
<style>
68+
.navigation-history {
69+
display: flex;
70+
align-items: center;
71+
justify-content: center;
72+
}
73+
</style>

src/view/components/container/toolbar/toolbar.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import SearchInput from './components/search-input.svelte';
77
import LeftSidebarToggle from './components/left-sidebar-toggle.svelte';
88
import SearchNavigationButtons from './components/search/search-navigation-buttons.svelte';
9+
import DocumentHistoryButtons from './components/document-history-buttons.svelte';
910
1011
const view = getView();
1112
@@ -15,14 +16,16 @@
1516
<div class="navigation-history-container">
1617
<LeftSidebarToggle />
1718
<NavigationHistory />
19+
<DocumentHistoryButtons />
1820
<SearchToggle />
1921
{#if $search.showInput}
2022
<SearchInput />
2123
{#if $search.query.length > 0}
22-
<SearchNavigationButtons results={Array.from($search.results)}/>
24+
<SearchNavigationButtons results={Array.from($search.results)} />
2325
{/if}
2426
{/if}
2527
</div>
28+
2629
<style>
2730
.navigation-history-container {
2831
z-index: var(--z-index-breadcrumbs);
@@ -32,6 +35,6 @@
3235
position: absolute;
3336
gap: var(--size-4-2);
3437
flex-wrap: wrap;
35-
max-width: 90%
38+
max-width: 90%;
3639
}
3740
</style>

src/view/modals/vertical-toolbar-buttons/vertical-toolbar-buttons.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { lang } from 'src/lang/lang';
22
import {
3-
HistoryIcon,
43
Keyboard,
54
Minus as ZoomOut,
65
Palette,
76
PanelRightInactive as PanelRight,
87
Plus as ZoomIn,
9-
Redo2 as RedoIcon,
108
RotateCcw,
119
ScanSearch,
12-
Undo2 as UndoIcon,
1310
} from 'lucide-svelte';
1411
import { CustomIcon, customIcons } from 'src/helpers/load-custom-icons';
1512

@@ -87,26 +84,7 @@ export const verticalToolbarButtons: VerticalToolbarGroup[] = [
8784
},
8885
],
8986
},
90-
{
91-
id: 'history',
92-
buttons: [
93-
{
94-
id: 'snapshots-list',
95-
label: lang.controls_history,
96-
icon: HistoryIcon,
97-
},
98-
{
99-
id: 'undo',
100-
label: lang.controls_history_undo,
101-
icon: UndoIcon,
102-
},
103-
{
104-
id: 'redo',
105-
label: lang.controls_history_redo,
106-
icon: RedoIcon,
107-
},
108-
],
109-
},
87+
11088
{
11189
id: 'zoom',
11290
buttons: [

0 commit comments

Comments
 (0)