Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
V1
  • Loading branch information
huachuman authored Nov 3, 2024
0 parents commit 8d295d2
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 0 deletions.
101 changes: 101 additions & 0 deletions pane-zoom-levels/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const { Plugin } = require('obsidian');

class PaneZoomLevelsPlugin extends Plugin {
async onload() {
this.zoomLevels = new Map();

// Add command to set zoom level
this.addCommand({
id: 'set-pane-zoom',
name: 'Set Zoom Level for Current Pane',
callback: async () => {
const leaf = this.app.workspace.activeLeaf;
if (!leaf) return;

const zoomLevels = ['zoom-10', 'zoom-20', 'zoom-30', 'zoom-40', 'zoom-50', 'zoom-60', 'zoom-70', 'zoom-80', 'zoom-90','zoom-100'];
const selected = await this.showZoomSelector(zoomLevels);

if (selected) {
this.setZoomForPane(leaf, selected);
}
}
});

// Register for layout change events
this.registerEvent(
this.app.workspace.on('layout-change', () => {
this.reapplyZoomLevels();
})
);

// Register for file open events
this.registerEvent(
this.app.workspace.on('file-open', () => {
this.reapplyZoomLevels();
})
);
}

async showZoomSelector(options) {
const modal = new ZoomSelectorModal(this.app, options);
return new Promise(resolve => {
modal.onChooseItem = (item) => {
resolve(item);
modal.close();
};
modal.open();
});
}

setZoomForPane(leaf, zoomClass) {
const leafId = leaf.id;

// Remove any existing zoom classes
const container = leaf.view.containerEl;
container.classList.remove('zoom-10', 'zoom-20', 'zoom-30', 'zoom-40', 'zoom-50', 'zoom-60', 'zoom-70', 'zoom-80', 'zoom-90','zoom-100');

// Add new zoom class
container.classList.add(zoomClass);

// Store the zoom level for this pane
this.zoomLevels.set(leafId, zoomClass);
}

reapplyZoomLevels() {
this.app.workspace.iterateAllLeaves(leaf => {
const zoomClass = this.zoomLevels.get(leaf.id);
if (zoomClass) {
leaf.view.containerEl.classList.remove('zoom-10', 'zoom-20', 'zoom-30', 'zoom-40', 'zoom-50', 'zoom-60', 'zoom-70', 'zoom-80', 'zoom-90','zoom-100');
leaf.view.containerEl.classList.add(zoomClass);
}
});
}

onunload() {
// Remove all zoom classes when plugin is disabled
this.app.workspace.iterateAllLeaves(leaf => {
leaf.view.containerEl.classList.remove('zoom-10', 'zoom-20', 'zoom-30', 'zoom-40', 'zoom-50', 'zoom-60', 'zoom-70', 'zoom-80', 'zoom-90','zoom-100');
});
}
}

class ZoomSelectorModal extends require('obsidian').FuzzySuggestModal {
constructor(app, options) {
super(app);
this.options = options;
}

getItems() {
return this.options;
}

getItemText(item) {
return item.replace('zoom-', '') + '%';
}

onChooseItem(item) {
return item;
}
}

module.exports = PaneZoomLevelsPlugin;
9 changes: 9 additions & 0 deletions pane-zoom-levels/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "pane-zoom-levels",
"name": "Pane Zoom Levels",
"version": "1.0.0",
"minAppVersion": "0.15.0",
"description": "Set different zoom levels for different panes",
"author": "Your Name",
"isDesktopOnly": false
}
49 changes: 49 additions & 0 deletions pane-zoom-levels/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Base styles for zoom levels */
.zoom-10, .workspace-leaf-content.zoom-10 .markdown-preview-view, .workspace-leaf-content.zoom-10 .cm-content { font-size: 10% !important; }
.zoom-20, .workspace-leaf-content.zoom-20 .markdown-preview-view, .workspace-leaf-content.zoom-20 .cm-content { font-size: 20% !important; }
.zoom-30, .workspace-leaf-content.zoom-30 .markdown-preview-view, .workspace-leaf-content.zoom-30 .cm-content { font-size: 30% !important; }
.zoom-40, .workspace-leaf-content.zoom-40 .markdown-preview-view, .workspace-leaf-content.zoom-40 .cm-content { font-size: 40% !important; }
.zoom-50, .workspace-leaf-content.zoom-50 .markdown-preview-view, .workspace-leaf-content.zoom-50 .cm-content { font-size: 50% !important; }
.zoom-60, .workspace-leaf-content.zoom-60 .markdown-preview-view, .workspace-leaf-content.zoom-60 .cm-content { font-size: 60% !important; }
.zoom-70, .workspace-leaf-content.zoom-70 .markdown-preview-view, .workspace-leaf-content.zoom-70 .cm-content { font-size: 70% !important; }
.zoom-80, .workspace-leaf-content.zoom-80 .markdown-preview-view, .workspace-leaf-content.zoom-80 .cm-content { font-size: 80% !important; }
.zoom-90, .workspace-leaf-content.zoom-90 .markdown-preview-view, .workspace-leaf-content.zoom-90 .cm-content { font-size: 90% !important; }
.zoom-100, .workspace-leaf-content.zoom-100 .markdown-preview-view, .workspace-leaf-content.zoom-100 .cm-content { font-size: 100% !important; }

/* Heading styles using em units with increased specificity */
.workspace-leaf-content[class*="zoom-"] .markdown-preview-view h1,
.workspace-leaf-content[class*="zoom-"] .cm-header-1 {
font-size: 2em !important;
}
.workspace-leaf-content[class*="zoom-"] .markdown-preview-view h2,
.workspace-leaf-content[class*="zoom-"] .cm-header-2 {
font-size: 1.5em !important;
}
.workspace-leaf-content[class*="zoom-"] .markdown-preview-view h3,
.workspace-leaf-content[class*="zoom-"] .cm-header-3 {
font-size: 1.3em !important;
}
.workspace-leaf-content[class*="zoom-"] .markdown-preview-view h4,
.workspace-leaf-content[class*="zoom-"] .cm-header-4 {
font-size: 1.2em !important;
}
.workspace-leaf-content[class*="zoom-"] .markdown-preview-view h5,
.workspace-leaf-content[class*="zoom-"] .cm-header-5 {
font-size: 1.1em !important;
}
.workspace-leaf-content[class*="zoom-"] .markdown-preview-view h6,
.workspace-leaf-content[class*="zoom-"] .cm-header-6 {
font-size: 1em !important;
}

/* Styles for .cm-lapel with absolute scaling */
.workspace-leaf-content.zoom-10 .cm-lapel { font-size: 11px !important; }
.workspace-leaf-content.zoom-20 .cm-lapel { font-size: 11px !important; }
.workspace-leaf-content.zoom-30 .cm-lapel { font-size: 11px !important; }
.workspace-leaf-content.zoom-40 .cm-lapel { font-size: 11px !important; }
.workspace-leaf-content.zoom-50 .cm-lapel { font-size: 11px !important; }
.workspace-leaf-content.zoom-60 .cm-lapel { font-size: 12px !important; }
.workspace-leaf-content.zoom-70 .cm-lapel { font-size: 13px !important; }
.workspace-leaf-content.zoom-80 .cm-lapel { font-size: 14px !important; }
.workspace-leaf-content.zoom-90 .cm-lapel { font-size: 15px !important; }
.workspace-leaf-content.zoom-100 .cm-lapel { font-size: 16px !important; }

0 comments on commit 8d295d2

Please sign in to comment.