Move word wrapping options logic to the EditorLayoutInfoComputer
parent
9ecc810720
commit
af4b129ce3
|
@ -1744,6 +1744,10 @@ export interface EditorLayoutInfo {
|
|||
*/
|
||||
readonly viewportColumn: number;
|
||||
|
||||
readonly isWordWrapMinified: boolean;
|
||||
readonly isViewportWrapping: boolean;
|
||||
readonly wrappingColumn: number;
|
||||
|
||||
/**
|
||||
* The width of the vertical scrollbar.
|
||||
*/
|
||||
|
@ -1763,15 +1767,16 @@ export interface EditorLayoutInfo {
|
|||
* @internal
|
||||
*/
|
||||
export interface EditorLayoutInfoComputerEnv {
|
||||
memory: IComputeOptionsMemory | null;
|
||||
outerWidth: number;
|
||||
outerHeight: number;
|
||||
lineHeight: number;
|
||||
viewLineCount: number;
|
||||
lineNumbersDigitCount: number;
|
||||
typicalHalfwidthCharacterWidth: number;
|
||||
maxDigitWidth: number;
|
||||
pixelRatio: number;
|
||||
readonly memory: IComputeOptionsMemory | null;
|
||||
readonly outerWidth: number;
|
||||
readonly outerHeight: number;
|
||||
readonly isDominatedByLongLines: boolean
|
||||
readonly lineHeight: number;
|
||||
readonly viewLineCount: number;
|
||||
readonly lineNumbersDigitCount: number;
|
||||
readonly typicalHalfwidthCharacterWidth: number;
|
||||
readonly maxDigitWidth: number;
|
||||
readonly pixelRatio: number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1782,7 +1787,12 @@ export class EditorLayoutInfoComputer extends ComputedEditorOption<EditorOption.
|
|||
constructor() {
|
||||
super(
|
||||
EditorOption.layoutInfo,
|
||||
[EditorOption.glyphMargin, EditorOption.lineDecorationsWidth, EditorOption.folding, EditorOption.minimap, EditorOption.scrollbar, EditorOption.lineNumbers]
|
||||
[
|
||||
EditorOption.glyphMargin, EditorOption.lineDecorationsWidth, EditorOption.folding,
|
||||
EditorOption.minimap, EditorOption.scrollbar, EditorOption.lineNumbers,
|
||||
EditorOption.wordWrap, EditorOption.wordWrapColumn, EditorOption.wordWrapMinified,
|
||||
EditorOption.accessibilitySupport
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1791,6 +1801,7 @@ export class EditorLayoutInfoComputer extends ComputedEditorOption<EditorOption.
|
|||
memory: env.memory,
|
||||
outerWidth: env.outerWidth,
|
||||
outerHeight: env.outerHeight,
|
||||
isDominatedByLongLines: env.isDominatedByLongLines,
|
||||
lineHeight: env.fontInfo.lineHeight,
|
||||
viewLineCount: env.viewLineCount,
|
||||
lineNumbersDigitCount: env.lineNumbersDigitCount,
|
||||
|
@ -1823,6 +1834,11 @@ export class EditorLayoutInfoComputer extends ComputedEditorOption<EditorOption.
|
|||
const maxDigitWidth = env.maxDigitWidth;
|
||||
const pixelRatio = env.pixelRatio;
|
||||
|
||||
const wordWrap = options.get(EditorOption.wordWrap);
|
||||
const wordWrapColumn = options.get(EditorOption.wordWrapColumn);
|
||||
const wordWrapMinified = options.get(EditorOption.wordWrapMinified);
|
||||
const accessibilitySupport = options.get(EditorOption.accessibilitySupport);
|
||||
|
||||
const showGlyphMargin = options.get(EditorOption.glyphMargin);
|
||||
const showLineNumbers = (options.get(EditorOption.lineNumbers).renderType !== RenderLineNumbersType.Off);
|
||||
const lineNumbersMinChars = options.get(EditorOption.lineNumbersMinChars) | 0;
|
||||
|
@ -1974,6 +1990,52 @@ export class EditorLayoutInfoComputer extends ComputedEditorOption<EditorOption.
|
|||
|
||||
const verticalArrowSize = (verticalScrollbarHasArrows ? scrollbarArrowSize : 0);
|
||||
|
||||
let bareWrappingInfo: { isWordWrapMinified: boolean; isViewportWrapping: boolean; wrappingColumn: number; } | null = null;
|
||||
{
|
||||
if (accessibilitySupport === AccessibilitySupport.Enabled) {
|
||||
// See https://github.com/Microsoft/vscode/issues/27766
|
||||
// Never enable wrapping when a screen reader is attached
|
||||
// because arrow down etc. will not move the cursor in the way
|
||||
// a screen reader expects.
|
||||
bareWrappingInfo = {
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1
|
||||
};
|
||||
} else if (wordWrapMinified && env.isDominatedByLongLines) {
|
||||
// Force viewport width wrapping if model is dominated by long lines
|
||||
bareWrappingInfo = {
|
||||
isWordWrapMinified: true,
|
||||
isViewportWrapping: true,
|
||||
wrappingColumn: Math.max(1, viewportColumn)
|
||||
};
|
||||
} else if (wordWrap === 'on') {
|
||||
bareWrappingInfo = {
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: true,
|
||||
wrappingColumn: Math.max(1, viewportColumn)
|
||||
};
|
||||
} else if (wordWrap === 'bounded') {
|
||||
bareWrappingInfo = {
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: true,
|
||||
wrappingColumn: Math.min(Math.max(1, viewportColumn), wordWrapColumn)
|
||||
};
|
||||
} else if (wordWrap === 'wordWrapColumn') {
|
||||
bareWrappingInfo = {
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: wordWrapColumn
|
||||
};
|
||||
} else {
|
||||
bareWrappingInfo = {
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
width: outerWidth,
|
||||
height: outerHeight,
|
||||
|
@ -2004,6 +2066,10 @@ export class EditorLayoutInfoComputer extends ComputedEditorOption<EditorOption.
|
|||
|
||||
viewportColumn: viewportColumn,
|
||||
|
||||
isWordWrapMinified: bareWrappingInfo.isWordWrapMinified,
|
||||
isViewportWrapping: bareWrappingInfo.isViewportWrapping,
|
||||
wrappingColumn: bareWrappingInfo.wrappingColumn,
|
||||
|
||||
verticalScrollbarWidth: verticalScrollbarWidth,
|
||||
horizontalScrollbarHeight: horizontalScrollbarHeight,
|
||||
|
||||
|
@ -3234,67 +3300,17 @@ export interface EditorWrappingInfo {
|
|||
class EditorWrappingInfoComputer extends ComputedEditorOption<EditorOption.wrappingInfo, EditorWrappingInfo> {
|
||||
|
||||
constructor() {
|
||||
super(EditorOption.wrappingInfo, [EditorOption.wordWrap, EditorOption.wordWrapColumn, EditorOption.wordWrapMinified, EditorOption.layoutInfo, EditorOption.accessibilitySupport]);
|
||||
super(EditorOption.wrappingInfo, [EditorOption.layoutInfo]);
|
||||
}
|
||||
|
||||
public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: EditorWrappingInfo): EditorWrappingInfo {
|
||||
const wordWrap = options.get(EditorOption.wordWrap);
|
||||
const wordWrapColumn = options.get(EditorOption.wordWrapColumn);
|
||||
const wordWrapMinified = options.get(EditorOption.wordWrapMinified);
|
||||
const layoutInfo = options.get(EditorOption.layoutInfo);
|
||||
const accessibilitySupport = options.get(EditorOption.accessibilitySupport);
|
||||
|
||||
let bareWrappingInfo: { isWordWrapMinified: boolean; isViewportWrapping: boolean; wrappingColumn: number; } | null = null;
|
||||
{
|
||||
if (accessibilitySupport === AccessibilitySupport.Enabled) {
|
||||
// See https://github.com/Microsoft/vscode/issues/27766
|
||||
// Never enable wrapping when a screen reader is attached
|
||||
// because arrow down etc. will not move the cursor in the way
|
||||
// a screen reader expects.
|
||||
bareWrappingInfo = {
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1
|
||||
};
|
||||
} else if (wordWrapMinified && env.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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
isDominatedByLongLines: env.isDominatedByLongLines,
|
||||
isWordWrapMinified: bareWrappingInfo.isWordWrapMinified,
|
||||
isViewportWrapping: bareWrappingInfo.isViewportWrapping,
|
||||
wrappingColumn: bareWrappingInfo.wrappingColumn,
|
||||
isWordWrapMinified: layoutInfo.isWordWrapMinified,
|
||||
isViewportWrapping: layoutInfo.isViewportWrapping,
|
||||
wrappingColumn: layoutInfo.wrappingColumn,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,10 +76,16 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
};
|
||||
options._write(EditorOption.lineNumbers, lineNumbersOptions);
|
||||
|
||||
options._write(EditorOption.wordWrap, 'off');
|
||||
options._write(EditorOption.wordWrapColumn, 80);
|
||||
options._write(EditorOption.wordWrapMinified, true);
|
||||
options._write(EditorOption.accessibilitySupport, 'auto');
|
||||
|
||||
const actual = EditorLayoutInfoComputer.computeLayout(options, {
|
||||
memory: null,
|
||||
outerWidth: input.outerWidth,
|
||||
outerHeight: input.outerHeight,
|
||||
isDominatedByLongLines: false,
|
||||
lineHeight: input.lineHeight,
|
||||
viewLineCount: input.maxLineNumber || Math.pow(10, input.lineNumbersDigitCount) - 1,
|
||||
lineNumbersDigitCount: input.lineNumbersDigitCount,
|
||||
|
@ -138,7 +144,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 800,
|
||||
minimapCanvasOuterWidth: 0,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 98,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -200,7 +210,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 800,
|
||||
minimapCanvasOuterWidth: 0,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 97,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 11,
|
||||
horizontalScrollbarHeight: 12,
|
||||
|
@ -262,7 +276,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 800,
|
||||
minimapCanvasOuterWidth: 0,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 88,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -324,7 +342,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 900,
|
||||
minimapCanvasOuterWidth: 0,
|
||||
minimapCanvasOuterHeight: 900,
|
||||
|
||||
viewportColumn: 88,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -386,7 +408,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 900,
|
||||
minimapCanvasOuterWidth: 0,
|
||||
minimapCanvasOuterHeight: 900,
|
||||
|
||||
viewportColumn: 88,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -448,7 +474,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 900,
|
||||
minimapCanvasOuterWidth: 0,
|
||||
minimapCanvasOuterHeight: 900,
|
||||
|
||||
viewportColumn: 83,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -510,7 +540,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 900,
|
||||
minimapCanvasOuterWidth: 0,
|
||||
minimapCanvasOuterHeight: 900,
|
||||
|
||||
viewportColumn: 83,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -572,7 +606,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 900,
|
||||
minimapCanvasOuterWidth: 0,
|
||||
minimapCanvasOuterHeight: 900,
|
||||
|
||||
viewportColumn: 82,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -634,7 +672,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 900,
|
||||
minimapCanvasOuterWidth: 0,
|
||||
minimapCanvasOuterHeight: 900,
|
||||
|
||||
viewportColumn: 171,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -696,7 +738,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 900,
|
||||
minimapCanvasOuterWidth: 0,
|
||||
minimapCanvasOuterHeight: 900,
|
||||
|
||||
viewportColumn: 169,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -758,7 +804,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 800,
|
||||
minimapCanvasOuterWidth: 97,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 89,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -820,7 +870,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 1600,
|
||||
minimapCanvasOuterWidth: 97,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 89,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -882,7 +936,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 3200,
|
||||
minimapCanvasOuterWidth: 55,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 93,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -944,7 +1002,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 3200,
|
||||
minimapCanvasOuterWidth: 55,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 93,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -1008,7 +1070,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 1560,
|
||||
minimapCanvasOuterWidth: 97,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 89,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -1072,7 +1138,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 1600,
|
||||
minimapCanvasOuterWidth: 55,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 93,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -1136,7 +1206,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 1600,
|
||||
minimapCanvasOuterWidth: 97,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 89,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -1200,7 +1274,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 1600,
|
||||
minimapCanvasOuterWidth: 55,
|
||||
minimapCanvasOuterHeight: 800,
|
||||
|
||||
viewportColumn: 93,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 0,
|
||||
horizontalScrollbarHeight: 0,
|
||||
|
@ -1262,7 +1340,11 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
|
|||
minimapCanvasInnerHeight: 844,
|
||||
minimapCanvasOuterWidth: 91,
|
||||
minimapCanvasOuterHeight: 422,
|
||||
|
||||
viewportColumn: 83,
|
||||
isWordWrapMinified: false,
|
||||
isViewportWrapping: false,
|
||||
wrappingColumn: -1,
|
||||
|
||||
verticalScrollbarWidth: 14,
|
||||
horizontalScrollbarHeight: 10,
|
||||
|
|
|
@ -3423,6 +3423,9 @@ declare namespace monaco.editor {
|
|||
* The number of columns (of typical characters) fitting on a viewport line.
|
||||
*/
|
||||
readonly viewportColumn: number;
|
||||
readonly isWordWrapMinified: boolean;
|
||||
readonly isViewportWrapping: boolean;
|
||||
readonly wrappingColumn: number;
|
||||
/**
|
||||
* The width of the vertical scrollbar.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue