From a0f9e32dedba3df826a58b437b4cb96d21cccb8d Mon Sep 17 00:00:00 2001 From: Cattamer Date: Fri, 16 Jan 2026 22:04:42 +0100 Subject: [PATCH] Add setting to skip header row in calculations When enabled, the first row of each table will be excluded from vertical (^) calculations. This is useful when header rows contain numbers that shouldn't be included in sums, averages, etc. Co-Authored-By: Claude Opus 4.5 --- src/main.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 0880683..f2da371 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,12 +22,14 @@ interface SimpleTableMathSettings { fractions: number; locale: string | null; styleLastRow: boolean; + skipHeaderRow: boolean; } const DEFAULT_SETTINGS: SimpleTableMathSettings = { fractions: 2, locale: null, styleLastRow: true, + skipHeaderRow: false, } /** @@ -156,7 +158,8 @@ export default class SimpleTableMath extends Plugin { } if (direction === '^') { - const actualStartRow = Math.max(0, startIndex); + const minStartRow = this.settings.skipHeaderRow ? 1 : 0; + const actualStartRow = Math.max(minStartRow, startIndex); const actualEndRow = endIndex !== -1 ? endIndex : rowIndex - 1; const finalEndRow = Math.min(actualEndRow, rowIndex - 1); if (actualStartRow <= finalEndRow) { @@ -422,5 +425,15 @@ class SettingTab extends PluginSettingTab { this.plugin.settings.styleLastRow = value; await this.plugin.saveSettings(); })); + + new Setting(containerEl) + .setName('Skip header row') + .setDesc('When enabled, the first row of each table will be excluded from vertical (^) calculations. Useful when your header row contains numbers.') + .addToggle(component => component + .setValue(this.plugin.settings.skipHeaderRow) + .onChange(async (value) => { + this.plugin.settings.skipHeaderRow = value; + await this.plugin.saveSettings(); + })); } }