From aa1fefee2851c9010591ffe844447d5165097f02 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 16 Feb 2022 14:42:12 +0530 Subject: [PATCH] fix: pass context to autocompletions getter --- frappe/public/js/frappe/form/controls/code.js | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/frappe/public/js/frappe/form/controls/code.js b/frappe/public/js/frappe/form/controls/code.js index 96243e8cec..42168282a3 100644 --- a/frappe/public/js/frappe/form/controls/code.js +++ b/frappe/public/js/frappe/form/controls/code.js @@ -71,33 +71,21 @@ frappe.ui.form.ControlCode = class ControlCode extends frappe.ui.form.ControlTex if (this._autocompletion_setup) return; const ace = window.ace; - const get_autocompletions = () => { - let getters = this._autocompletions || []; - let completions = []; - for (let getter of getters) { - let values = getter() - completions.push(...values); - } - return completions; - } - - ace.config.loadModule("ace/ext/language_tools", langTools => { - this.editor.setOptions({ - enableBasicAutocompletion: true, - enableLiveAutocompletion: true - }); - - langTools.addCompleter({ - getCompletions: customGetCompletions || getCompletions - }); - }); - this._autocompletion_setup = true; - function getCompletions(editor, session, pos, prefix, callback) { + let getCompletions = (editor, session, pos, prefix, callback) => { if (prefix.length === 0) { callback(null, []); return; } + const get_autocompletions = () => { + let getters = this._autocompletions || []; + let completions = []; + for (let getter of getters) { + let values = getter({ editor, session, pos, prefix }); + completions.push(...values); + } + return completions; + } let autocompletions = get_autocompletions(); if (autocompletions.length) { callback( @@ -117,6 +105,18 @@ frappe.ui.form.ControlCode = class ControlCode extends frappe.ui.form.ControlTex ); } } + + ace.config.loadModule("ace/ext/language_tools", langTools => { + this.editor.setOptions({ + enableBasicAutocompletion: true, + enableLiveAutocompletion: true + }); + + langTools.addCompleter({ + getCompletions: customGetCompletions || getCompletions + }); + }); + this._autocompletion_setup = true; } refresh_height() {