소스 검색

fix: more flexible autocompletion api

version-14
Faris Ansari 3 년 전
부모
커밋
3ac6fd6ea4
1개의 변경된 파일44개의 추가작업 그리고 25개의 파일을 삭제
  1. +44
    -25
      frappe/public/js/frappe/form/controls/code.js

+ 44
- 25
frappe/public/js/frappe/form/controls/code.js 파일 보기

@@ -54,17 +54,32 @@ frappe.ui.form.ControlCode = class ControlCode extends frappe.ui.form.ControlTex
return this._autocompletions || [];
},
set: (value) => {
let getter = value
if (typeof getter !== 'function') {
getter = () => value
}
if (!this._autocompletions) {
this._autocompletions = [];
}
this._autocompletions.push(getter);
this.setup_autocompletion();
this.df._autocompletions = value;
}
});
}

setup_autocompletion() {
setup_autocompletion(customGetCompletions) {
if (this._autocompletion_setup) return;

const ace = window.ace;
const get_autocompletions = () => this.df.autocompletions;
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({
@@ -73,31 +88,35 @@ frappe.ui.form.ControlCode = class ControlCode extends frappe.ui.form.ControlTex
});

langTools.addCompleter({
getCompletions: function(editor, session, pos, prefix, callback) {
if (prefix.length === 0) {
callback(null, []);
return;
}
let autocompletions = get_autocompletions();
if (autocompletions.length) {
callback(
null,
autocompletions.map(a => {
if (typeof a === 'string') {
a = { value: a };
}
return {
name: 'frappe',
value: a.value,
score: a.score
};
})
);
}
}
getCompletions: customGetCompletions || getCompletions
});
});
this._autocompletion_setup = true;

function getCompletions(editor, session, pos, prefix, callback) {
if (prefix.length === 0) {
callback(null, []);
return;
}
let autocompletions = get_autocompletions();
if (autocompletions.length) {
callback(
null,
autocompletions.map(a => {
if (typeof a === "string") {
a = { value: a };
}
return {
name: "frappe",
value: a.value,
score: a.score,
meta: a.meta,
caption: a.caption
};
})
);
}
}
}

refresh_height() {


불러오는 중...
취소
저장