From ef16ccc8f6e93ec29e0cdfbb3c618334503c4a5b Mon Sep 17 00:00:00 2001 From: Marin Sokol Date: Tue, 24 Dec 2024 13:17:45 +0100 Subject: [PATCH 1/2] feat(AcePopup): adding getDataContainer and setVisibleRows methods --- ace-internal.d.ts | 2 ++ src/autocomplete/popup.js | 16 ++++++++++++++++ src/autocomplete/popup_test.js | 18 ++++++++++++++++++ types/ace-modules.d.ts | 4 ++++ 4 files changed, 40 insertions(+) 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..ed65202cd1d 100644 --- a/src/autocomplete/popup_test.js +++ b/src/autocomplete/popup_test.js @@ -209,6 +209,24 @@ 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); + assert.strictEqual(Math.floor(popup.container.clientHeight / lineHeight), 4); + }, + "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" { From e7a43b607b6b81e28960e3a485f5fc6eea81a05d Mon Sep 17 00:00:00 2001 From: Marin Sokol Date: Tue, 24 Dec 2024 13:38:53 +0100 Subject: [PATCH 2/2] fixing setVisibleRows test --- src/autocomplete/popup_test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/autocomplete/popup_test.js b/src/autocomplete/popup_test.js index ed65202cd1d..b5922a4fd63 100644 --- a/src/autocomplete/popup_test.js +++ b/src/autocomplete/popup_test.js @@ -218,7 +218,10 @@ module.exports = { popup.renderer.updateFull(true); // We add one more element to the DOM assert.strictEqual(popup.getDataContainer().children.length, 5); - assert.strictEqual(Math.floor(popup.container.clientHeight / lineHeight), 4); + + popup.setVisibleRows(1); + popup.renderer.updateFull(true); + assert.strictEqual(popup.getDataContainer().children.length, 2); }, "test: getDataContainer returns element with the popup data": function() { setupPopup();