From 8d0249d320218e2daf79572f2d685923a1bd549d Mon Sep 17 00:00:00 2001 From: pajoma Date: Wed, 19 Sep 2018 21:10:50 +0200 Subject: [PATCH] feature freeze --- docs/known_issues.md | 9 ++++++++ package.json | 8 +++---- src/actions/inject.ts | 12 ++++++++++- src/ext/commands.ts | 17 ++++++--------- src/ext/conf.ts | 11 ++++++++-- test/journal.test.ts | 2 +- test/script.md | 32 ++++++++++++++++++++++++++++ test/workspace/.vscode/settings.json | 14 +++++++++++- 8 files changed, 86 insertions(+), 19 deletions(-) create mode 100644 docs/known_issues.md create mode 100644 test/script.md diff --git a/docs/known_issues.md b/docs/known_issues.md new file mode 100644 index 0000000..46d4e9d --- /dev/null +++ b/docs/known_issues.md @@ -0,0 +1,9 @@ +# Known Issues + +The following list consists of open issues which I have identified during testing, but decided to ignore them (for now). These issues are either just not worth the effort or just happening w/in rather weird conditions. + +## Linebreaks for injected links when last line is empty +Sometimes linebreaks are missing between the links + +## Compute Duration always below 12h +Order doesn't matter, we always substract the smaller from the larger. No order was on purpose, I think its better to just add a "+1" to add day breaks (you can then also add +2) \ No newline at end of file diff --git a/package.json b/package.json index e086342..1571531 100644 --- a/package.json +++ b/package.json @@ -151,7 +151,7 @@ "journal.base": { "type": "string", "default": "", - "description": "(Mandatatory) The base directory for your notes. Defaults to the directory 'Journal' in your home directory" + "description": "(Mandatatory) The base directory for your notes. Defaults to the directory 'Journal' in your home directory. Supports embedded variables" }, "journal.ext": { "type": "string", @@ -179,13 +179,13 @@ }, "journal.tpl-entry": { "type": "string", - "default": "# Journal Entry for ${localDate}\n\n## Tasks\n\n## Notes", - "description": "The template string for your daily journal entries. It will be formatted as date (Using moment.js formatting tokens), escape your own strings with []." + "default": "# ${weekday}, ${localDate}\n\n## Tasks\n\n## Notes\n\n", + "description": "The template string for your daily journal entries." }, "journal.tpl-time": { "type": "string", "default": "${localTime}", - "description": "The template string for inserting the current time at the cursor location. It will be formatted as date (Using moment.js formatting tokens), escape your own strings with []." + "description": "The template string for inserting the current time at the cursor location. Defaults to local time. " }, "journal.tpl-note": { "type": "string", diff --git a/src/actions/inject.ts b/src/actions/inject.ts index 8dc3306..246f148 100644 --- a/src/actions/inject.ts +++ b/src/actions/inject.ts @@ -175,6 +175,14 @@ export class Inject { // shift (inject line break) if line is occupied if ((newLine === true) && (!content.document.lineAt(content.position.line).isEmptyOrWhitespace)) { + + // if we are at end of the file we prefix another linebreak to make room + let end: vscode.Position = content.document.lineAt(content.document.lineCount-1).range.end; + + if(content.position.isAfterOrEqual(end)) { + content.value = '\n'+ content.value; + } + content.value = content.value + '\n'; } @@ -190,9 +198,11 @@ export class Inject { // ).then(() => { let multiple: boolean = (!isNullOrUndefined(other) && other.length > 0); + /* if (multiple) { + content.value = content.value + '\n'; - } + }*/ edit.insert(content.document.uri, content.position, content.value); // ! = not null assertion operator diff --git a/src/ext/commands.ts b/src/ext/commands.ts index 275fa70..b70fc80 100644 --- a/src/ext/commands.ts +++ b/src/ext/commands.ts @@ -103,7 +103,7 @@ export class JournalCommands implements Commands { this.ctrl.logger.trace("Entering printSum() in ext/commands.ts"); return Q.Promise((resolve, reject) => { let editor: vscode.TextEditor = vscode.window.activeTextEditor; - let regExp: RegExp = /(\d+[,\.]?\d*\s)|(\s)/; + let regExp: RegExp = /(\d+[,\.]?\d*\s?)|(\s)/; let target: vscode.Position; let numbers: number[] = []; @@ -159,14 +159,12 @@ export class JournalCommands implements Commands { // Todo: identify scope of the active editot this.ctrl.config.getTimeStringTemplate().then(tpl => { - let locale = this.ctrl.config.getLocale(); - return J.Util.formatDate(new Date(), tpl.template, locale); - }).then((str: string) => { - let currentPosition: vscode.Position = editor.selection.active; + + let currentPosition: vscode.Position = editor.selection.active; - this.ctrl.inject.injectString(editor.document, str, currentPosition); + this.ctrl.inject.injectString(editor.document, tpl.value!, currentPosition); - resolve(str); + resolve(tpl.value!); }).catch(error => reject(error)) .done(); @@ -201,7 +199,6 @@ export class JournalCommands implements Commands { let end: moment.Moment; let target: vscode.Position; - let tpl = this.ctrl.config.getTimeString(); editor.selections.forEach((selection: vscode.Selection) => { let range: vscode.Range | undefined = editor.document.getWordRangeAtPosition(selection.active, regExp); @@ -222,8 +219,8 @@ export class JournalCommands implements Commands { return; } - // try to format into date - let time: moment.Moment = moment(text, tpl); + // try to format into local date + let time: moment.Moment = moment(text, "LT"); if (!time.isValid()) { // 123pm diff --git a/src/ext/conf.ts b/src/ext/conf.ts index 0d639fe..cfbad89 100644 --- a/src/ext/conf.ts +++ b/src/ext/conf.ts @@ -225,7 +225,7 @@ export class Configuration { * @param date */ // https://regex101.com/r/i5MUpx/1/ - private regExpDateFormats: RegExp = new RegExp(/\$\{(?:(year|month|day|localTime|localDate)|(d:\w+))\}/g); + private regExpDateFormats: RegExp = new RegExp(/\$\{(?:(year|month|day|localTime|localDate|weekday)|(d:\w+))\}/g); private replaceDateFormats(st: ScopedTemplate, date: Date): void { let matches: RegExpMatchArray = st.template.match(this.regExpDateFormats) || []; @@ -254,6 +254,9 @@ export class Configuration { case "${localDate}": st.value = st.value!.replace(match, mom.format("LL")); break; + case "${weekday}": + st.value = st.value!.replace(match, mom.format("dddd")); + break; default: // check if custom format if (match.startsWith("${d:")) { @@ -410,7 +413,11 @@ export class Configuration { * @memberof Configuration */ public getTimeStringTemplate(_scopeId?: string): Q.Promise { - return this.getInlineTemplate("tpl-time", "LT", this.resolveScope(_scopeId)); + return this.getInlineTemplate("tpl-time", "LT", this.resolveScope(_scopeId)) + .then(tpl => { + this.replaceDateFormats(tpl, new Date()); + return tpl; + }); } diff --git a/test/journal.test.ts b/test/journal.test.ts index 6f67a6a..2eeb0b6 100644 --- a/test/journal.test.ts +++ b/test/journal.test.ts @@ -5,8 +5,8 @@ // Defines a Mocha test suite to group tests of similar kind together suite("Journal Unit Tests", () => { - /* + test("open weekday (\"last wednesday\")", done => { var journal:Journal = new Journal(null); diff --git a/test/script.md b/test/script.md new file mode 100644 index 0000000..af90e80 --- /dev/null +++ b/test/script.md @@ -0,0 +1,32 @@ + + +Create Note + New Note + New file is created in correct location + Link to file is placed in today's entry in correct location + + New Note with tags + + Second note + Link to file is placed above the other entries + +Create Entry + magic input = 0, +2, -5, last wednesday, next fri, specific date + +Create tasks + magic input: "task today do this", "task next friday do this", "task specific date do this" + +Create memo + magic input, same as above without flag "task" + +Print time + +Compute Duration + +Compute Sum + +## Configuration +change locale +change location of notes +change base directory +change \ No newline at end of file diff --git a/test/workspace/.vscode/settings.json b/test/workspace/.vscode/settings.json index 22b5cf7..3113f27 100644 --- a/test/workspace/.vscode/settings.json +++ b/test/workspace/.vscode/settings.json @@ -1,4 +1,16 @@ { "journal.base": "E:\\Projects\\vscode-journal\\tests\\Journal", - "journal.dev": true + "journal.dev": true, + "journal.locale": "fr-FR", + "journal.openInNewEditorGroup": true, + "journal.patterns": { + "notes": { + "path": "${base}/${year}-${month}/", + "file": "${day}-${input}.${ext}" + }, + "entries": { + "path": "${base}/${year}-${month}", + "file": "${day}.${ext}" + } + }, } \ No newline at end of file