mirror of
https://gitlab.com/aviortheking/code-stats-vscode.git
synced 2025-04-22 10:52:13 +00:00
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
This commit is contained in:
parent
f2aedac7fb
commit
ac731b06ed
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user