提交 8186062a 编写于 作者: A Alex Dima

Fixes #9120: Seed search scope on find field focus gain if the editor...

Fixes #9120: Seed search scope on find field focus gain if the editor selection was not set by the find model
上级 1b8ef8ca
......@@ -265,7 +265,7 @@
}
.monaco-editor .findScope {
background-color: rgba(239, 239, 242, 0.4);
background-color: rgba(180, 180, 180, 0.3);
}
/* Theming */
......
......@@ -21,6 +21,7 @@ import {IConfigurationChangedEvent} from 'vs/editor/common/editorCommon';
import {ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, OverlayWidgetPositionPreference} from 'vs/editor/browser/editorBrowser';
import {FIND_IDS, MATCHES_LIMIT} from 'vs/editor/contrib/find/common/findModel';
import {FindReplaceState, FindReplaceStateChangedEvent} from 'vs/editor/contrib/find/common/findState';
import {Range} from 'vs/editor/common/core/range';
export interface IFindController {
replace(): void;
......@@ -71,6 +72,8 @@ export class FindWidget extends Widget implements IOverlayWidget {
private _isVisible: boolean;
private _isReplaceVisible: boolean;
private _focusTracker: dom.IFocusTracker;
constructor(
codeEditor: ICodeEditor,
controller: IFindController,
......@@ -107,6 +110,17 @@ export class FindWidget extends Widget implements IOverlayWidget {
this._updateToggleSelectionFindButton();
}
}));
this._focusTracker = this._register(dom.trackFocus(this._findInput.inputBox.inputElement));
this._focusTracker.addFocusListener(() => {
let selection = this._codeEditor.getSelection();
let currentMatch = this._state.currentMatch;
if (selection.startLineNumber !== selection.endLineNumber) {
if (!Range.equalsRange(selection, currentMatch)) {
// Reseed find scope
this._state.change({ searchScope: selection }, true);
}
}
});
this._codeEditor.addOverlayWidget(this);
}
......
......@@ -140,7 +140,11 @@ export class FindModelBoundToEditorModel {
let findMatches = this._findMatches(findScope, MATCHES_LIMIT);
this._decorations.set(findMatches, findScope);
this._state.changeMatchInfo(this._decorations.getCurrentMatchesPosition(this._editor.getSelection()), this._decorations.getCount());
this._state.changeMatchInfo(
this._decorations.getCurrentMatchesPosition(this._editor.getSelection()),
this._decorations.getCount(),
undefined
);
if (moveCursor) {
this._moveToNextMatch(this._decorations.getStartPosition());
......@@ -163,6 +167,18 @@ export class FindModelBoundToEditorModel {
return false;
}
private _setCurrentFindMatch(match:Range): void {
let matchesPosition = this._decorations.setCurrentFindMatch(match);
this._state.changeMatchInfo(
matchesPosition,
this._decorations.getCount(),
match
);
this._editor.setSelection(match);
this._editor.revealRangeInCenterIfOutsideViewport(match);
}
private _moveToPrevMatch(before:Position, isRecursed:boolean = false): void {
if (this._cannotFind()) {
return;
......@@ -220,10 +236,7 @@ export class FindModelBoundToEditorModel {
return this._moveToPrevMatch(prevMatch.getStartPosition(), true);
}
let matchesPosition = this._decorations.setCurrentFindMatch(prevMatch);
this._state.changeMatchInfo(matchesPosition, this._decorations.getCount());
this._editor.setSelection(prevMatch);
this._editor.revealRangeInCenterIfOutsideViewport(prevMatch);
this._setCurrentFindMatch(prevMatch);
}
public moveToPrevMatch(): void {
......@@ -287,10 +300,7 @@ export class FindModelBoundToEditorModel {
return this._moveToNextMatch(nextMatch.getEndPosition(), true);
}
let matchesPosition = this._decorations.setCurrentFindMatch(nextMatch);
this._state.changeMatchInfo(matchesPosition, this._decorations.getCount());
this._editor.setSelection(nextMatch);
this._editor.revealRangeInCenterIfOutsideViewport(nextMatch);
this._setCurrentFindMatch(nextMatch);
}
public moveToNextMatch(): void {
......
......@@ -21,6 +21,7 @@ export interface FindReplaceStateChangedEvent {
searchScope: boolean;
matchesPosition: boolean;
matchesCount: boolean;
currentMatch: boolean;
}
export interface INewFindReplaceState {
......@@ -48,6 +49,7 @@ export class FindReplaceState implements IDisposable {
private _searchScope: Range;
private _matchesPosition: number;
private _matchesCount: number;
private _currentMatch: Range;
private _eventEmitter: EventEmitter;
public get searchString(): string { return this._searchString; }
......@@ -60,6 +62,7 @@ export class FindReplaceState implements IDisposable {
public get searchScope(): Range { return this._searchScope; }
public get matchesPosition(): number { return this._matchesPosition; }
public get matchesCount(): number { return this._matchesCount; }
public get currentMatch(): Range { return this._currentMatch; }
constructor() {
this._searchString = '';
......@@ -72,6 +75,7 @@ export class FindReplaceState implements IDisposable {
this._searchScope = null;
this._matchesPosition = 0;
this._matchesCount = 0;
this._currentMatch = null;
this._eventEmitter = new EventEmitter();
}
......@@ -83,7 +87,7 @@ export class FindReplaceState implements IDisposable {
return this._eventEmitter.addListener2(FindReplaceState._CHANGED_EVENT, listener);
}
public changeMatchInfo(matchesPosition:number, matchesCount:number): void {
public changeMatchInfo(matchesPosition:number, matchesCount:number, currentMatch:Range): void {
let changeEvent:FindReplaceStateChangedEvent = {
moveCursor: false,
searchString: false,
......@@ -95,7 +99,8 @@ export class FindReplaceState implements IDisposable {
matchCase: false,
searchScope: false,
matchesPosition: false,
matchesCount: false
matchesCount: false,
currentMatch: false
};
let somethingChanged = false;
......@@ -117,6 +122,14 @@ export class FindReplaceState implements IDisposable {
somethingChanged = true;
}
if (typeof currentMatch !== 'undefined') {
if (!Range.equalsRange(this._currentMatch, currentMatch)) {
this._currentMatch = currentMatch;
changeEvent.currentMatch = true;
somethingChanged = true;
}
}
if (somethingChanged) {
this._eventEmitter.emit(FindReplaceState._CHANGED_EVENT, changeEvent);
}
......@@ -134,7 +147,8 @@ export class FindReplaceState implements IDisposable {
matchCase: false,
searchScope: false,
matchesPosition: false,
matchesCount: false
matchesCount: false,
currentMatch: false
};
let somethingChanged = false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册