Skip to content

Commit 2635da4

Browse files
guttyonvsgutcodealexdima
authored
Temporarily disable input method interception. (microsoft#159699)
* Temporarily disable input method interception. fixes microsoft#151496 rebase, sync fork Author: guttyon <[email protected]> interactive rebase in progress; onto 851a0da Last command done (1 command done): pick e021b16 Temporarily disable input method interception. fixes microsoft#151496 Next command to do (1 remaining command): pick 07b3ec4be36 add keybindingChordMode. move ime code into if-closure in _leaveChordMode. Because original code is called multi time while typing key. You are currently rebasing branch 'temporarily_disable_input_method_interception' on '851a0dad5dd'. * add keybindingChordMode. move ime code into if-closure in _leaveChordMode. Because original code is called multi time while typing key. * remove ipcRender.send * remove ffi-napi * remove \n * Added to test that the keybindingChordMode command is called. * Make all editors readonly when in chord mode to suppress composing Co-authored-by: vsgutcode <[email protected]> Co-authored-by: Alexandru Dima <[email protected]>
1 parent 3a75026 commit 2635da4

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

src/vs/base/common/ime.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { Emitter } from 'vs/base/common/event';
7+
8+
export class IMEImpl {
9+
10+
private readonly _onDidChange = new Emitter<void>();
11+
public readonly onDidChange = this._onDidChange.event;
12+
13+
private _enabled = true;
14+
15+
public get enabled() {
16+
return this._enabled;
17+
}
18+
19+
/**
20+
* Enable IME
21+
*/
22+
public enable(): void {
23+
this._enabled = true;
24+
this._onDidChange.fire();
25+
}
26+
27+
/**
28+
* Disable IME
29+
*/
30+
public disable(): void {
31+
this._enabled = false;
32+
this._onDidChange.fire();
33+
}
34+
}
35+
36+
export const IME = new IMEImpl();

src/vs/editor/browser/controller/textAreaHandler.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { TokenizationRegistry } from 'vs/editor/common/languages';
3535
import { ColorId, ITokenPresentation } from 'vs/editor/common/encodedTokenAttributes';
3636
import { Color } from 'vs/base/common/color';
3737
import { TimeoutTimer } from 'vs/base/common/async';
38+
import { IME } from 'vs/base/common/ime';
3839

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

189-
if (options.get(EditorOption.domReadOnly) && options.get(EditorOption.readOnly)) {
190-
this.textArea.setAttribute('readonly', 'true');
191-
}
190+
this._ensureReadOnlyAttribute();
192191

193192
this.textAreaCover = createFastDomNode(document.createElement('div'));
194193
this.textAreaCover.setPosition('absolute');
@@ -464,6 +463,10 @@ export class TextAreaHandler extends ViewPart {
464463
this._register(this._textAreaInput.onBlur(() => {
465464
this._context.viewModel.setHasFocus(false);
466465
}));
466+
467+
this._register(IME.onDidChange(() => {
468+
this._ensureReadOnlyAttribute();
469+
}));
467470
}
468471

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

597600
if (e.hasChanged(EditorOption.domReadOnly) || e.hasChanged(EditorOption.readOnly)) {
598-
if (options.get(EditorOption.domReadOnly) && options.get(EditorOption.readOnly)) {
599-
this.textArea.setAttribute('readonly', 'true');
600-
} else {
601-
this.textArea.removeAttribute('readonly');
602-
}
601+
this._ensureReadOnlyAttribute();
603602
}
604603

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

681680
// --- end view API
682681

682+
private _ensureReadOnlyAttribute(): void {
683+
const options = this._context.configuration.options;
684+
// When someone requests to disable IME, we set the "readonly" attribute on the <textarea>.
685+
// This will prevent composition.
686+
const useReadOnly = !IME.enabled || (options.get(EditorOption.domReadOnly) && options.get(EditorOption.readOnly));
687+
if (useReadOnly) {
688+
this.textArea.setAttribute('readonly', 'true');
689+
} else {
690+
this.textArea.removeAttribute('readonly');
691+
}
692+
}
693+
683694
private _primaryCursorPosition: Position = new Position(1, 1);
684695
private _primaryCursorVisibleRange: HorizontalPosition | null = null;
685696

src/vs/platform/keybinding/common/abstractKeybindingService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKe
1919
import { ILogService } from 'vs/platform/log/common/log';
2020
import { INotificationService } from 'vs/platform/notification/common/notification';
2121
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
22+
import { IME } from 'vs/base/common/ime';
2223

2324
interface CurrentChord {
2425
keypress: string;
@@ -164,6 +165,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
164165
}
165166

166167
}, 500);
168+
IME.disable();
167169
}
168170

169171
private _leaveChordMode(): void {
@@ -173,6 +175,7 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
173175
}
174176
this._currentChordChecker.cancel();
175177
this._currentChord = null;
178+
IME.enable();
176179
}
177180

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

0 commit comments

Comments
 (0)