From 8253c7c3b54302f4d8a6baa059b43d0ecbbfd1de Mon Sep 17 00:00:00 2001 From: Nick Winters <65742767+DynamicPlayerSector@users.noreply.github.com> Date: Mon, 12 Feb 2024 16:16:35 +0300 Subject: [PATCH] Bug fix and code lintering Fixed a bug which made it so that the plugin was making it impossible to choose a note from suggestions while linking --- src/BOMS.ts | 4 ---- src/CAMS.ts | 9 +++------ src/main.ts | 18 ++++++++++++------ src/settings.ts | 4 ++-- src/time.utils.ts | 1 - 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/BOMS.ts b/src/BOMS.ts index ab77f4e..e5a6bfb 100644 --- a/src/BOMS.ts +++ b/src/BOMS.ts @@ -1,7 +1,3 @@ -import { TAbstractFile, TFile } from 'obsidian'; -import { moment } from 'obsidian'; -import TimeThings from './main' - export function getValue(obj: any, fieldPath: string) { const keys = fieldPath.split('.'); let value = obj; diff --git a/src/CAMS.ts b/src/CAMS.ts index 1dd9e11..2734cf6 100644 --- a/src/CAMS.ts +++ b/src/CAMS.ts @@ -1,5 +1,4 @@ -import { Editor, Setting } from 'obsidian'; -import { moment } from 'obsidian'; +import { Editor,} from 'obsidian'; export function isLineIndented(line: string): boolean { return /^[\s\t]/.test(line); @@ -31,14 +30,12 @@ export function frontmatterEndLine(editor: Editor): number | undefined { export function getLine(editor: Editor, fieldPath: string): number | undefined { const frontmatterLine = frontmatterEndLine(editor); const keys = fieldPath.split('.'); - const depth = keys.length; if (frontmatterLine === undefined) { return undefined; } let targetDepth = 1; - let currentDepth = 1; let startLine = 1; let emergingPath = []; @@ -51,8 +48,8 @@ export function getLine(editor: Editor, fieldPath: string): number | undefined { if (currentFieldName === key) { emergingPath.push(currentFieldName); - let targetPath = fieldPath.split('.'); - let targetPathShrink = targetPath.slice(0, emergingPath.length); + const targetPath = fieldPath.split('.'); + const targetPathShrink = targetPath.slice(0, emergingPath.length); if (targetPathShrink.join('.') === emergingPath.join('.') === false) { emergingPath.pop(); startLine = i + 1; diff --git a/src/main.ts b/src/main.ts index 3205fd6..e69d3b1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, TAbstractFile, TFile, WorkspaceLeaf } from 'obsidian'; +import {Editor, MarkdownView, Plugin, TAbstractFile, TFile,} from 'obsidian'; import { moment } from 'obsidian'; import * as BOMS from './BOMS'; @@ -85,8 +85,15 @@ export default class TimeThings extends Plugin { this.registerDomEvent(document, 'keyup', (evt: KeyboardEvent) => { // If CAMS enabled - - if (evt.ctrlKey) { + const ignoreKeys = [ + "ArrowDown", + "ArrowUp", + "Tab", + "CapsLock", + "Alt", + ] + + if (evt.ctrlKey || ignoreKeys.includes(evt.key)) { return; } @@ -150,7 +157,6 @@ export default class TimeThings extends Plugin { if (activeView === null) { return; } - const editor: Editor = activeView.editor; if (this.settings.useCustomFrontmatterHandlingSolution === false) { @@ -203,7 +209,7 @@ export default class TimeThings extends Plugin { async setEditDurationBar(useCustomSolution: boolean, solution: Editor | TAbstractFile) { // what the hell is this monstrosity let value = 0; if (solution instanceof Editor) { - let editor = solution; + const editor = solution; const fieldLine = CAMS.getLine(editor, this.settings.editDurationPath); if (fieldLine === undefined) { this.editDurationBar.setText("⌛ --"); @@ -212,7 +218,7 @@ export default class TimeThings extends Plugin { value = +editor.getLine(fieldLine).split(/:(.*)/s)[1].trim(); } if (solution instanceof TAbstractFile) { - let file = solution; + const file = solution; await this.app.fileManager.processFrontMatter(file as TFile, (frontmatter) => { value = BOMS.getValue(frontmatter, this.settings.editDurationPath); if (value === undefined) { diff --git a/src/settings.ts b/src/settings.ts index fe401e1..1e79b2c 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,4 +1,4 @@ -import { App, PluginSettingTab, SearchComponent, Setting } from 'obsidian'; +import { App, PluginSettingTab, Setting } from 'obsidian'; import TimeThings from './main'; export interface TimeThingsSettings { @@ -182,7 +182,7 @@ export class TimeThingsSettingsTab extends PluginSettingTab { .onChange(async (value) => { this.plugin.settings.updateIntervalFrontmatterMinutes = value; await this.plugin.saveSettings(); - }) + }) .setDynamicTooltip(), ); } diff --git a/src/time.utils.ts b/src/time.utils.ts index d36f2d2..66a7365 100644 --- a/src/time.utils.ts +++ b/src/time.utils.ts @@ -1,4 +1,3 @@ -import { Editor, Setting } from 'obsidian'; import { moment } from 'obsidian'; export function momentToClockEmoji(time: moment.Moment): string {