From ac731b06edc8386b203c499c20c5f149a12c6efa Mon Sep 17 00:00:00 2001 From: Mikko Ahlroth Date: Sun, 27 Aug 2017 20:54:34 +0300 Subject: [PATCH] Fix XP issue by always giving 1 XP no matter the changes This can be done because onDidChangeTextDocument is fired for every typed character, i.e. it is not debounced. So every change is 1 XP which is a good approximation. I ran some basic tests with this, hope it works well in all situations. Fixes #8 --- src/xp-counter.ts | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/src/xp-counter.ts b/src/xp-counter.ts index 133b24b..cdd24ab 100644 --- a/src/xp-counter.ts +++ b/src/xp-counter.ts @@ -44,36 +44,7 @@ export class XpCounter { } private onTextDocumentChanged(event: TextDocumentChangeEvent): void { - let changeCount: number = 0; - let containsLineBreaks: boolean = false; - for (let change of event.contentChanges) { - if (change.text.indexOf("\n") !== -1) { - //if line breaks found in text, assume it is a reformatting of a text or JSON object - containsLineBreaks = true; - } else { - changeCount += this.determineChangeCount(change.range); - } - } - if (containsLineBreaks) { - this.updateXpCount(event.document, 1); - } else { - this.updateXpCount(event.document, changeCount); - } - } - - private determineChangeCount(range: Range): number { - if (range === null || range === undefined) { - return 0; - } - if (range.start.line === range.end.line) { - if (range.start.character === range.end.character) { - return 1; - } else { - return range.end.character - range.start.character; - } - } - // multiline changes, copy/paste count as 1XP - return 1; + this.updateXpCount(event.document, 1); } public updateXpCount(document: TextDocument, changeCount: number): void {