Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add fliping bias settings #5

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { MarkdownView, Plugin } from "obsidian";
import { OnyxSideButtonSettings, DEFAULT_SETTINGS } from "./settings/settings";
import { OnyxSideButtonSettingsTab } from "./settings/settingsTab";

export default class OnyxSideButton extends Plugin {
settings: OnyxSideButtonSettings;
lastPageY: number;
async onload() {
await this.loadSettings();
this.addSettingTab(new OnyxSideButtonSettingsTab(this.app, this));
this.registerEvent(
this.app.workspace.on("file-open", (_) => {
const viewEl = document.querySelector(".markdown-reading-view") as HTMLElement;
Expand All @@ -24,11 +29,19 @@ export default class OnyxSideButton extends Plugin {
);
}

async loadSettings(): Promise<void> {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

async saveSettings(): Promise<void> {
await this.saveData(this.settings);
}

flip(mode: string) {
const thisView = this.app.workspace.getActiveViewOfType(MarkdownView);
// @ts-ignore
const thisScrollObj = thisView?.previewMode?.renderer?.previewEl;
const range = thisScrollObj?.clientHeight - 60;
const range = thisScrollObj?.clientHeight - this.settings.flipingBias;
thisScrollObj?.scrollBy(0, mode === "up" ? -range : range);
}
}
7 changes: 7 additions & 0 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface OnyxSideButtonSettings {
flipingBias: number;
}

export const DEFAULT_SETTINGS: OnyxSideButtonSettings = {
flipingBias: 60
};
30 changes: 30 additions & 0 deletions src/settings/settingsTab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import OnyxSideButton from "../main";
import { App, PluginSettingTab, Setting } from "obsidian";


export class OnyxSideButtonSettingsTab extends PluginSettingTab {
plugin: OnyxSideButton;
constructor(app: App, plugin: OnyxSideButton) {
super(app, plugin);
this.plugin = plugin;
}

display(): void {
const { containerEl } = this;
containerEl.empty();

new Setting(containerEl)
.setName("Fliping bias")
.setDesc("Fliping bias")
.addText((text) =>
text
.setPlaceholder("60")
.setValue(String(this.plugin.settings.flipingBias))
.onChange(async (value) => {
this.plugin.settings.flipingBias = Number(value);
await this.plugin.saveSettings();
})
);
}
}