From 7ffbe1141d04ad2c0e8cd291f48c165ad08f72f5 Mon Sep 17 00:00:00 2001 From: Benjamin Christopher Simmonds <44439583+benibenj@users.noreply.github.com> Date: Thu, 7 Aug 2025 17:36:16 +0200 Subject: [PATCH] Only include user typing in typing speed computation (#260339) --- .../browser/model/typingSpeed.ts | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/vs/editor/contrib/inlineCompletions/browser/model/typingSpeed.ts b/src/vs/editor/contrib/inlineCompletions/browser/model/typingSpeed.ts index 9e42d5db345..3378546d421 100644 --- a/src/vs/editor/contrib/inlineCompletions/browser/model/typingSpeed.ts +++ b/src/vs/editor/contrib/inlineCompletions/browser/model/typingSpeed.ts @@ -60,7 +60,11 @@ export class TypingInterval extends Disposable { private _updateTypingSpeed(change: IModelContentChangedEvent): void { const now = Date.now(); - const characterCount = this._calculateEffectiveCharacterCount(change); + + if (!this._isUserTyping(change)) { + this._finalizeCurrentSession(); + return; + } // If too much time has passed since last change, start a new session if (this._currentSession && (now - this._lastChangeTime) > TypingInterval.MAX_SESSION_GAP_MS) { @@ -78,24 +82,12 @@ export class TypingInterval extends Disposable { // Update current session this._currentSession.endTime = now; - this._currentSession.characterCount += characterCount; + this._currentSession.characterCount += this._getActualCharacterCount(change); this._lastChangeTime = now; this._cacheInvalidated = true; } - private _calculateEffectiveCharacterCount(change: IModelContentChangedEvent): number { - const actualCharCount = this._getActualCharacterCount(change); - - // If this is actual user typing, count all characters - if (this._isUserTyping(change)) { - return actualCharCount; - } - - // For all other actions (paste, suggestions, etc.), count as 1 regardless of size - return actualCharCount > 0 ? 1 : 0; - } - private _getActualCharacterCount(change: IModelContentChangedEvent): number { let totalChars = 0; for (const c of change.changes) { @@ -108,7 +100,7 @@ export class TypingInterval extends Disposable { private _isUserTyping(change: IModelContentChangedEvent): boolean { // If no detailed reasons, assume user typing if (!change.detailedReasons || change.detailedReasons.length === 0) { - return true; + return false; } // Check if any of the reasons indicate actual user typing