Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/vs/base/common/ime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Emitter } from 'vs/base/common/event';

export class IMEImpl {

private readonly _onDidChange = new Emitter<void>();
public readonly onDidChange = this._onDidChange.event;

private _enabled = true;

public get enabled() {
return this._enabled;
}

/**
* Enable IME
*/
public enable(): void {
this._enabled = true;
this._onDidChange.fire();
}

/**
* Disable IME
*/
public disable(): void {
this._enabled = false;
this._onDidChange.fire();
}
}

export const IME = new IMEImpl();
27 changes: 19 additions & 8 deletions src/vs/editor/browser/controller/textAreaHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { TokenizationRegistry } from 'vs/editor/common/languages';
import { ColorId, ITokenPresentation } from 'vs/editor/common/encodedTokenAttributes';
import { Color } from 'vs/base/common/color';
import { TimeoutTimer } from 'vs/base/common/async';
import { IME } from 'vs/base/common/ime';

export interface IVisibleRangeProvider {
visibleRangeForPosition(position: Position): HorizontalPosition | null;
Expand Down Expand Up @@ -186,9 +187,7 @@ export class TextAreaHandler extends ViewPart {
this.textArea.setAttribute('aria-haspopup', 'false');
this.textArea.setAttribute('aria-autocomplete', 'both');

if (options.get(EditorOption.domReadOnly) && options.get(EditorOption.readOnly)) {
this.textArea.setAttribute('readonly', 'true');
}
this._ensureReadOnlyAttribute();

this.textAreaCover = createFastDomNode(document.createElement('div'));
this.textAreaCover.setPosition('absolute');
Expand Down Expand Up @@ -464,6 +463,10 @@ export class TextAreaHandler extends ViewPart {
this._register(this._textAreaInput.onBlur(() => {
this._context.viewModel.setHasFocus(false);
}));

this._register(IME.onDidChange(() => {
this._ensureReadOnlyAttribute();
}));
}

public override dispose(): void {
Expand Down Expand Up @@ -595,11 +598,7 @@ export class TextAreaHandler extends ViewPart {
this.textArea.setAttribute('tabindex', String(options.get(EditorOption.tabIndex)));

if (e.hasChanged(EditorOption.domReadOnly) || e.hasChanged(EditorOption.readOnly)) {
if (options.get(EditorOption.domReadOnly) && options.get(EditorOption.readOnly)) {
this.textArea.setAttribute('readonly', 'true');
} else {
this.textArea.removeAttribute('readonly');
}
this._ensureReadOnlyAttribute();
}

if (e.hasChanged(EditorOption.accessibilitySupport)) {
Expand Down Expand Up @@ -680,6 +679,18 @@ export class TextAreaHandler extends ViewPart {

// --- end view API

private _ensureReadOnlyAttribute(): void {
const options = this._context.configuration.options;
// When someone requests to disable IME, we set the "readonly" attribute on the <textarea>.
// This will prevent composition.
const useReadOnly = !IME.enabled || (options.get(EditorOption.domReadOnly) && options.get(EditorOption.readOnly));
if (useReadOnly) {
this.textArea.setAttribute('readonly', 'true');
} else {
this.textArea.removeAttribute('readonly');
}
}

private _primaryCursorPosition: Position = new Position(1, 1);
private _primaryCursorVisibleRange: HorizontalPosition | null = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKe
import { ILogService } from 'vs/platform/log/common/log';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IME } from 'vs/base/common/ime';

interface CurrentChord {
keypress: string;
Expand Down Expand Up @@ -164,6 +165,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
}

}, 500);
IME.disable();
}

private _leaveChordMode(): void {
Expand All @@ -173,6 +175,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
}
this._currentChordChecker.cancel();
this._currentChord = null;
IME.enable();
}

public dispatchByUserSettingsLabel(userSettingsLabel: string, target: IContextKeyServiceTarget): void {
Expand Down