(core) Add 'value' to trigger formula autocomplete

Summary:
API signature for autocomplete updated to add column ID, which is
necessary for exposing correct types for 'value'.

Test Plan: Unit tests.

Reviewers: alexmojaki

Reviewed By: alexmojaki

Subscribers: jarek, alexmojaki

Differential Revision: https://phab.getgrist.com/D2896
This commit is contained in:
George Gevoian
2021-07-07 09:03:01 -07:00
parent 8524b4f791
commit 9592e3610b
9 changed files with 105 additions and 54 deletions

View File

@@ -20,12 +20,14 @@ var modelUtil = require('../models/modelUtil');
* element. Both desiredSize and the return value are objects with 'width' and 'height' members.
*/
function AceEditor(options) {
options = options || {};
// Observable subscription is not created until the dom is built
this.observable = (options && options.observable) || null;
this.saveValueOnBlurEvent = !(options && (options.saveValueOnBlurEvent === false));
this.calcSize = (options && options.calcSize) || ((elem, size) => size);
this.gristDoc = (options && options.gristDoc) || null;
this.editorState = (options && options.editorState) || null;
this.observable = options.observable || null;
this.saveValueOnBlurEvent = !(options.saveValueOnBlurEvent === false);
this.calcSize = options.calcSize || ((_elem, size) => size);
this.gristDoc = options.gristDoc || null;
this.field = options.field || null;
this.editorState = options.editorState || null;
this._readonly = options.readonly || false;
this.editor = null;
@@ -183,10 +185,11 @@ AceEditor.prototype.setFontSize = function(pxVal) {
AceEditor.prototype._setup = function() {
// Standard editor setup
this.editor = this.autoDisposeWith('destroy', ace.edit(this.editorDom));
if (this.gristDoc) {
if (this.gristDoc && this.field) {
const getSuggestions = (prefix) => {
const tableId = this.gristDoc.viewModel.activeSection().table().tableId();
return this.gristDoc.docComm.autocomplete(prefix, tableId);
const columnId = this.field.column().colId();
return this.gristDoc.docComm.autocomplete(prefix, tableId, columnId);
};
setupAceEditorCompletions(this.editor, {getSuggestions});
}

View File

@@ -45,6 +45,7 @@ export class FormulaEditor extends NewBaseEditor {
this._formulaEditor = AceEditor.create({
// A bit awkward, but we need to assume calcSize is not used until attach() has been called
// and _editorPlacement created.
field: options.field,
calcSize: this._calcSize.bind(this),
gristDoc: options.gristDoc,
saveValueOnBlurEvent: !options.readonly,

View File

@@ -174,9 +174,9 @@ export interface ActiveDocAPI {
/**
* Find and return a list of auto-complete suggestions that start with `txt`, when editing a
* formula in table `tableId`.
* formula in table `tableId` and column `columnId`.
*/
autocomplete(txt: string, tableId: string): Promise<string[]>;
autocomplete(txt: string, tableId: string, columnId: string): Promise<string[]>;
/**
* Removes the current instance from the doc.

View File

@@ -836,11 +836,11 @@ export class ActiveDoc extends EventEmitter {
docSession.linkId = 0;
}
public async autocomplete(docSession: DocSession, txt: string, tableId: string): Promise<string[]> {
public async autocomplete(docSession: DocSession, txt: string, tableId: string, columnId: string): Promise<string[]> {
// Autocompletion can leak names of tables and columns.
if (!await this._granularAccess.canScanData(docSession)) { return []; }
await this.waitForInitialization();
return this._pyCall('autocomplete', txt, tableId);
return this._pyCall('autocomplete', txt, tableId, columnId);
}
public fetchURL(docSession: DocSession, url: string): Promise<UploadResult> {