Skip to content

Commit

Permalink
feature freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
pajoma committed Sep 19, 2018
1 parent ac04649 commit 8d0249d
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 19 deletions.
9 changes: 9 additions & 0 deletions 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)
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion src/actions/inject.ts
Expand Up @@ -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';
}

Expand All @@ -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

Expand Down
17 changes: 7 additions & 10 deletions src/ext/commands.ts
Expand Up @@ -103,7 +103,7 @@ export class JournalCommands implements Commands {
this.ctrl.logger.trace("Entering printSum() in ext/commands.ts");
return Q.Promise<string>((resolve, reject) => {
let editor: vscode.TextEditor = <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[] = [];
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/ext/conf.ts
Expand Up @@ -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) || [];

Expand Down Expand Up @@ -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:")) {
Expand Down Expand Up @@ -410,7 +413,11 @@ export class Configuration {
* @memberof Configuration
*/
public getTimeStringTemplate(_scopeId?: string): Q.Promise<ScopedTemplate> {
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;
});
}


Expand Down
2 changes: 1 addition & 1 deletion test/journal.test.ts
Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions 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
14 changes: 13 additions & 1 deletion 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}"
}
},
}

0 comments on commit 8d0249d

Please sign in to comment.