diff --git a/ace-internal.d.ts b/ace-internal.d.ts index 86fab157d74..c8042f72fbf 100644 --- a/ace-internal.d.ts +++ b/ace-internal.d.ts @@ -1495,6 +1495,8 @@ declare module "./src/autocomplete/popup" { anchorPos: any, isMouseOver?: boolean, selectedNode?: HTMLElement, + getDataContainer: () => HTMLDivElement; + setVisibleRows: (rows: number) => void; } } diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 2a164758ce8..aaadc86d033 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -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; + }; + + /** + * Number of rows shown in the popup. + * @param {number} rows + */ + popup.setVisibleRows = function(rows) { + this.renderer.$maxLines = rows; + }; + return popup; } } diff --git a/src/autocomplete/popup_test.js b/src/autocomplete/popup_test.js index 8c4ee962ee4..b5922a4fd63 100644 --- a/src/autocomplete/popup_test.js +++ b/src/autocomplete/popup_test.js @@ -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 }; diff --git a/types/ace-modules.d.ts b/types/ace-modules.d.ts index 53838b866ed..b804739f1bb 100644 --- a/types/ace-modules.d.ts +++ b/types/ace-modules.d.ts @@ -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; @@ -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" {