This commit is contained in:
Alex Dima
2016-02-22 23:36:29 +01:00
parent 35d8f0a115
commit 40d4c11fdf
3 changed files with 58 additions and 28 deletions
@@ -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;
@@ -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);
}
+41 -25
View File
@@ -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);