提交 292732cd 编写于 作者: A Alex Dima

Clarify editor focus related methods

上级 ba50c629
......@@ -1651,7 +1651,7 @@ class EditorOrNativeTextInputCommand extends Command {
let focusedEditor = findFocusedEditor(accessor);
// Only if editor text focus (i.e. not if editor has widget focus).
if (focusedEditor && focusedEditor.isFocused()) {
if (focusedEditor && focusedEditor.hasTextFocus()) {
return this._runEditorHandler(focusedEditor, args);
}
......
......@@ -365,12 +365,12 @@ export interface ICodeEditor extends editorCommon.IEditor {
*/
onDidChangeModelDecorations(listener: (e: IModelDecorationsChangedEvent) => void): IDisposable;
/**
* An event emitted when the text inside this editor gained focus (i.e. cursor blinking).
* An event emitted when the text inside this editor gained focus (i.e. cursor starts blinking).
* @event
*/
onDidFocusEditorText(listener: () => void): IDisposable;
/**
* An event emitted when the text inside this editor lost focus.
* An event emitted when the text inside this editor lost focus (i.e. cursor stops blinking).
* @event
*/
onDidBlurEditorText(listener: () => void): IDisposable;
......@@ -378,12 +378,12 @@ export interface ICodeEditor extends editorCommon.IEditor {
* An event emitted when the text inside this editor or an editor widget gained focus.
* @event
*/
onDidFocusEditor(listener: () => void): IDisposable;
onDidFocusEditorWidget(listener: () => void): IDisposable;
/**
* An event emitted when the text inside this editor or an editor widget lost focus.
* @event
*/
onDidBlurEditor(listener: () => void): IDisposable;
onDidBlurEditorWidget(listener: () => void): IDisposable;
/**
* An event emitted before interpreting typed characters (on the keyboard).
* @event
......@@ -477,7 +477,7 @@ export interface ICodeEditor extends editorCommon.IEditor {
restoreViewState(state: editorCommon.ICodeEditorViewState): void;
/**
* Returns true if this editor or one of its widgets has keyboard focus.
* Returns true if the text inside this editor or an editor widget has focus.
*/
hasWidgetFocus(): boolean;
......
......@@ -84,7 +84,7 @@ export abstract class AbstractCodeEditorService implements ICodeEditorService {
for (let i = 0; i < editors.length; i++) {
let editor = editors[i];
if (editor.isFocused()) {
if (editor.hasTextFocus()) {
// bingo!
return editor;
}
......
......@@ -115,9 +115,9 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
public readonly onDidFocusEditorText: Event<void> = this._editorTextFocus.onDidChangeToTrue;
public readonly onDidBlurEditorText: Event<void> = this._editorTextFocus.onDidChangeToFalse;
private _editorFocus: BooleanEventEmitter = this._register(new BooleanEventEmitter());
public readonly onDidFocusEditor: Event<void> = this._editorFocus.onDidChangeToTrue;
public readonly onDidBlurEditor: Event<void> = this._editorFocus.onDidChangeToFalse;
private _editorWidgetFocus: BooleanEventEmitter = this._register(new BooleanEventEmitter());
public readonly onDidFocusEditorWidget: Event<void> = this._editorWidgetFocus.onDidChangeToTrue;
public readonly onDidBlurEditorWidget: Event<void> = this._editorWidgetFocus.onDidChangeToFalse;
private readonly _onWillType: Emitter<string> = this._register(new Emitter<string>());
public readonly onWillType = this._onWillType.event;
......@@ -246,7 +246,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
this._focusTracker = new CodeEditorWidgetFocusTracker(domElement);
this._focusTracker.onChange(() => {
this._editorFocus.setValue(this._focusTracker.hasFocus());
this._editorWidgetFocus.setValue(this._focusTracker.hasFocus());
});
this.contentWidgets = {};
......@@ -1109,7 +1109,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
this._view.focus();
}
public isFocused(): boolean {
public hasTextFocus(): boolean {
return this.hasView && this._view.isFocused();
}
......@@ -1418,7 +1418,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
viewEventBus.onDidGainFocus = () => {
this._editorTextFocus.setValue(true);
// In IE, the focus is not synchronous, so we give it a little help
this._editorFocus.setValue(true);
this._editorWidgetFocus.setValue(true);
};
viewEventBus.onDidScroll = (e) => this._onDidScrollChange.fire(e);
......@@ -1563,8 +1563,8 @@ class EditorContextKeysManager extends Disposable {
this._register(this._editor.onDidChangeConfiguration(() => this._updateFromConfig()));
this._register(this._editor.onDidChangeCursorSelection(() => this._updateFromSelection()));
this._register(this._editor.onDidFocusEditor(() => this._updateFromFocus()));
this._register(this._editor.onDidBlurEditor(() => this._updateFromFocus()));
this._register(this._editor.onDidFocusEditorWidget(() => this._updateFromFocus()));
this._register(this._editor.onDidBlurEditorWidget(() => this._updateFromFocus()));
this._register(this._editor.onDidFocusEditorText(() => this._updateFromFocus()));
this._register(this._editor.onDidBlurEditorText(() => this._updateFromFocus()));
......@@ -1593,8 +1593,8 @@ class EditorContextKeysManager extends Disposable {
private _updateFromFocus(): void {
this._editorFocus.set(this._editor.hasWidgetFocus() && !this._editor.isSimpleWidget);
this._editorTextFocus.set(this._editor.isFocused() && !this._editor.isSimpleWidget);
this._textInputFocus.set(this._editor.isFocused());
this._editorTextFocus.set(this._editor.hasTextFocus() && !this._editor.isSimpleWidget);
this._textInputFocus.set(this._editor.hasTextFocus());
}
}
......
......@@ -749,8 +749,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this.modifiedEditor.focus();
}
public isFocused(): boolean {
return this.originalEditor.isFocused() || this.modifiedEditor.isFocused();
public hasTextFocus(): boolean {
return this.originalEditor.hasTextFocus() || this.modifiedEditor.hasTextFocus();
}
public onVisible(): void {
......
......@@ -124,12 +124,12 @@ export class DiffReview extends Disposable {
}
this._render();
}));
this._register(diffEditor.getOriginalEditor().onDidFocusEditor(() => {
this._register(diffEditor.getOriginalEditor().onDidFocusEditorWidget(() => {
if (this._isVisible) {
this.hide();
}
}));
this._register(diffEditor.getModifiedEditor().onDidFocusEditor(() => {
this._register(diffEditor.getModifiedEditor().onDidFocusEditorWidget(() => {
if (this._isVisible) {
this.hide();
}
......
......@@ -291,9 +291,9 @@ export interface IEditor {
focus(): void;
/**
* Returns true if this editor has keyboard focus (e.g. cursor is blinking).
* Returns true if the text inside this editor is focused (i.e. cursor is blinking).
*/
isFocused(): boolean;
hasTextFocus(): boolean;
/**
* Returns all actions associated with this editor.
......
......@@ -42,7 +42,7 @@ abstract class ExecCommandAction extends EditorAction {
public runCommand(accessor: ServicesAccessor, args: any): void {
let focusedEditor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
// Only if editor text focus (i.e. not if editor has widget focus).
if (focusedEditor && focusedEditor.isFocused()) {
if (focusedEditor && focusedEditor.hasTextFocus()) {
focusedEditor.trigger('keyboard', this.id, args);
return;
}
......
......@@ -155,7 +155,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
this._updateToggleSelectionFindButton();
}
}));
this._register(this._codeEditor.onDidFocusEditor(() => {
this._register(this._codeEditor.onDidFocusEditorWidget(() => {
if (this._isVisible) {
let globalBufferTerm = this._controller.getGlobalBufferTerm();
if (globalBufferTerm && globalBufferTerm !== this._state.searchString) {
......
......@@ -156,7 +156,7 @@ export class MultiCursorSession {
// - focus is not in the editor (i.e. it is in the find widget)
// - and the search widget is visible
// - and the search string is non-empty
if (!editor.isFocused() && findState.isRevealed && findState.searchString.length > 0) {
if (!editor.hasTextFocus() && findState.isRevealed && findState.searchString.length > 0) {
// Find widget owns what is searched for
return new MultiCursorSession(editor, findController, false, findState.searchString, findState.wholeWord, findState.matchCase, null);
}
......
......@@ -179,7 +179,7 @@ export abstract class ReferencesController implements editorCommon.IEditorContri
if (this._model) { // can be called while still resolving...
let source = this._model.nearestReference(this._editor.getModel().uri, this._widget.position);
let target = this._model.nextOrPreviousReference(source, fwd);
let editorFocus = this._editor.isFocused();
let editorFocus = this._editor.hasTextFocus();
await this._widget.setSelection(target);
await this._gotoReference(target);
if (editorFocus) {
......
......@@ -167,7 +167,7 @@ export default class RenameInputField implements IContentWidget, IDisposable {
};
disposeOnDone.push(this._editor.onDidChangeCursorSelection(onCursorChanged));
disposeOnDone.push(this._editor.onDidBlurEditor(() => this.cancelInput(false)));
disposeOnDone.push(this._editor.onDidBlurEditorWidget(() => this.cancelInput(false)));
this._show();
......
......@@ -481,7 +481,7 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
}
this.editorBlurTimeout = TPromise.timeout(150).then(() => {
if (!this.editor.isFocused()) {
if (!this.editor.hasTextFocus()) {
this.setState(State.Hidden);
}
});
......
......@@ -2014,9 +2014,9 @@ declare namespace monaco.editor {
*/
focus(): void;
/**
* Returns true if this editor has keyboard focus (e.g. cursor is blinking).
* Returns true if the text inside this editor is focused (i.e. cursor is blinking).
*/
isFocused(): boolean;
hasTextFocus(): boolean;
/**
* Returns all actions associated with this editor.
*/
......@@ -3639,12 +3639,12 @@ declare namespace monaco.editor {
*/
onDidChangeModelDecorations(listener: (e: IModelDecorationsChangedEvent) => void): IDisposable;
/**
* An event emitted when the text inside this editor gained focus (i.e. cursor blinking).
* An event emitted when the text inside this editor gained focus (i.e. cursor starts blinking).
* @event
*/
onDidFocusEditorText(listener: () => void): IDisposable;
/**
* An event emitted when the text inside this editor lost focus.
* An event emitted when the text inside this editor lost focus (i.e. cursor stops blinking).
* @event
*/
onDidBlurEditorText(listener: () => void): IDisposable;
......@@ -3652,12 +3652,12 @@ declare namespace monaco.editor {
* An event emitted when the text inside this editor or an editor widget gained focus.
* @event
*/
onDidFocusEditor(listener: () => void): IDisposable;
onDidFocusEditorWidget(listener: () => void): IDisposable;
/**
* An event emitted when the text inside this editor or an editor widget lost focus.
* @event
*/
onDidBlurEditor(listener: () => void): IDisposable;
onDidBlurEditorWidget(listener: () => void): IDisposable;
/**
* An event emitted on a "mouseup".
* @event
......@@ -3712,7 +3712,7 @@ declare namespace monaco.editor {
*/
restoreViewState(state: ICodeEditorViewState): void;
/**
* Returns true if this editor or one of its widgets has keyboard focus.
* Returns true if the text inside this editor or an editor widget has focus.
*/
hasWidgetFocus(): boolean;
/**
......
......@@ -244,7 +244,7 @@ class MainThreadDocumentAndEditorStateComputer {
) {
const apiEditor = new TextEditorSnapshot(editor);
editors.set(apiEditor.id, apiEditor);
if (editor.isFocused()) {
if (editor.hasTextFocus()) {
activeEditor = apiEditor.id;
}
}
......
......@@ -266,10 +266,10 @@ export class MainThreadTextEditor {
this.setCodeEditor(null);
}));
this._codeEditorListeners.push(this._codeEditor.onDidFocusEditor(() => {
this._codeEditorListeners.push(this._codeEditor.onDidFocusEditorWidget(() => {
this._focusTracker.onGainedFocus();
}));
this._codeEditorListeners.push(this._codeEditor.onDidBlurEditor(() => {
this._codeEditorListeners.push(this._codeEditor.onDidBlurEditorWidget(() => {
this._focusTracker.onLostFocus();
}));
......@@ -423,7 +423,7 @@ export class MainThreadTextEditor {
public isFocused(): boolean {
if (this._codeEditor) {
return this._codeEditor.isFocused();
return this._codeEditor.hasTextFocus();
}
return false;
}
......
......@@ -92,7 +92,7 @@ function findEditor(model: ITextModel, codeEditorService: ICodeEditorService): I
if (model.isAttachedToEditor()) {
for (const editor of codeEditorService.listCodeEditors()) {
if (editor.getModel() === model) {
if (editor.isFocused()) {
if (editor.hasTextFocus()) {
return editor; // favour focused editor if there are multiple
}
......
......@@ -140,10 +140,10 @@ export abstract class BaseTextEditor extends BaseEditor {
// Application & Editor focus change to respect auto save settings
if (isCodeEditor(this.editorControl)) {
this.toUnbind.push(this.editorControl.onDidBlurEditor(() => this.onEditorFocusLost()));
this.toUnbind.push(this.editorControl.onDidBlurEditorWidget(() => this.onEditorFocusLost()));
} else if (isDiffEditor(this.editorControl)) {
this.toUnbind.push(this.editorControl.getOriginalEditor().onDidBlurEditor(() => this.onEditorFocusLost()));
this.toUnbind.push(this.editorControl.getModifiedEditor().onDidBlurEditor(() => this.onEditorFocusLost()));
this.toUnbind.push(this.editorControl.getOriginalEditor().onDidBlurEditorWidget(() => this.onEditorFocusLost()));
this.toUnbind.push(this.editorControl.getModifiedEditor().onDidBlurEditorWidget(() => this.onEditorFocusLost()));
}
this.toUnbind.push(this.editorGroupService.onEditorsChanged(() => this.onEditorFocusLost()));
......
......@@ -782,7 +782,7 @@ class SideBySidePreferencesWidget extends Widget {
this.defaultPreferencesEditor = this._register(this.instantiationService.createInstance(DefaultPreferencesEditor));
this.defaultPreferencesEditor.create(this.defaultPreferencesEditorContainer);
this.defaultPreferencesEditor.setVisible(true);
(<CodeEditorWidget>this.defaultPreferencesEditor.getControl()).onDidFocusEditor(() => this.lastFocusedEditor = this.defaultPreferencesEditor);
(<CodeEditorWidget>this.defaultPreferencesEditor.getControl()).onDidFocusEditorWidget(() => this.lastFocusedEditor = this.defaultPreferencesEditor);
this.editablePreferencesEditorContainer = DOM.append(parentElement, DOM.$('.editable-preferences-editor-container'));
this.editablePreferencesEditorContainer.style.position = 'absolute';
......@@ -879,7 +879,7 @@ class SideBySidePreferencesWidget extends Widget {
this.editablePreferencesEditor = editor;
this.editablePreferencesEditor.create(this.editablePreferencesEditorContainer);
this.editablePreferencesEditor.setVisible(true);
(<CodeEditorWidget>this.editablePreferencesEditor.getControl()).onDidFocusEditor(() => this.lastFocusedEditor = this.editablePreferencesEditor);
(<CodeEditorWidget>this.editablePreferencesEditor.getControl()).onDidFocusEditorWidget(() => this.lastFocusedEditor = this.editablePreferencesEditor);
this.lastFocusedEditor = this.editablePreferencesEditor;
return editor;
......
......@@ -172,7 +172,7 @@ function getOuterEditorFromDiffEditor(accessor: ServicesAccessor): ICodeEditor {
const diffEditors = accessor.get(ICodeEditorService).listDiffEditors();
for (const diffEditor of diffEditors) {
if (diffEditor.isFocused() && diffEditor instanceof EmbeddedDiffEditorWidget) {
if (diffEditor.hasTextFocus() && diffEditor instanceof EmbeddedDiffEditorWidget) {
return diffEditor.getParentEditor();
}
}
......
......@@ -891,7 +891,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
let editorControl = this.editorService.getActiveEditor().getControl();
if (isDiffEditor(editorControl)) {
if (editorControl.getOriginalEditor().isFocused()) {
if (editorControl.getOriginalEditor().hasTextFocus()) {
editorControl = editorControl.getOriginalEditor();
} else {
editorControl = editorControl.getModifiedEditor();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册