Skip to content

Commit

Permalink
Handle trailing whitespace in sectionHeading (#13)
Browse files Browse the repository at this point in the history
* Handle trailing whitespace

* Bump version
  • Loading branch information
liamcain authored Apr 28, 2021
1 parent 727dc3e commit 32963d8
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 53 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "things-logbook",
"name": "Things Logbook",
"description": "Sync your Things.app Logbook with Daily Notes",
"version": "0.1.10",
"version": "0.1.11",
"author": "Liam Cain",
"authorUrl": "https://github.com/liamcain/",
"isDesktopOnly": true,
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-things-logbook-plugin",
"version": "0.1.10",
"version": "0.1.11",
"description": "Sync Things.app Logbook with Obsidian",
"author": "liamcain",
"main": "main.js",
Expand All @@ -14,9 +14,9 @@
},
"dependencies": {
"obsidian": "obsidianmd/obsidian-api#master",
"obsidian-daily-notes-interface": "0.7.7",
"obsidian-daily-notes-interface": "0.9.2",
"papaparse": "5.3.0",
"tslib": "2.1.0"
"tslib": "2.2.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "17.1.0",
Expand All @@ -26,7 +26,6 @@
"@rollup/plugin-typescript": "8.2.0",
"@types/jest": "26.0.20",
"@types/moment": "2.13.0",
"@types/node": "14.14.34",
"@types/papaparse": "5.2.5",
"@typescript-eslint/eslint-plugin": "4.17.0",
"@typescript-eslint/parser": "4.17.0",
Expand Down
13 changes: 6 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type moment from "moment";
import { App, Notice, Plugin } from "obsidian";
import { Notice, Plugin } from "obsidian";
import {
createDailyNote,
getDailyNote,
getAllDailyNotes,
} from "obsidian-daily-notes-interface";

import { createConfirmationDialog } from "./modal";
import { ConfirmationModal } from "./modal";
import { LogbookRenderer } from "./renderer";
import {
DEFAULT_SETTINGS,
Expand All @@ -24,7 +24,6 @@ import { groupBy, isMacOS, updateSection } from "./textUtils";

declare global {
interface Window {
app: App;
moment: typeof moment;
}
}
Expand Down Expand Up @@ -73,7 +72,7 @@ export default class ThingsLogbookPlugin extends Plugin {
if (this.options.hasAcceptedDisclaimer) {
this.syncLogbook();
} else {
createConfirmationDialog({
new ConfirmationModal(this.app, {
cta: "Sync",
onAccept: async () => {
await this.writeOptions({ hasAcceptedDisclaimer: true });
Expand All @@ -82,15 +81,15 @@ export default class ThingsLogbookPlugin extends Plugin {
text:
"Enabling sync will backfill your entire Things Logbook into Obsidian. This means potentially creating or modifying hundreds of notes. Make sure to test the plugin in a test vault before continuing.",
title: "Sync Now?",
});
}).open();
}
}

async tryToScheduleSync(): Promise<void> {
if (this.options.hasAcceptedDisclaimer) {
this.scheduleNextSync();
} else {
createConfirmationDialog({
new ConfirmationModal(this.app, {
cta: "Sync",
onAccept: async () => {
await this.writeOptions({ hasAcceptedDisclaimer: true });
Expand All @@ -104,7 +103,7 @@ export default class ThingsLogbookPlugin extends Plugin {
text:
"Enabling sync will backfill your entire Things Logbook into Obsidian. This means potentially creating or modifying hundreds of notes. Make sure to test the plugin in a test vault before continuing.",
title: "Sync Now?",
});
}).open();
}
}

Expand Down
19 changes: 0 additions & 19 deletions src/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,3 @@ export class ConfirmationModal extends Modal {
}
}
}

export function createConfirmationDialog({
cta,
onAccept,
onCancel,
text,
title,
}: IConfirmationDialogParams): ConfirmationModal {
const modal = new ConfirmationModal(window.app, {
cta,
onAccept,
onCancel,
text,
title,
});
modal.open();

return modal;
}
3 changes: 2 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class ThingsLogbookSettingsTab extends PluginSettingTab {
)
.addText((textfield) => {
textfield.setValue(this.plugin.options.sectionHeading);
textfield.onChange(async (sectionHeading) => {
textfield.onChange(async (rawSectionHeading) => {
const sectionHeading = rawSectionHeading.trim();
this.plugin.writeOptions({ sectionHeading });
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/textUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ export async function updateSection(
): Promise<void> {
const headingLevel = getHeadingLevel(heading);

const { vault } = window.app;
const { vault } = app;
const fileContents = await vault.read(file);
const fileLines = fileContents.split("\n");

let logbookSectionLineNum = -1;
let nextSectionLineNum = -1;

for (let i = 0; i < fileLines.length; i++) {
if (fileLines[i] === heading) {
if (fileLines[i].trim() === heading) {
logbookSectionLineNum = i;
} else if (logbookSectionLineNum !== -1) {
const currLevel = getHeadingLevel(fileLines[i]);
Expand Down
4 changes: 4 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"0.1.10": "0.10.8",
"0.1.11": "0.10.8"
}
39 changes: 20 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -605,17 +605,17 @@
dependencies:
"@babel/types" "^7.3.0"

"@types/[email protected].98":
version "0.0.98"
resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-0.0.98.tgz#b35c7a4ab1fc1684b08a4e3eb65240020556ebfb"
integrity sha512-cbty5LPayy2vNSeuUdjNA9tggG+go5vAxmnLDRWpiZI5a+RDBi9dlozy4/jW/7P/gletbBWbQREEa7A81YxstA==
"@types/[email protected].108":
version "0.0.108"
resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-0.0.108.tgz#e640422b666bf49251b384c390cdeb2362585bde"
integrity sha512-3FGFcus0P7C2UOGCNUVENqObEb4SFk+S8Dnxq7K6aIsLVs/vDtlangl3PEO0ykaKXyK56swVF6Nho7VsA44uhw==
dependencies:
"@types/tern" "*"

"@types/estree@*":
version "0.0.46"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.46.tgz#0fb6bfbbeabd7a30880504993369c4bf1deab1fe"
integrity sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg==
version "0.0.47"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.47.tgz#d7a51db20f0650efec24cd04994f523d93172ed4"
integrity sha512-c5ciR06jK8u9BstrmJyO97m+klJrrhCf9u3rLu3DEAJBirxRqSCvDQoYKmxuYwQI5SZChAWu+tq9oVlGRuzPAg==

"@types/[email protected]":
version "0.0.39"
Expand Down Expand Up @@ -673,11 +673,6 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.21.tgz#d934aacc22424fe9622ebf6857370c052eae464e"
integrity sha512-cHYfKsnwllYhjOzuC5q1VpguABBeecUp24yFluHpn/BQaVxB1CuQ1FSRZCzrPxrkIfWISXV2LbeoBthLWg0+0A==

"@types/[email protected]":
version "14.14.34"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.34.tgz#07935194fc049069a1c56c0c274265abeddf88da"
integrity sha512-dBPaxocOK6UVyvhbnpFIj2W+S+1cBTkHQbFQfeeJhoKFbzYcVUGHvddeWPSucKATb3F0+pgDq0i6ghEaZjsugA==

"@types/normalize-package-data@^2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
Expand Down Expand Up @@ -3142,19 +3137,20 @@ object.pick@^1.3.0:
dependencies:
isobject "^3.0.1"

obsidian-daily-notes-interface@0.7.7:
version "0.7.7"
resolved "https://registry.yarnpkg.com/obsidian-daily-notes-interface/-/obsidian-daily-notes-interface-0.7.7.tgz#55057284d1258fc38143fd3adc16203839e3e8a7"
integrity sha512-RAK4Z47qCY6JEWUieseMKc8KOpBxPBSxyRweptxJlTWNrh7iF8ROy+yj/R+c54t7ol8YtkW/CZGf7lr4dtakNQ==
obsidian-daily-notes-interface@0.9.2:
version "0.9.2"
resolved "https://registry.yarnpkg.com/obsidian-daily-notes-interface/-/obsidian-daily-notes-interface-0.9.2.tgz#f551620fbb576c91522699f73c2cdb6b4457e938"
integrity sha512-prwSUpKcvtHjpHGpLm8TQVr5Z1k1ZkL4XdSt8A8JKX+QB+r8yoCxSjvgegKqtU+WVjEW5JYiijDr36FoseS+mQ==
dependencies:
obsidian obsidianmd/obsidian-api#master
tslib "2.1.0"

obsidian@obsidianmd/obsidian-api#master:
version "0.10.6"
resolved "https://codeload.github.com/obsidianmd/obsidian-api/tar.gz/a0e0c245561215ced9468859091e01d015f5cda9"
version "0.12.0"
resolved "https://codeload.github.com/obsidianmd/obsidian-api/tar.gz/eb459522e7e35983e3e6c2358301a21b26de7b64"
dependencies:
"@types/codemirror" "0.0.98"
"@types/codemirror" "0.0.108"
moment "2.29.1"

once@^1.3.0, once@^1.3.1, once@^1.4.0:
version "1.4.0"
Expand Down Expand Up @@ -3998,6 +3994,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==

[email protected]:
version "2.2.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c"
integrity sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w==

tslib@^1.8.1:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
Expand Down

0 comments on commit 32963d8

Please sign in to comment.