Skip to content

Commit

Permalink
Fixes #7682: Always respect tab preference
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Jul 15, 2016
1 parent ce720d5 commit 7fa48d2
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/vs/editor/common/controller/oneCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,25 @@ export class OneCursorOp {
return result;
}

private static _replaceJumpToNextIndent(cursor:OneCursor, selection:Selection): ReplaceCommand {
let typeText = '';

let position = selection.getStartPosition();
let modelOpts = cursor.model.getOptions();
if (modelOpts.insertSpaces) {
let visibleColumnFromColumn = cursor.getVisibleColumnFromColumn(position.lineNumber, position.column);
let tabSize = modelOpts.tabSize;
let spacesCnt = tabSize - (visibleColumnFromColumn % tabSize);
for (let i = 0; i < spacesCnt; i++) {
typeText += ' ';
}
} else {
typeText = '\t';
}

return new ReplaceCommand(selection, typeText);
}

public static tab(cursor:OneCursor, ctx: IOneCursorOperationContext): boolean {
let selection = cursor.getSelection();

Expand All @@ -1529,28 +1548,14 @@ export class OneCursorOp {
}
}

let typeText = '';
let position = cursor.getPosition();
let modelOpts = cursor.model.getOptions();
if (modelOpts.insertSpaces) {
let visibleColumnFromColumn = cursor.getVisibleColumnFromColumn(position.lineNumber, position.column);
let tabSize = modelOpts.tabSize;
let spacesCnt = tabSize - (visibleColumnFromColumn % tabSize);
for (let i = 0; i < spacesCnt; i++) {
typeText += ' ';
}
} else {
typeText = '\t';
}

ctx.executeCommand = new ReplaceCommand(selection, typeText);
ctx.executeCommand = this._replaceJumpToNextIndent(cursor, selection);
return true;
} else {
if (selection.startLineNumber === selection.endLineNumber) {
let lineMaxColumn = cursor.model.getLineMaxColumn(selection.startLineNumber);
if (selection.startColumn !== 1 || selection.endColumn !== lineMaxColumn) {
// This is a single line selection that is not the entire line
ctx.executeCommand = new ReplaceCommand(selection, '\t');
ctx.executeCommand = this._replaceJumpToNextIndent(cursor, selection);
return true;
}
}
Expand Down

0 comments on commit 7fa48d2

Please sign in to comment.