Skip to content

Commit

Permalink
Merge pull request #61206 from roytang/master
Browse files Browse the repository at this point in the history
Fixes #15043 Format selection keyboard shortcut will …
  • Loading branch information
jrieken authored Oct 23, 2018
2 parents d1206c6 + 250f27a commit e489a70
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/vs/editor/contrib/format/formatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export class FormatSelectionAction extends AbstractFormatAction {
id: 'editor.action.formatSelection',
label: nls.localize('formatSelection.label', "Format Selection"),
alias: 'Format Code',
precondition: ContextKeyExpr.and(EditorContextKeys.writable, EditorContextKeys.hasNonEmptySelection),
precondition: ContextKeyExpr.and(EditorContextKeys.writable),
kbOpts: {
kbExpr: EditorContextKeys.editorTextFocus,
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_F),
Expand All @@ -357,8 +357,14 @@ export class FormatSelectionAction extends AbstractFormatAction {

protected _getFormattingEdits(editor: ICodeEditor, token: CancellationToken): Promise<ISingleEditOperation[]> {
const model = editor.getModel();
let selection = editor.getSelection();
if (selection.isEmpty()) {
const maxColumn = model.getLineMaxColumn(selection.startLineNumber);
selection = selection.setStartPosition(selection.startLineNumber, 1);
selection = selection.setEndPosition(selection.endLineNumber, maxColumn);
}
const { tabSize, insertSpaces } = model.getOptions();
return getDocumentRangeFormattingEdits(model, editor.getSelection(), { tabSize, insertSpaces }, token);
return getDocumentRangeFormattingEdits(model, selection, { tabSize, insertSpaces }, token);
}

protected _notifyNoProviderError(notificationService: INotificationService, language: string): void {
Expand Down

0 comments on commit e489a70

Please sign in to comment.