diff --git a/src/vs/editor/contrib/find/common/findDecorations.ts b/src/vs/editor/contrib/find/common/findDecorations.ts index 59d8c003a3d..9a238950833 100644 --- a/src/vs/editor/contrib/find/common/findDecorations.ts +++ b/src/vs/editor/contrib/find/common/findDecorations.ts @@ -39,6 +39,10 @@ export class FindDecorations implements IDisposable { this._highlightedDecorationId = null; } + public getCount(): number { + return this._decorations.length; + } + public getFindScope(): editorCommon.IEditorRange { if (this._findScopeDecorationId) { return this._editor.getModel().getDecorationRange(this._findScopeDecorationId); @@ -55,6 +59,16 @@ export class FindDecorations implements IDisposable { this.setCurrentFindMatch(null); } + public getCurrentMatchesPosition(desiredRange:editorCommon.IEditorRange): number { + for (let i = 0, len = this._decorations.length; i < len; i++) { + let range = this._editor.getModel().getDecorationRange(this._decorations[i]); + if (desiredRange.equalsRange(range)) { + return (i + 1); + } + } + return 1; + } + public setCurrentFindMatch(nextMatch:editorCommon.IEditorRange): number { let newCurrentDecorationId: string = null; let matchPosition = 0; diff --git a/src/vs/editor/contrib/find/common/findModel.ts b/src/vs/editor/contrib/find/common/findModel.ts index f2c43873512..d50f079dc2f 100644 --- a/src/vs/editor/contrib/find/common/findModel.ts +++ b/src/vs/editor/contrib/find/common/findModel.ts @@ -124,7 +124,7 @@ export class FindModelBoundToEditorModel { let findMatches = this._findMatches(findScope, MATCHES_LIMIT); this._decorations.set(findMatches, findScope); - this._state.change({ matchesCount: findMatches.length }, false); + this._state.changeMatchInfo(this._decorations.getCurrentMatchesPosition(this._editor.getSelection()), this._decorations.getCount()); if (moveCursor) { this._moveToNextMatch(this._decorations.getStartPosition()); @@ -205,7 +205,7 @@ export class FindModelBoundToEditorModel { } let matchesPosition = this._decorations.setCurrentFindMatch(prevMatch); - this._state.change({ matchesPosition: matchesPosition }, false); + this._state.changeMatchInfo(matchesPosition, this._decorations.getCount()); this._editor.setSelection(prevMatch); this._editor.revealRangeInCenterIfOutsideViewport(prevMatch); } @@ -273,7 +273,7 @@ export class FindModelBoundToEditorModel { } let matchesPosition = this._decorations.setCurrentFindMatch(nextMatch); - this._state.change({ matchesPosition: matchesPosition }, false); + this._state.changeMatchInfo(matchesPosition, this._decorations.getCount()); this._editor.setSelection(nextMatch); this._editor.revealRangeInCenterIfOutsideViewport(nextMatch); } diff --git a/src/vs/editor/contrib/find/common/findState.ts b/src/vs/editor/contrib/find/common/findState.ts index 30f5ebaffba..58a851ce7c5 100644 --- a/src/vs/editor/contrib/find/common/findState.ts +++ b/src/vs/editor/contrib/find/common/findState.ts @@ -33,8 +33,8 @@ export interface INewFindReplaceState { wholeWord?: boolean; matchCase?: boolean; searchScope?: IEditorRange; - matchesPosition?: number; - matchesCount?: number; + // matchesPosition?: number; + // matchesCount?: number; } export class FindReplaceState implements IDisposable { @@ -86,6 +86,45 @@ export class FindReplaceState implements IDisposable { return this._eventEmitter.addListener2(FindReplaceState._CHANGED_EVENT, listener); } + public changeMatchInfo(matchesPosition:number, matchesCount:number): void { + let changeEvent:FindReplaceStateChangedEvent = { + moveCursor: false, + searchString: false, + replaceString: false, + isRevealed: false, + isReplaceRevealed: false, + isRegex: false, + wholeWord: false, + matchCase: false, + searchScope: false, + matchesPosition: false, + matchesCount: false + }; + let somethingChanged = false; + + if (matchesCount === 0) { + matchesPosition = 0; + } + if (matchesPosition > matchesCount) { + matchesPosition = matchesCount; + } + + if (this._matchesPosition !== matchesPosition) { + this._matchesPosition = matchesPosition; + changeEvent.matchesPosition = true; + somethingChanged = true; + } + if (this._matchesCount !== matchesCount) { + this._matchesCount = matchesCount; + changeEvent.matchesCount = true; + somethingChanged = true; + } + + if (somethingChanged) { + this._eventEmitter.emit(FindReplaceState._CHANGED_EVENT, changeEvent); + } + } + public change(newState:INewFindReplaceState, moveCursor:boolean): void { let changeEvent:FindReplaceStateChangedEvent = { moveCursor: moveCursor, @@ -158,29 +197,6 @@ export class FindReplaceState implements IDisposable { somethingChanged = true; } } - if (typeof newState.matchesPosition !== 'undefined') { - if (this._matchesPosition !== newState.matchesPosition) { - this._matchesPosition = newState.matchesPosition; - changeEvent.matchesPosition = true; - somethingChanged = true; - } - } - if (typeof newState.matchesCount !== 'undefined') { - if (this._matchesCount !== newState.matchesCount) { - this._matchesCount = newState.matchesCount; - changeEvent.matchesCount = true; - somethingChanged = true; - - if (this._matchesCount === 0) { - this._matchesPosition = 0; - changeEvent.matchesPosition = true; - } else if (this._matchesPosition > this._matchesCount) { - this._matchesPosition = this._matchesCount; - changeEvent.matchesPosition = true; - } - } - } - if (somethingChanged) { this._eventEmitter.emit(FindReplaceState._CHANGED_EVENT, changeEvent);