generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
67 lines (58 loc) · 2.12 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {Plugin, WorkspaceLeaf, WorkspaceSidedock} from 'obsidian';
export default class CycleInSidebarPlugin extends Plugin {
getLeavesOfSidebar(split: WorkspaceSidedock) {
const oneSideSplitRoot = split.getRoot()
const leaves : WorkspaceLeaf[] = []
this.app.workspace.iterateAllLeaves(l => { leaves.push(l) })
const leavesInOneSide = leaves
.filter(l => l.getRoot() === oneSideSplitRoot)
.filter(l => l.view.getViewType() !== 'empty');
if (leavesInOneSide.length == 0) return leaves;
// filter only first container (if top/ bottom views)
const parent = leavesInOneSide[0].parent
return leavesInOneSide.filter(l => l.parent == parent);
}
isSidebarOpen (split: WorkspaceSidedock) {
return this.getLeavesOfSidebar(split).some(l => l.view.containerEl.clientHeight > 0)
}
cycleInSideBar (split: WorkspaceSidedock, offset: number) {
const leaves = this.getLeavesOfSidebar(split)
var currentIndex = 0;
for (currentIndex = 0; currentIndex < leaves.length; currentIndex++) {
if (leaves[currentIndex].view.containerEl.clientHeight > 0) break;
}
if (currentIndex == leaves.length) return;
const nextIndex = ((currentIndex + offset) < 0 ? (leaves.length - 1) : (currentIndex + offset)) % leaves.length;
this.app.workspace.revealLeaf(leaves[nextIndex]);
}
async cycleRightSideBar (offset: number) {
this.cycleInSideBar(this.app.workspace.rightSplit, offset);
}
async cycleLeftSideBar (offset: number) {
this.cycleInSideBar(this.app.workspace.leftSplit, offset);
}
async onload() {
this.addCommand({
id: 'cycle-right-sidebar',
name: 'Cycle tabs of right sidebar',
callback: () => { this.cycleRightSideBar(1) }
});
this.addCommand({
id: 'cycle-right-sidebar-reverse',
name: 'Cycle tabs of right sidebar in reverse',
callback: () => { this.cycleRightSideBar(-1) }
});
this.addCommand({
id: 'cycle-left-sidebar',
name: 'Cycle tabs of left sidebar',
callback: () => { this.cycleLeftSideBar(1) }
});
this.addCommand({
id: 'cycle-left-sidebar-reverse',
name: 'Cycle tabs of left sidebar in reverse',
callback: () => { this.cycleLeftSideBar(-1) }
});
}
onunload() {
}
}