Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AcePopup): adding getDataContainer and setVisibleRows methods #5708

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ace-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,8 @@ declare module "./src/autocomplete/popup" {
anchorPos: any,
isMouseOver?: boolean,
selectedNode?: HTMLElement,
getDataContainer: () => HTMLDivElement;
setVisibleRows: (rows: number) => void;
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/autocomplete/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,22 @@ class AcePopup {
popup.$imageSize = 0;
popup.$borderSize = 1;

/**
* Get HTML element containing the popup data.
* @returns {HTMLDivElement} element
*/
popup.getDataContainer = function() {
return this.renderer.$textLayer.element;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason for exposing renderer.$textLayer.element here and not, for example, renderer.content or render.scroller? (which encompass all layers of the popup and might allow more flexibility when styling the popup)

};

/**
* Number of rows shown in the popup.
* @param {number} rows
*/
popup.setVisibleRows = function(rows) {
this.renderer.$maxLines = rows;
};

return popup;
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/autocomplete/popup_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,27 @@ module.exports = {
assert.strictEqual(popup.container.style.display, "none");
done();
},
"test: setVisibleRows shows correct number of rows": function() {
setupPopup();
tryShowAndRender({ top: 0, left: 0 }, lineHeight);
assert.strictEqual(popup.getDataContainer().children.length, 8);

popup.setVisibleRows(4);
popup.renderer.updateFull(true);
// We add one more element to the DOM
assert.strictEqual(popup.getDataContainer().children.length, 5);

popup.setVisibleRows(1);
popup.renderer.updateFull(true);
assert.strictEqual(popup.getDataContainer().children.length, 2);
},
"test: getDataContainer returns element with the popup data": function() {
setupPopup();
tryShowAndRender({ top: 0, left: 0 }, lineHeight);
assert.strictEqual(popup.getDataContainer().children.length, 8);
assert.strictEqual(popup.getDataContainer().children[0].textContent, "foo0 ");
assert.strictEqual(popup.getDataContainer().children[7].textContent, "foo7 ");
},
tearDown: tearDown
};

Expand Down
4 changes: 4 additions & 0 deletions types/ace-modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,8 @@ declare module "ace-code/src/autocomplete/popup" {
anchorPos: any;
isMouseOver?: boolean;
selectedNode?: HTMLElement;
getDataContainer: () => HTMLDivElement;
setVisibleRows: (rows: number) => void;
}
export function $singleLineEditor(el?: HTMLElement): Editor;
export function getAriaId(index: any): string;
Expand Down Expand Up @@ -2887,6 +2889,8 @@ declare module "ace-code/src/autocomplete/popup" {
anchorPos: any;
isMouseOver?: boolean;
selectedNode?: HTMLElement;
getDataContainer: () => HTMLDivElement;
setVisibleRows: (rows: number) => void;
}
}
declare module "ace-code/src/range_list" {
Expand Down
Loading