未验证 提交 e489a700 编写于 作者: J Johannes Rieken 提交者: GitHub

Merge pull request #61206 from roytang/master

Fixes Microsoft/vscode#15043 Format selection keyboard shortcut will …
......@@ -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),
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册