提交 ecf6a017 编写于 作者: S SteVen Batten

fix test

上级 c9a2f782
......@@ -79,25 +79,26 @@ export interface ILayoutAnchor {
*/
export function layout(viewportSize: number, viewSize: number, anchor: ILayoutAnchor): number {
const anchorEnd = anchor.offset + anchor.size;
const viewportBorderBuffer = 5;
console.log(`viewport: ${viewportSize}, view: ${viewSize}`);
if (anchor.position === LayoutAnchorPosition.Before) {
if (viewSize <= viewportSize - anchorEnd - viewportBorderBuffer) {
if (viewSize <= viewportSize - anchorEnd) {
return anchorEnd; // happy case, lay it out after the anchor
}
if (viewSize <= anchor.offset - viewportBorderBuffer) {
if (viewSize <= anchor.offset) {
return anchor.offset - viewSize; // ok case, lay it out before the anchor
}
return Math.max(viewportSize - viewSize - viewportBorderBuffer, 0); // sad case, lay it over the anchor
return Math.max(viewportSize - viewSize, 0); // sad case, lay it over the anchor
} else {
if (viewSize <= anchor.offset - viewportBorderBuffer) {
if (viewSize <= anchor.offset) {
return anchor.offset - viewSize; // happy case, lay it out before the anchor
}
if (viewSize <= viewportSize - anchorEnd) {
return anchorEnd - viewportBorderBuffer; // ok case, lay it out after the anchor
return anchorEnd; // ok case, lay it out after the anchor
}
return 0; // sad case, lay it over the anchor
......
......@@ -8,7 +8,7 @@ import { layout, LayoutAnchorPosition } from 'vs/base/browser/ui/contextview/con
suite('Contextview', function () {
test.skip('layout', () => {
test('layout', () => {
assert.equal(layout(200, 20, { offset: 0, size: 0, position: LayoutAnchorPosition.Before }), 0);
assert.equal(layout(200, 20, { offset: 50, size: 0, position: LayoutAnchorPosition.Before }), 50);
assert.equal(layout(200, 20, { offset: 200, size: 0, position: LayoutAnchorPosition.Before }), 180);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册