Skip to content

Commit

Permalink
Fixes #23445
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Mar 29, 2017
1 parent 3db0796 commit 543f956
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 23 deletions.
13 changes: 1 addition & 12 deletions src/vs/editor/browser/widget/diffEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,6 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif
if (type === editorCommon.EventType.ViewZonesChanged) {
this._onViewZonesChanged();
}
if (type === editorCommon.EventType.ConfigurationChanged) {
let isViewportWrapping = this.originalEditor.getConfiguration().wrappingInfo.isViewportWrapping;
if (isViewportWrapping) {
// oh no, you didn't!
this.originalEditor.updateOptions({ wordWrap: 'off' });
}
}
}
this._recomputeIfNecessary(events);
}
Expand All @@ -805,11 +798,6 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif
}
if (type === editorCommon.EventType.ConfigurationChanged) {
let e = <editorCommon.IConfigurationChangedEvent>data;
let isViewportWrapping = this.modifiedEditor.getConfiguration().wrappingInfo.isViewportWrapping;
if (isViewportWrapping) {
// oh no, you didn't!
this.modifiedEditor.updateOptions({ wordWrap: 'off' });
}
if (e.fontInfo && this.modifiedEditor.getModel()) {
this._onViewZonesChanged();
}
Expand Down Expand Up @@ -886,6 +874,7 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif

private _adjustOptionsForSubEditor(options: editorCommon.IDiffEditorOptions): editorCommon.IDiffEditorOptions {
let clonedOptions: editorCommon.IDiffEditorOptions = objects.clone(options || {});
clonedOptions.inDiffEditor = true;
clonedOptions.wordWrap = 'off';
clonedOptions.wordWrapMinified = false;
clonedOptions.automaticLayout = false;
Expand Down
2 changes: 2 additions & 0 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class InternalEditorOptionsHelper {
}

let wrappingInfo = new editorCommon.EditorWrappingInfo({
inDiffEditor: Boolean(opts.inDiffEditor),
isDominatedByLongLines: isDominatedByLongLines,
isWordWrapMinified: bareWrappingInfo.isWordWrapMinified,
isViewportWrapping: bareWrappingInfo.isViewportWrapping,
wrappingColumn: bareWrappingInfo.wrappingColumn,
Expand Down
15 changes: 14 additions & 1 deletion src/vs/editor/common/editorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ export type LineNumbersOption = 'on' | 'off' | 'relative' | ((lineNumber: number
* Configuration options for the editor.
*/
export interface IEditorOptions {
/**
* This editor is used inside a diff editor.
* @internal
*/
inDiffEditor?: boolean;
/**
* Enable experimental screen reader support.
* Defaults to `true`.
Expand Down Expand Up @@ -713,6 +718,8 @@ export class InternalEditorMinimapOptions {
export class EditorWrappingInfo {
readonly _editorWrappingInfoBrand: void;

readonly inDiffEditor: boolean;
readonly isDominatedByLongLines: boolean;
readonly isWordWrapMinified: boolean;
readonly isViewportWrapping: boolean;
readonly wrappingColumn: number;
Expand All @@ -725,6 +732,8 @@ export class EditorWrappingInfo {
* @internal
*/
constructor(source: {
inDiffEditor: boolean;
isDominatedByLongLines: boolean;
isWordWrapMinified: boolean;
isViewportWrapping: boolean;
wrappingColumn: number;
Expand All @@ -733,6 +742,8 @@ export class EditorWrappingInfo {
wordWrapBreakAfterCharacters: string;
wordWrapBreakObtrusiveCharacters: string;
}) {
this.inDiffEditor = Boolean(source.inDiffEditor);
this.isDominatedByLongLines = Boolean(source.isDominatedByLongLines);
this.isWordWrapMinified = Boolean(source.isWordWrapMinified);
this.isViewportWrapping = Boolean(source.isViewportWrapping);
this.wrappingColumn = source.wrappingColumn | 0;
Expand All @@ -747,7 +758,9 @@ export class EditorWrappingInfo {
*/
public equals(other: EditorWrappingInfo): boolean {
return (
this.isWordWrapMinified === other.isWordWrapMinified
this.inDiffEditor === other.inDiffEditor
&& this.isDominatedByLongLines === other.isDominatedByLongLines
&& this.isWordWrapMinified === other.isWordWrapMinified
&& this.isViewportWrapping === other.isViewportWrapping
&& this.wrappingColumn === other.wrappingColumn
&& this.wrappingIndent === other.wrappingIndent
Expand Down
2 changes: 2 additions & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,8 @@ declare module monaco.editor {

export class EditorWrappingInfo {
readonly _editorWrappingInfoBrand: void;
readonly inDiffEditor: boolean;
readonly isDominatedByLongLines: boolean;
readonly isWordWrapMinified: boolean;
readonly isViewportWrapping: boolean;
readonly wrappingColumn: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import 'vs/css!./media/codeEditor';
import * as nls from 'vs/nls';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ICommonCodeEditor, IEditorContribution } from 'vs/editor/common/editorCommon';
import { ICommonCodeEditor, IEditorContribution, InternalEditorOptions } from 'vs/editor/common/editorCommon';
import { editorAction, ServicesAccessor, EditorAction, commonEditorContribution } from 'vs/editor/common/editorCommonExtensions';
import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { DefaultConfig } from 'vs/editor/common/config/defaultConfig';
import { MenuRegistry, MenuId } from "vs/platform/actions/common/actions";
import { ContextKeyExpr, IContextKeyService } from "vs/platform/contextkey/common/contextkey";
import { Disposable } from "vs/base/common/lifecycle";
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { Disposable } from 'vs/base/common/lifecycle';
import { IMessageService } from 'vs/platform/message/common/message';
import Severity from 'vs/base/common/severity';

@editorAction
class ToggleWordWrapAction extends EditorAction {
Expand All @@ -33,6 +35,14 @@ class ToggleWordWrapAction extends EditorAction {
}

public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
const editorConfiguration = editor.getConfiguration();
if (editorConfiguration.wrappingInfo.inDiffEditor) {
// Cannot change wrapping settings inside the diff editor
const messageService = accessor.get(IMessageService);
messageService.show(Severity.Info, nls.localize('wordWrap.notInDiffEditor', "Cannot toggle word wrap in a diff editor."));
return;
}

const codeEditorService = accessor.get(ICodeEditorService);
const configurationService = accessor.get(IConfigurationService);
const model = editor.getModel();
Expand Down Expand Up @@ -88,18 +98,32 @@ class ToggleWordWrapController extends Disposable implements IEditorContribution
) {
super();

const key = this.contextKeyService.createKey('isWordWrapMinified', this._isWordWrapMinified());
const configuration = this.editor.getConfiguration();
const isWordWrapMinified = this.contextKeyService.createKey('isWordWrapMinified', this._isWordWrapMinified(configuration));
const isDominatedByLongLines = this.contextKeyService.createKey('isDominatedByLongLines', this._isDominatedByLongLines(configuration));
const inDiffEditor = this.contextKeyService.createKey('inDiffEditor', this._inDiffEditor(configuration));

this._register(editor.onDidChangeConfiguration((e) => {
if (!e.wrappingInfo) {
return;
}
key.set(this._isWordWrapMinified());
const configuration = this.editor.getConfiguration();
isWordWrapMinified.set(this._isWordWrapMinified(configuration));
isDominatedByLongLines.set(this._isDominatedByLongLines(configuration));
inDiffEditor.set(this._inDiffEditor(configuration));
}));
}

private _isWordWrapMinified(): boolean {
return this.editor.getConfiguration().wrappingInfo.isWordWrapMinified;
private _isWordWrapMinified(config: InternalEditorOptions): boolean {
return config.wrappingInfo.isWordWrapMinified;
}

private _isDominatedByLongLines(config: InternalEditorOptions): boolean {
return config.wrappingInfo.isDominatedByLongLines;
}

private _inDiffEditor(config: InternalEditorOptions): boolean {
return config.wrappingInfo.inDiffEditor;
}

public getId(): string {
Expand All @@ -110,10 +134,28 @@ class ToggleWordWrapController extends Disposable implements IEditorContribution
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
id: 'editor.action.toggleWordWrap',
title: nls.localize('unwrapMinified', "Disable wrapping of this minified file"),
title: nls.localize('unwrapMinified', "Disable wrapping for this file"),
iconClass: 'toggle-word-wrap-action'
},
group: 'navigation',
order: 1,
when: ContextKeyExpr.and(
ContextKeyExpr.not('inDiffEditor'),
ContextKeyExpr.has('isDominatedByLongLines'),
ContextKeyExpr.has('isWordWrapMinified')
)
});
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
id: 'editor.action.toggleWordWrap',
title: nls.localize('wrapMinified', "Enable wrapping for this file"),
iconClass: 'toggle-word-wrap-action'
},
group: 'navigation',
order: 1,
when: ContextKeyExpr.has('isWordWrapMinified')
when: ContextKeyExpr.and(
ContextKeyExpr.not('inDiffEditor'),
ContextKeyExpr.has('isDominatedByLongLines'),
ContextKeyExpr.not('isWordWrapMinified')
)
});

0 comments on commit 543f956

Please sign in to comment.