toggleWordWrap.ts 1.3 KB
Newer Older
I
ivanixgames 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

A
Alex Dima 已提交
7
import * as nls from 'vs/nls';
J
Johannes Rieken 已提交
8 9 10
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ICommonCodeEditor, EditorContextKeys } from 'vs/editor/common/editorCommon';
import { editorAction, ServicesAccessor, EditorAction } from 'vs/editor/common/editorCommonExtensions';
A
Alex Dima 已提交
11

A
Alex Dima 已提交
12
@editorAction
A
Alex Dima 已提交
13
class ToggleWordWrapAction extends EditorAction {
A
Alex Dima 已提交
14 15

	constructor() {
16 17 18 19 20 21 22 23 24 25
		super({
			id: 'editor.action.toggleWordWrap',
			label: nls.localize('toggle.wordwrap', "View: Toggle Word Wrap"),
			alias: 'View: Toggle Word Wrap',
			precondition: null,
			kbOpts: {
				kbExpr: EditorContextKeys.TextFocus,
				primary: KeyMod.Alt | KeyCode.KEY_Z
			}
		});
I
ivanixgames 已提交
26 27
	}

J
Johannes Rieken 已提交
28
	public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
I
ivanixgames 已提交
29

A
Alex Dima 已提交
30
		let wrappingInfo = editor.getConfiguration().wrappingInfo;
I
ivanixgames 已提交
31

32
		let newWrappingColumn: number;
A
tslint  
Alex Dima 已提交
33
		if (!wrappingInfo.isViewportWrapping) {
34
			newWrappingColumn = 0;
I
ivanixgames 已提交
35
		} else {
36
			newWrappingColumn = -1;
I
ivanixgames 已提交
37
		}
38

A
Alex Dima 已提交
39
		editor.updateOptions({
40 41
			wrappingColumn: newWrappingColumn
		});
I
ivanixgames 已提交
42 43
	}
}