mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Floating formula editor
Summary: Adding a way to detach an editor. Initially only implemented for the formula editor, includes redesign for the AI part. - Initially, the detached editor is tight with the formula assistant and both are behind GRIST_FORMULA_ASSISTANT flag, but this can be relaxed later on, as the detached editor can be used on its own. - Detached editor is only supported in regular fields and on the creator panel. It is not supported yet for conditional styles, due to preview limitations. - Old code for the assistant was removed completely, as it was only a temporary solution, but the AI conversation part was copied to the new one. - Prompting was not modified in this diff, it will be included in the follow-up with more test cases. Test Plan: Added only new tests; existing tests should pass. Reviewers: JakubSerafin Reviewed By: JakubSerafin Differential Revision: https://phab.getgrist.com/D3863
This commit is contained in:
@@ -28,7 +28,7 @@ import {makeT} from 'app/client/lib/localization';
|
||||
import {createSessionObs} from 'app/client/lib/sessionObs';
|
||||
import {setTestState} from 'app/client/lib/testState';
|
||||
import {selectFiles} from 'app/client/lib/uploads';
|
||||
import {reportError} from 'app/client/models/AppModel';
|
||||
import {AppModel, reportError} from 'app/client/models/AppModel';
|
||||
import BaseRowModel from 'app/client/models/BaseRowModel';
|
||||
import DataTableModel from 'app/client/models/DataTableModel';
|
||||
import {DataTableModelWithDiff} from 'app/client/models/DataTableModelWithDiff';
|
||||
@@ -205,6 +205,7 @@ export class GristDoc extends DisposableWithEvents {
|
||||
|
||||
constructor(
|
||||
public readonly app: App,
|
||||
public readonly appModel: AppModel,
|
||||
public readonly docComm: DocComm,
|
||||
public readonly docPageModel: DocPageModel,
|
||||
openDocResponse: OpenLocalDocResult,
|
||||
@@ -440,13 +441,7 @@ export class GristDoc extends DisposableWithEvents {
|
||||
|
||||
// Command to be manually triggered on cell selection. Moves the cursor to the selected cell.
|
||||
// This is overridden by the formula editor to insert "$col" variables when clicking cells.
|
||||
setCursor(rowModel: BaseRowModel, fieldModel?: ViewFieldRec) {
|
||||
return this.setCursorPos({
|
||||
rowIndex: rowModel?._index() || 0,
|
||||
fieldIndex: fieldModel?._index() || 0,
|
||||
sectionId: fieldModel?.viewSection().getRowId(),
|
||||
});
|
||||
},
|
||||
setCursor: this.onSetCursorPos.bind(this),
|
||||
}, this, true));
|
||||
|
||||
this.listenTo(app.comm, 'docUserAction', this.onDocUserAction);
|
||||
@@ -614,6 +609,14 @@ export class GristDoc extends DisposableWithEvents {
|
||||
return Object.assign(pos, viewInstance ? viewInstance.cursor.getCursorPos() : {});
|
||||
}
|
||||
|
||||
public async onSetCursorPos(rowModel: BaseRowModel|undefined, fieldModel?: ViewFieldRec) {
|
||||
return this.setCursorPos({
|
||||
rowIndex: rowModel?._index() || 0,
|
||||
fieldIndex: fieldModel?._index() || 0,
|
||||
sectionId: fieldModel?.viewSection().getRowId(),
|
||||
});
|
||||
}
|
||||
|
||||
public async setCursorPos(cursorPos: CursorPos) {
|
||||
if (cursorPos.sectionId && cursorPos.sectionId !== this.externalSectionId.get()) {
|
||||
const desiredSection: ViewSectionRec = this.docModel.viewSections.getRowModel(cursorPos.sectionId);
|
||||
@@ -1149,7 +1152,7 @@ export class GristDoc extends DisposableWithEvents {
|
||||
* Opens up an editor at cursor position
|
||||
* @param input Optional. Cell's initial value
|
||||
*/
|
||||
public async activateEditorAtCursor(options: { init?: string, state?: any}) {
|
||||
public async activateEditorAtCursor(options?: { init?: string, state?: any}) {
|
||||
const view = await this._waitForView();
|
||||
view?.activateEditorAtCursor(options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user