Skip to content

Commit

Permalink
fix issue with sidebar (close #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Dec 19, 2020
1 parent 40edc33 commit e8ae84b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
42 changes: 23 additions & 19 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { App, Modal, Notice, Plugin, PluginSettingTab, Setting, WorkspaceLeaf, View } from 'obsidian';
import { App, MarkdownView, Plugin, WorkspaceLeaf } from 'obsidian';

export default class CycleThroughPanes extends Plugin {
onload() {
console.log('loading plugin: Cycle through panes');
onload() {
console.log('loading plugin: Cycle through panes');

this.addCommand({
this.addCommand({
id: 'cycle-through-panes',
name: 'Cycle through panes',
callback: () => {
let active = this.app.workspace.activeLeaf;
let leafs: WorkspaceLeaf[] = []
this.app.workspace.iterateAllLeaves((leaf) => {
if (leaf.getViewState().type == "markdown")
leafs.push(leaf);
if (leaf.getViewState().type == "markdown") {
if (leaf.getRoot() === this.app.workspace.rootSplit)
leafs.push(leaf);
}
})
let index = leafs.indexOf(active);
if (index == leafs.length - 1) {
this.app.workspace.setActiveLeaf(leafs[0]);
fixCursor(leafs[0]);
setActiveLeaf(leafs[0], this.app)
}
else {
this.app.workspace.setActiveLeaf(leafs[index + 1])
fixCursor(leafs[index + 1])
setActiveLeaf(leafs[index + 1], this.app)
}

}, hotkeys: [
Expand All @@ -32,6 +32,11 @@ export default class CycleThroughPanes extends Plugin {
]

});
function setActiveLeaf(newLeaf: WorkspaceLeaf, app: App) {
app.workspace.setActiveLeaf(newLeaf)
fixCursor(newLeaf)
}

function fixCursor(newLeaf: WorkspaceLeaf) {
let view = newLeaf.view as MarkdownView;
let editor = view.sourceMode.cmEditor;
Expand All @@ -46,16 +51,15 @@ export default class CycleThroughPanes extends Plugin {
let leafs: WorkspaceLeaf[] = []
this.app.workspace.iterateAllLeaves((leaf) => {
if (leaf.getViewState().type == "markdown")
leafs.push(leaf);
if (leaf.getRoot() === this.app.workspace.rootSplit)
leafs.push(leaf);
})
let index = leafs.indexOf(active);
if (index == 0) {
this.app.workspace.setActiveLeaf(leafs[leafs.length - 1])
fixCursor(leafs[leafs.length - 1])
setActiveLeaf(leafs[leafs.length - 1], this.app)
}
else {
this.app.workspace.setActiveLeaf(leafs[index - 1])
fixCursor(leafs[index - 1])
setActiveLeaf(leafs[index - 1], this.app)
}

}, hotkeys: [
Expand All @@ -67,9 +71,9 @@ export default class CycleThroughPanes extends Plugin {

});

}
}

onunload() {
console.log('unloading plugin: Cycle through panes');
}
onunload() {
console.log('unloading plugin: Cycle through panes');
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "cycle-through-panes",
"name": "Cycle through Panes",
"version": "0.0.3",
"version": "0.0.4",
"minAppVersion": "0.9.7",
"description": "Cycle through your open Panes with `ctrl + Tab`, just like with Tabs in your Browser!, ctrl+shift+Tab for Reverse",
"author": "Vinadon & Rythm",
Expand Down

0 comments on commit e8ae84b

Please sign in to comment.