Skip to content

Commit

Permalink
fix #5 + bump version to 0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Feb 24, 2021
1 parent b7b0acb commit 50aa42c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,62 @@ export default class CycleThroughPanes extends Plugin {
name: 'Cycle through panes',
callback: () => {
let active = this.app.workspace.activeLeaf;
let leafs: WorkspaceLeaf[] = []
let leafs: WorkspaceLeaf[] = [];
this.app.workspace.iterateAllLeaves((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) {
setActiveLeaf(leafs[0], this.app)
setActiveLeaf(leafs[0], this.app);
}
else {
setActiveLeaf(leafs[index + 1], this.app)
setActiveLeaf(leafs[index + 1], this.app);
}

}, hotkeys: [
{
modifiers: ["Mod"],
modifiers: ["Ctrl"],
key: "Tab"
}
]

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

function fixCursor(newLeaf: WorkspaceLeaf) {
let view = newLeaf.view as MarkdownView;
let editor = view.sourceMode.cmEditor;
editor.focus()
editor.focus();
}

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

}, hotkeys: [
{
modifiers: ["Mod", "Shift"],
modifiers: ["Ctrl", "Shift"],
key: "Tab"
}
]
Expand All @@ -75,18 +75,18 @@ export default class CycleThroughPanes extends Plugin {
this.app.workspace.on("file-open", () => {
//use just markdown panes
if (this.app.workspace.activeLeaf.getViewState().type != "markdown") {
return
return;
}
//if a file gets opened in current pane
if (this.lastPanes?.last() == this.app.workspace.activeLeaf.id) {
return;
}
//keep a history of 10 panes
if (this.lastPanes.length > 10) {
this.lastPanes.splice(0, 1)
this.lastPanes.splice(0, 1);
}
//add current pane to history
this.lastPanes.push(this.app.workspace.activeLeaf.id)
this.lastPanes.push(this.app.workspace.activeLeaf.id);
});

this.addCommand({
Expand Down
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.5",
"version": "0.0.6",
"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 50aa42c

Please sign in to comment.