zoom sensitivity for mouse and touch

This commit is contained in:
poanse 2026-02-03 15:05:45 +03:00
parent 3e03d89688
commit 4fd97a3e13
7 changed files with 54 additions and 48 deletions

View file

@ -11,9 +11,18 @@ export const TOOLBAR_SIZE = {
width: 98 * 2,
height: 22 * 2,
};
export const TASK_SIZE = {
width: 280,
height: 80,
width_hovered: 284,
height_hovered: 84,
};
export function parseNumber(value: string | null | undefined): number | null {
if (value === null || value === undefined) {
return null;
}
const num = Number(value);
return isNaN(num) || value.trim() === "" ? null : num;
}

View file

@ -27,6 +27,7 @@ import { delink, LinkManager, tasknameFromFilePath } from "./LinkManager";
export class Context {
app: App;
plugin: TaskmapPlugin;
view: TaskmapView;
nodePositionsCalculator: NodePositionsCalculator;
linkManager: LinkManager;
@ -55,11 +56,13 @@ export class Context {
private springOptions = { stiffness: 0.07, damping: 0.7 };
constructor(
plugin: TaskmapPlugin,
view: TaskmapView,
projectData: ProjectData,
app: App,
nodePositionsCalculator: NodePositionsCalculator,
) {
this.plugin = plugin;
this.view = view;
this.nodePositionsCalculator = nodePositionsCalculator;
this.app = app;
@ -411,12 +414,7 @@ export class Context {
);
this.projectData.setTaskStatus(this.selectedTaskId, status);
this.toolbarStatus = status;
const x = TaskmapPlugin.getActiveView();
if (x) {
x.debouncedSave();
}
// get taskdata
// change its status
this.view.debouncedSave();
}
public hideTaskBranch(id: number) {

View file

@ -1,7 +1,9 @@
export interface PluginSettings {
mySetting: string;
zoomSensitivityTouchpad: string;
zoomSensitivityMouse: string;
}
export const DEFAULT_SETTINGS: PluginSettings = {
mySetting: 'default'
}
zoomSensitivityTouchpad: "100",
zoomSensitivityMouse: "100",
};

View file

@ -15,14 +15,26 @@ export class TaskmapSettingTab extends PluginSettingTab {
containerEl.empty();
new Setting(containerEl)
.setName("Setting #1")
.setDesc("It's a secret")
.setName("Zoom sensitivity (touchpad)")
.setDesc("In percents")
.addText((text) =>
text
.setPlaceholder("Enter your secret")
.setValue(this.plugin.settings.mySetting)
.setPlaceholder("100")
.setValue(this.plugin.settings.zoomSensitivityTouchpad)
.onChange(async (value) => {
this.plugin.settings.mySetting = value;
this.plugin.settings.zoomSensitivityTouchpad = value;
await this.plugin.saveSettings();
}),
);
new Setting(containerEl)
.setName("Zoom sensitivity (mouse)")
.setDesc("In percents")
.addText((text) =>
text
.setPlaceholder("100")
.setValue(this.plugin.settings.zoomSensitivityMouse)
.onChange(async (value) => {
this.plugin.settings.zoomSensitivityMouse = value;
await this.plugin.saveSettings();
}),
);

View file

@ -5,22 +5,24 @@ import { Context } from "./Context.svelte.js";
import { NodePositionsCalculator } from "./NodePositionsCalculator";
import TaskmapContainer from "./components/TaskmapContainer.svelte";
import { deserializeProjectData, updateFile } from "./SaveManager";
import type TaskmapPlugin from "./main";
export const TASKMAP_VIEW_TYPE = "taskmap-view";
export class TaskmapView extends TextFileView {
taskmapContainer: ReturnType<typeof TaskmapContainer> | undefined;
constructor(leaf: WorkspaceLeaf) {
super(leaf);
}
debouncedSave = debounce(() => this.save(), 1000, true);
plugin: TaskmapPlugin;
data: string = DEFAULT_DATA;
projectData: ProjectData;
context: Context;
constructor(leaf: WorkspaceLeaf, plugin: TaskmapPlugin) {
super(leaf);
this.plugin = plugin;
}
debouncedSave = debounce(() => this.save(), 1000, true);
getViewType() {
return TASKMAP_VIEW_TYPE;
}
@ -37,6 +39,7 @@ export class TaskmapView extends TextFileView {
this.setViewData(data);
this.projectData = deserializeProjectData(this.app, this.data);
this.context = new Context(
this.plugin,
this,
this.projectData,
this.app,

View file

@ -8,6 +8,7 @@
import Connection from "./Connection.svelte";
import {NoTaskId, RootTaskId} from "../NodePositionsCalculator";
import {DraggingManager} from "../DraggingManager.svelte";
import {parseNumber} from "../Constants";
let {context}: {context: Context} = $props();
@ -53,29 +54,15 @@
}
function onwheel(e: WheelEvent) {
let scaledEvent: WheelEvent;
let scaleConstant: number;
const isTouchpad = Math.abs(e.deltaY) < 50;
if (isTouchpad) {
// Create a modified event with scaled deltaY for touchpad
const scaleConstant = 0.2;
scaledEvent = new WheelEvent('wheel', {
deltaY: e.deltaY * scaleConstant,
deltaX: e.deltaX * scaleConstant,
deltaMode: e.deltaMode,
clientX: e.clientX,
clientY: e.clientY,
ctrlKey: e.ctrlKey,
shiftKey: e.shiftKey,
altKey: e.altKey,
metaKey: e.metaKey,
button: e.button,
buttons: e.buttons,
});
scaleConstant = 0.05 * (parseNumber(context.plugin.settings.zoomSensitivityTouchpad) ?? 100) / 100;
} else {
scaledEvent = e;
scaleConstant = 0.5 * (parseNumber(context.plugin.settings.zoomSensitivityMouse) ?? 100) / 100;
}
getPanzoom().zoomWithWheel(scaledEvent);
getPanzoom().zoomWithWheel(e, {step: scaleConstant});
context.setScale(getPanzoom().getScale());
if (getPanzoom().getScale() > 1) {
context.incrementUpdateOnZoomCounter();

View file

@ -18,13 +18,14 @@ import { generateMarkdownLink } from "./LinkManager";
export const FILE_EXTENSION = "taskmap";
export default class TaskmapPlugin extends Plugin {
static instance: TaskmapPlugin;
settings: PluginSettings;
async onload() {
TaskmapPlugin.instance = this;
await this.loadSettings();
this.registerView(TASKMAP_VIEW_TYPE, (leaf) => new TaskmapView(leaf));
this.registerView(
TASKMAP_VIEW_TYPE,
(leaf) => new TaskmapView(leaf, this),
);
this.registerExtensions([FILE_EXTENSION], TASKMAP_VIEW_TYPE);
// This creates an icon in the left ribbon.
@ -139,12 +140,6 @@ export default class TaskmapPlugin extends Plugin {
}
}
public static getActiveView() {
return TaskmapPlugin.instance.app.workspace.getActiveViewOfType(
TaskmapView,
);
}
public async createAndOpenDrawing(): Promise<string> {
this.app.workspace.detachLeavesOfType(TASKMAP_VIEW_TYPE);