Skip to content

Commit 3f593c9

Browse files
committed
Fixes microsoft#90016: Allow quotes to surround selection when using the mac US Intl keyboard layout
1 parent 85dda6d commit 3f593c9

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

src/vs/editor/common/controller/cursor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
779779
}
780780

781781
private _type(source: string, text: string): void {
782-
if (!this._isDoingComposition && source === 'keyboard') {
782+
if (source === 'keyboard') {
783783
// If this event is coming straight from the keyboard, look for electric characters and enter
784784

785785
const len = text.length;
@@ -790,7 +790,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
790790

791791
// Here we must interpret each typed character individually
792792
const autoClosedCharacters = AutoClosedAction.getAllAutoClosedCharacters(this._autoClosedActions);
793-
this._executeEditOperation(TypeOperations.typeWithInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), autoClosedCharacters, chr));
793+
this._executeEditOperation(TypeOperations.typeWithInterceptors(this._isDoingComposition, this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), autoClosedCharacters, chr));
794794

795795
offset += charLength;
796796
}

src/vs/editor/common/controller/cursorTypeOperations.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,9 @@ export class TypeOperations {
796796
return null;
797797
}
798798

799-
public static typeWithInterceptors(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selections: Selection[], autoClosedCharacters: Range[], ch: string): EditOperationResult {
799+
public static typeWithInterceptors(isDoingComposition: boolean, prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selections: Selection[], autoClosedCharacters: Range[], ch: string): EditOperationResult {
800800

801-
if (ch === '\n') {
801+
if (!isDoingComposition && ch === '\n') {
802802
let commands: ICommand[] = [];
803803
for (let i = 0, len = selections.length; i < len; i++) {
804804
commands[i] = TypeOperations._enter(config, model, false, selections[i]);
@@ -809,7 +809,7 @@ export class TypeOperations {
809809
});
810810
}
811811

812-
if (this._isAutoIndentType(config, model, selections)) {
812+
if (!isDoingComposition && this._isAutoIndentType(config, model, selections)) {
813813
let commands: Array<ICommand | null> = [];
814814
let autoIndentFails = false;
815815
for (let i = 0, len = selections.length; i < len; i++) {
@@ -827,13 +827,15 @@ export class TypeOperations {
827827
}
828828
}
829829

830-
if (this._isAutoClosingOvertype(config, model, selections, autoClosedCharacters, ch)) {
830+
if (!isDoingComposition && this._isAutoClosingOvertype(config, model, selections, autoClosedCharacters, ch)) {
831831
return this._runAutoClosingOvertype(prevEditOperationType, config, model, selections, ch);
832832
}
833833

834-
const autoClosingPairOpenCharType = this._isAutoClosingOpenCharType(config, model, selections, ch, true);
835-
if (autoClosingPairOpenCharType) {
836-
return this._runAutoClosingOpenCharType(prevEditOperationType, config, model, selections, ch, true, autoClosingPairOpenCharType);
834+
if (!isDoingComposition) {
835+
const autoClosingPairOpenCharType = this._isAutoClosingOpenCharType(config, model, selections, ch, true);
836+
if (autoClosingPairOpenCharType) {
837+
return this._runAutoClosingOpenCharType(prevEditOperationType, config, model, selections, ch, true, autoClosingPairOpenCharType);
838+
}
837839
}
838840

839841
if (this._isSurroundSelectionType(config, model, selections, ch)) {
@@ -842,7 +844,7 @@ export class TypeOperations {
842844

843845
// Electric characters make sense only when dealing with a single cursor,
844846
// as multiple cursors typing brackets for example would interfer with bracket matching
845-
if (this._isTypeInterceptorElectricChar(config, model, selections)) {
847+
if (!isDoingComposition && this._isTypeInterceptorElectricChar(config, model, selections)) {
846848
const r = this._typeInterceptorElectricChar(prevEditOperationType, config, model, selections[0], ch);
847849
if (r) {
848850
return r;

src/vs/editor/test/browser/controller/cursor.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5044,6 +5044,28 @@ suite('autoClosingPairs', () => {
50445044
mode.dispose();
50455045
});
50465046

5047+
test('issue #90016: allow accents on mac US intl keyboard to surround selection', () => {
5048+
let mode = new AutoClosingMode();
5049+
usingCursor({
5050+
text: [
5051+
'test'
5052+
],
5053+
languageIdentifier: mode.getLanguageIdentifier()
5054+
}, (model, cursor) => {
5055+
cursor.setSelections('test', [new Selection(1, 1, 1, 5)]);
5056+
5057+
// Typing ` + e on the mac US intl kb layout
5058+
cursorCommand(cursor, H.CompositionStart, null, 'keyboard');
5059+
cursorCommand(cursor, H.Type, { text: '\'' }, 'keyboard');
5060+
cursorCommand(cursor, H.ReplacePreviousChar, { replaceCharCnt: 1, text: '\'' }, 'keyboard');
5061+
cursorCommand(cursor, H.ReplacePreviousChar, { replaceCharCnt: 1, text: '\'' }, 'keyboard');
5062+
cursorCommand(cursor, H.CompositionEnd, null, 'keyboard');
5063+
5064+
assert.equal(model.getValue(), '\'test\'');
5065+
});
5066+
mode.dispose();
5067+
});
5068+
50475069
test('issue #53357: Over typing ignores characters after backslash', () => {
50485070
let mode = new AutoClosingMode();
50495071
usingCursor({

0 commit comments

Comments
 (0)