提交 9883c987 编写于 作者: A Alex Dima

Fixes #21801: Add action to disable wrapping in minified case, bump minified...

Fixes #21801: Add action to disable wrapping in minified case, bump minified line limit to 10k chars
上级 1242ff57
......@@ -190,7 +190,7 @@ class InternalEditorOptionsHelper {
pixelRatio: pixelRatio
});
let bareWrappingInfo: { isViewportWrapping: boolean; wrappingColumn: number; } = null;
let bareWrappingInfo: { isWordWrapMinified: boolean; isViewportWrapping: boolean; wrappingColumn: number; } = null;
{
let wordWrap = opts.wordWrap;
let wordWrapColumn = toInteger(opts.wordWrapColumn, 1);
......@@ -206,26 +206,31 @@ class InternalEditorOptionsHelper {
if (wordWrapMinified && isDominatedByLongLines) {
// Force viewport width wrapping if model is dominated by long lines
bareWrappingInfo = {
isWordWrapMinified: true,
isViewportWrapping: true,
wrappingColumn: Math.max(1, layoutInfo.viewportColumn)
};
} else if (wordWrap === 'on') {
bareWrappingInfo = {
isWordWrapMinified: false,
isViewportWrapping: true,
wrappingColumn: Math.max(1, layoutInfo.viewportColumn)
};
} else if (wordWrap === 'bounded') {
bareWrappingInfo = {
isWordWrapMinified: false,
isViewportWrapping: true,
wrappingColumn: Math.min(Math.max(1, layoutInfo.viewportColumn), wordWrapColumn)
};
} else if (wordWrap === 'wordWrapColumn') {
bareWrappingInfo = {
isWordWrapMinified: false,
isViewportWrapping: false,
wrappingColumn: wordWrapColumn
};
} else {
bareWrappingInfo = {
isWordWrapMinified: false,
isViewportWrapping: false,
wrappingColumn: -1
};
......@@ -233,6 +238,7 @@ class InternalEditorOptionsHelper {
}
let wrappingInfo = new editorCommon.EditorWrappingInfo({
isWordWrapMinified: bareWrappingInfo.isWordWrapMinified,
isViewportWrapping: bareWrappingInfo.isViewportWrapping,
wrappingColumn: bareWrappingInfo.wrappingColumn,
wrappingIndent: wrappingIndentFromString(opts.wrappingIndent),
......
......@@ -713,6 +713,7 @@ export class InternalEditorMinimapOptions {
export class EditorWrappingInfo {
readonly _editorWrappingInfoBrand: void;
readonly isWordWrapMinified: boolean;
readonly isViewportWrapping: boolean;
readonly wrappingColumn: number;
readonly wrappingIndent: WrappingIndent;
......@@ -724,6 +725,7 @@ export class EditorWrappingInfo {
* @internal
*/
constructor(source: {
isWordWrapMinified: boolean;
isViewportWrapping: boolean;
wrappingColumn: number;
wrappingIndent: WrappingIndent;
......@@ -731,6 +733,7 @@ export class EditorWrappingInfo {
wordWrapBreakAfterCharacters: string;
wordWrapBreakObtrusiveCharacters: string;
}) {
this.isWordWrapMinified = Boolean(source.isWordWrapMinified);
this.isViewportWrapping = Boolean(source.isViewportWrapping);
this.wrappingColumn = source.wrappingColumn | 0;
this.wrappingIndent = source.wrappingIndent | 0;
......@@ -744,7 +747,8 @@ export class EditorWrappingInfo {
*/
public equals(other: EditorWrappingInfo): boolean {
return (
this.isViewportWrapping === other.isViewportWrapping
this.isWordWrapMinified === other.isWordWrapMinified
&& this.isViewportWrapping === other.isViewportWrapping
&& this.wrappingColumn === other.wrappingColumn
&& this.wrappingIndent === other.wrappingIndent
&& this.wordWrapBreakBeforeCharacters === other.wordWrapBreakBeforeCharacters
......
......@@ -18,7 +18,7 @@ import { TextModelSearch, SearchParams } from 'vs/editor/common/model/textModelS
import { TextSource, ITextSource, IRawTextSource, RawTextSource } from 'vs/editor/common/model/textSource';
const LIMIT_FIND_COUNT = 999;
export const LONG_LINE_BOUNDARY = 1000;
export const LONG_LINE_BOUNDARY = 10000;
export interface ITextModelCreationData {
readonly text: ITextSource;
......
......@@ -1530,6 +1530,7 @@ declare module monaco.editor {
export class EditorWrappingInfo {
readonly _editorWrappingInfoBrand: void;
readonly isWordWrapMinified: boolean;
readonly isViewportWrapping: boolean;
readonly wrappingColumn: number;
readonly wrappingIndent: WrappingIndent;
......
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.st0{opacity:0}.st0,.st1{fill:#f6f6f6}.st2{fill:#424242}</style><g id="outline"><path class="st0" d="M0 0h16v16H0z"/><path class="st1" d="M16 3H9v.445c-.034-.07-.062-.145-.1-.21a2.318 2.318 0 0 0-.759-.793C7.81 2.229 7 2.117 7 2.109V0H4v2.438c-.078-.042-.15-.092-.233-.125a2.685 2.685 0 0 0-1.013-.188c-.184 0-.392.016-.619.055a5.422 5.422 0 0 0-.506.115c-.149.045-.337.096-.493.162-.173.077-.39.151-.533.25L0 3.006v3.17c0 .297.045.56.136.821.1.291.255.525.454.736.207.224.462.351.75.467.065.027.137.026.205.039a2.827 2.827 0 0 0-.651.532 3.064 3.064 0 0 0-.6 1.061 3.81 3.81 0 0 0-.188 1.21c0 .402.062.784.185 1.137.132.377.323.709.562.978a2.748 2.748 0 0 0 2.131.942c.333 0 .595-.042.876-.13a2.61 2.61 0 0 0 .678-.333L5 13.225v-1.811L8.586 15h4.828l-2-2H16V3zM5 10.586V8.523l-.556-.404c-.081-.043-.152-.083-.228-.119h1.96c.196 0 .409.266.634.266.187 0 .366-.007.538-.029L5 10.586z"/></g><g id="icon_x5F_bg"><path class="st2" d="M10 4v2h3v4H9l2-2H9l-3 3 3 3h2l-2-2h6V4zM3.869 3.568a1.21 1.21 0 0 0-.473-.329c-.274-.111-.623-.15-1.055-.076a3.5 3.5 0 0 0-.711.208 1.501 1.501 0 0 0-.234.125l-.043.03v1.056l.168-.139c.149-.124.326-.225.527-.303.196-.074.399-.113.604-.113.188 0 .33.051.431.157.087.095.137.248.147.456l-.962.144c-.219.03-.41.086-.57.166a1.245 1.245 0 0 0-.398.311 1.234 1.234 0 0 0-.229.426 1.714 1.714 0 0 0 .011 1.008 1.096 1.096 0 0 0 .638.67c.155.063.328.093.528.093a1.25 1.25 0 0 0 .978-.441v.345h1.007V4.769c0-.255-.03-.484-.089-.681a1.423 1.423 0 0 0-.275-.52zm-.636 1.896V5.7c0 .119-.018.231-.055.341a.745.745 0 0 1-.377.447.694.694 0 0 1-.512.027.454.454 0 0 1-.156-.094.389.389 0 0 1-.094-.139.474.474 0 0 1-.035-.186c0-.077.009-.147.024-.212a.33.33 0 0 1 .078-.141.436.436 0 0 1 .161-.109 1.3 1.3 0 0 1 .305-.073l.661-.097zM8.284 4.397a2.253 2.253 0 0 0-.244-.656 1.354 1.354 0 0 0-.436-.459 1.165 1.165 0 0 0-.642-.173 1.136 1.136 0 0 0-.69.223 1.312 1.312 0 0 0-.264.266V1.119H5.09v6.224h.918v-.281a1.023 1.023 0 0 0 .472.328c.098.032.208.047.33.047.255 0 .483-.06.677-.177.192-.115.355-.278.486-.486a2.29 2.29 0 0 0 .293-.718 3.87 3.87 0 0 0 .096-.886 3.76 3.76 0 0 0-.078-.773zm-.861.758c0 .232-.02.439-.059.613-.036.172-.09.315-.159.424a.639.639 0 0 1-.233.237.582.582 0 0 1-.565.014.683.683 0 0 1-.211-.183.925.925 0 0 1-.141-.283 1.187 1.187 0 0 1-.054-.358v-.517c0-.164.02-.314.059-.447.037-.132.088-.242.157-.336a.668.668 0 0 1 .228-.208.584.584 0 0 1 .289-.071.554.554 0 0 1 .497.279c.063.099.108.214.143.354.031.143.049.306.049.482zM2.409 10.019a.913.913 0 0 1 .316-.239c.218-.1.547-.105.766-.018.104.042.204.1.32.184l.329.26V9.064l-.096-.062a1.932 1.932 0 0 0-.905-.215c-.308 0-.593.057-.846.168-.25.11-.467.27-.647.475a2.072 2.072 0 0 0-.403.717c-.09.272-.137.57-.137.895 0 .289.043.561.129.808.087.249.212.471.374.652.161.185.361.333.597.441.232.104.493.155.778.155.233 0 .434-.028.613-.084a1.85 1.85 0 0 0 .466-.217l.078-.061v-.889l-.2.095a.402.402 0 0 1-.076.026c-.05.017-.099.035-.128.049-.036.023-.227.09-.227.09-.06.024-.14.043-.218.059a.977.977 0 0 1-.599-.057.827.827 0 0 1-.306-.225 1.088 1.088 0 0 1-.205-.376 1.728 1.728 0 0 1-.076-.529c0-.21.028-.399.083-.56.054-.158.129-.294.22-.4z"/></g></svg>
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.toggle-word-wrap-action {
background: url('WordWrap_16x.svg') center center no-repeat;
}
......@@ -4,13 +4,17 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/css!./media/codeEditor';
import * as nls from 'vs/nls';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import { editorAction, ServicesAccessor, EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { ICommonCodeEditor, IEditorContribution } 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";
@editorAction
class ToggleWordWrapAction extends EditorAction {
......@@ -42,12 +46,23 @@ class ToggleWordWrapAction extends EditorAction {
const alreadyToggled = codeEditorService.getTransientModelProperty(model, 'toggleWordWrap');
if (!alreadyToggled) {
codeEditorService.setTransientModelProperty(model, 'toggleWordWrap', true);
if (configuredWordWrap !== 'off') {
const actualWrappingInfo = editor.getConfiguration().wrappingInfo;
if (actualWrappingInfo.isWordWrapMinified) {
// => wrapping due to minified file
editor.updateOptions({
wordWrap: 'off',
wordWrapMinified: false
});
} else if (configuredWordWrap !== 'off') {
// => wrapping is configured to be on (or some variant)
editor.updateOptions({
wordWrap: 'off',
wordWrapMinified: false
});
} else {
// => wrapping is configured to be off
editor.updateOptions({
wordWrap: 'on'
});
......@@ -61,3 +76,44 @@ class ToggleWordWrapAction extends EditorAction {
}
}
}
@commonEditorContribution
class ToggleWordWrapController extends Disposable implements IEditorContribution {
private static _ID = 'editor.contrib.toggleWordWrapController';
constructor(
private readonly editor: ICommonCodeEditor,
@IContextKeyService readonly contextKeyService: IContextKeyService
) {
super();
const key = this.contextKeyService.createKey('isWordWrapMinified', this._isWordWrapMinified());
this._register(editor.onDidChangeConfiguration((e) => {
if (!e.wrappingInfo) {
return;
}
key.set(this._isWordWrapMinified());
}));
}
private _isWordWrapMinified(): boolean {
return this.editor.getConfiguration().wrappingInfo.isWordWrapMinified;
}
public getId(): string {
return ToggleWordWrapController._ID;
}
}
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
id: 'editor.action.toggleWordWrap',
title: nls.localize('unwrapMinified', "Disable wrapping of this minified file"),
iconClass: 'toggle-word-wrap-action'
},
group: 'navigation',
order: 1,
when: ContextKeyExpr.has('isWordWrapMinified')
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册