{ "area": "layout", "cases": [ { "name": "unmeasured lines count one row each", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": false }], "expect": { "widthChanged": true, "totalRows": 20, "rowStart": { "10": 10, "20": 20 }, "content": [100, 200], "maxScroll": [0, 150], "visible": [0, 4] } }, { "name": "a line measured below the viewport leaves the scroll", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": false }, { "op": "scrollTo", "x": 0, "y": 30, "expect": { "result": true, "scroll": [0, 30], "visible": [3, 7] } }, { "op": "measure", "pairs": [[10, 3]] }], "expect": { "scroll": [0, 30], "totalRows": 22, "rowStart": { "11": 13 }, "content": [100, 220] } }, { "name": "a line measured above the viewport keeps the visible text in place", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": false }, { "op": "scrollTo", "x": 0, "y": 50, "expect": { "visible": [5, 9], "lineTop": { "5": 0 } } }, { "op": "measure", "pairs": [[2, 3]] }], "expect": { "scroll": [0, 70], "visible": [5, 9], "lineTop": { "5": 0 }, "maxScroll": [0, 170] } }, { "name": "a visible line that shrinks at the end of the content clamps the scroll", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": true }, { "op": "measure", "pairs": [[19, 10]] }, { "op": "scrollTo", "x": 0, "y": 1000, "expect": { "scroll": [0, 240], "maxScroll": [0, 240] } }, { "op": "measure", "pairs": [[19, 1]] }], "expect": { "scroll": [0, 150], "maxScroll": [0, 150], "totalRows": 20 } }, { "name": "a batch with a growth above and a shrink at the first visible line keeps that line in place", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": false }, { "op": "measure", "pairs": [[5, 3]] }, { "op": "scrollTo", "x": 0, "y": 50, "expect": { "visible": [5, 7], "lineTop": { "5": 0 } } }, { "op": "measure", "pairs": [[2, 2], [5, 1]] }], "expect": { "scroll": [0, 60], "lineTop": { "5": 0 }, "totalRows": 21, "content": [100, 210], "maxScroll": [0, 160] } }, { "name": "gap rows sit beside wrap rows", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": true }, { "op": "decorate", "items": [{ "kind": "gap", "line": 3, "rows": 2 }] }, { "op": "measure", "pairs": [[3, 2]] }], "expect": { "rowStart": { "3": 3, "4": 7 }, "isGapRow": { "3": false, "4": false, "5": true, "6": true, "7": false }, "totalRows": 23 } }, { "name": "a new decoration set replaces the gaps", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": false }, { "op": "decorate", "items": [{ "kind": "gap", "line": 2, "rows": 2 }], "expect": { "totalRows": 22 } }, { "op": "decorate", "items": [{ "kind": "gap", "line": 5, "rows": 1 }] }], "expect": { "totalRows": 21, "rowStart": { "3": 3, "6": 7 }, "isGapRow": { "3": false, "6": true } } }, { "name": "deleting a gap's line at the end and undoing keeps the rows in range", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": false }, { "op": "decorate", "items": [{ "kind": "gap", "line": 19, "rows": 2 }] }, { "op": "scrollTo", "x": 0, "y": 1000, "expect": { "scroll": [0, 170], "totalRows": 22 } }, { "op": "replace", "start": 29, "end": 39, "text": "", "expect": { "lineCount": 15, "gapRows": {}, "totalRows": 15, "scroll": [0, 100], "isGapRow": { "14": false, "15": false } } }, { "op": "undo" }], "expect": { "lineCount": 20, "gapRows": {}, "totalRows": 20, "scroll": [0, 100], "maxScroll": [0, 150] } }, { "name": "setText drops the gaps and keeps the scroll in range", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": false }, { "op": "decorate", "items": [{ "kind": "gap", "line": 0, "rows": 2 }] }, { "op": "scrollTo", "x": 0, "y": 1000, "expect": { "scroll": [0, 170], "totalRows": 22 } }, { "op": "setText", "text": "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny" }], "expect": { "lineCount": 20, "gapRows": {}, "totalRows": 20, "scroll": [0, 150], "maxScroll": [0, 150] } }, { "name": "an edit makes fresh one-row lines and moves gap lines with their text", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": true }, { "op": "decorate", "items": [{ "kind": "gap", "line": 10, "rows": 2 }] }, { "op": "measure", "pairs": [[5, 3], [12, 2]] }, { "op": "replace", "start": 10, "end": 10, "text": "y\ny\n" }], "expect": { "lineCount": 22, "gapRows": { "12": 2 }, "rowStart": { "5": 5, "8": 8, "12": 12, "13": 15, "14": 16, "15": 18 }, "totalRows": 25 } }, { "name": "rows map to the view through the insets", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [8, 4, 6, 2], "gutter": 10, "padding": 3, "wrap": false, "expect": { "content": [82, 200], "maxScroll": [0, 162], "lineTop": { "0": 8, "3": 38 }, "visible": [0, 3] } }, { "op": "scrollTo", "x": 0, "y": 25 }], "expect": { "lineTop": { "3": 13 }, "visible": [2, 6] } }, { "name": "layout reports only a text area width change", "text": "x\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": false, "expect": { "widthChanged": true } }, { "op": "layout", "rowHeight": 10, "width": 100, "height": 80, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": false, "expect": { "widthChanged": false } }, { "op": "layout", "rowHeight": 10, "width": 100, "height": 80, "insets": [0, 0, 4, 0], "gutter": 0, "padding": 0, "wrap": false, "expect": { "widthChanged": true } }, { "op": "layout", "rowHeight": 10, "width": 120, "height": 80, "insets": [0, 0, 4, 0], "gutter": 0, "padding": 0, "wrap": false, "expect": { "widthChanged": true } }] }, { "name": "the widest line sets the content width without wrap only", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 4, "wrap": false }, { "op": "measure", "pairs": [[0, 1]], "widest": 180, "expect": { "content": [188, 200], "maxScroll": [88, 150] } }, { "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 4, "wrap": true }], "expect": { "widthChanged": false, "content": [100, 200], "maxScroll": [0, 150] } }, { "name": "reveal takes the smallest scroll that shows the rect with padding", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 4, "wrap": false }, { "op": "measure", "pairs": [[0, 1]], "widest": 300 }, { "op": "reveal", "left": 150, "top": 120, "right": 160, "bottom": 130, "expect": { "result": true, "scroll": [68, 80] } }, { "op": "reveal", "left": 10, "top": 20, "right": 20, "bottom": 30 }], "expect": { "scroll": [10, 20] } }, { "name": "scrollTo clamps to zero and to the maximum", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": false }, { "op": "scrollTo", "x": -5, "y": -5, "expect": { "result": false, "scroll": [0, 0] } }, { "op": "scrollTo", "x": 0, "y": 1000, "expect": { "result": true, "scroll": [0, 150] } }, { "op": "scrollBy", "dx": 0, "dy": 10, "expect": { "result": false, "scroll": [0, 150] } }] }, { "name": "the anchor survives resetRows", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": true }, { "op": "measure", "pairs": [[1, 3], [2, 2]] }, { "op": "scrollTo", "x": 0, "y": 65, "expect": { "visible": [3, 8] } }, { "op": "anchor" }, { "op": "resetRows" }, { "op": "restore" }], "expect": { "scroll": [0, 35], "totalRows": 20, "lineTop": { "3": -5 } } }, { "name": "restore inside a gap keeps the offset in the gap", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": true }, { "op": "decorate", "items": [{ "kind": "gap", "line": 2, "rows": 3 }] }, { "op": "scrollTo", "x": 0, "y": 45 }, { "op": "anchor" }, { "op": "resetRows" }, { "op": "restore" }], "expect": { "scroll": [0, 45], "isGapRow": { "4": true } } }, { "name": "a gap re-measured at the top of the viewport shifts the text below (known, kept)", "text": "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "ops": [{ "op": "layout", "rowHeight": 10, "width": 100, "height": 50, "insets": [0, 0, 0, 0], "gutter": 0, "padding": 0, "wrap": true }, { "op": "decorate", "items": [{ "kind": "gap", "line": 2, "rows": 3 }] }, { "op": "scrollTo", "x": 0, "y": 40, "expect": { "visible": [2, 5], "lineTop": { "3": 20 } } }, { "op": "measure", "pairs": [[2, 2]] }], "expect": { "scroll": [0, 40], "lineTop": { "3": 30 } } } ] }