Skip to content

Commit

Permalink
Bug fix and code lintering
Browse files Browse the repository at this point in the history
Fixed a bug which made it so that the plugin was making it impossible to choose a note from suggestions while linking
  • Loading branch information
plasmabit committed Feb 12, 2024
1 parent d25653f commit 8253c7c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
4 changes: 0 additions & 4 deletions src/BOMS.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
9 changes: 3 additions & 6 deletions src/CAMS.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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 = [];

Expand All @@ -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;
Expand Down
18 changes: 12 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -150,7 +157,6 @@ export default class TimeThings extends Plugin {
if (activeView === null) {
return;
}
const editor: Editor = activeView.editor;

if (this.settings.useCustomFrontmatterHandlingSolution === false) {

Expand Down Expand Up @@ -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("⌛ --");
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, PluginSettingTab, SearchComponent, Setting } from 'obsidian';
import { App, PluginSettingTab, Setting } from 'obsidian';
import TimeThings from './main';

export interface TimeThingsSettings {
Expand Down Expand Up @@ -182,7 +182,7 @@ export class TimeThingsSettingsTab extends PluginSettingTab {
.onChange(async (value) => {
this.plugin.settings.updateIntervalFrontmatterMinutes = value;
await this.plugin.saveSettings();
})
})
.setDynamicTooltip(),
);
}
Expand Down
1 change: 0 additions & 1 deletion src/time.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Editor, Setting } from 'obsidian';
import { moment } from 'obsidian';

export function momentToClockEmoji(time: moment.Moment): string {
Expand Down

0 comments on commit 8253c7c

Please sign in to comment.