mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Add shortcut for opening Record Card
Summary: Also adds tests for previously untested Record Card behavior. Test Plan: Browser tests. Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D4136
This commit is contained in:
@@ -10,9 +10,10 @@ dispose.makeDisposable(CheckBoxEditor);
|
||||
_.extend(CheckBoxEditor.prototype, TextEditor.prototype);
|
||||
|
||||
// For documentation, see NewBaseEditor.ts
|
||||
CheckBoxEditor.skipEditor = function(typedVal, cellVal) {
|
||||
if (typedVal === ' ') {
|
||||
// This is a special case when user hits <space>. We return the toggled value to save, and by
|
||||
CheckBoxEditor.skipEditor = function(typedVal, cellVal, {event}) {
|
||||
// eslint-disable-next-line no-undef
|
||||
if (typedVal === '<enter>' || (event && event instanceof KeyboardEvent)) {
|
||||
// This is a special case when user hits <enter>. We return the toggled value to save, and by
|
||||
// this indicate that the editor should not open.
|
||||
return !cellVal;
|
||||
}
|
||||
|
||||
@@ -699,6 +699,7 @@ export class FieldBuilder extends Disposable {
|
||||
public buildEditorDom(editRow: DataRowModel, mainRowModel: DataRowModel, options: {
|
||||
init?: string,
|
||||
state?: any
|
||||
event?: KeyboardEvent | MouseEvent
|
||||
}) {
|
||||
// If the user attempts to edit a value during transform, finalize (i.e. cancel or execute)
|
||||
// the transform.
|
||||
@@ -733,7 +734,13 @@ export class FieldBuilder extends Disposable {
|
||||
return clearOwn();
|
||||
}
|
||||
|
||||
if (!this._readonly.get() && saveWithoutEditor(editorCtor, editRow, this.field, options.init)) {
|
||||
if (
|
||||
!this._readonly.get() &&
|
||||
saveWithoutEditor(editorCtor, editRow, this.field, {
|
||||
typedVal: options.init,
|
||||
event: options.event,
|
||||
})
|
||||
) {
|
||||
return clearOwn();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,16 +24,20 @@ const t = makeT('FieldEditor');
|
||||
|
||||
/**
|
||||
* Check if the typed-in value should change the cell without opening the cell editor, and if so,
|
||||
* saves and returns true. E.g. on typing space, CheckBoxEditor toggles the cell without opening.
|
||||
* saves and returns true. E.g. on typing enter, CheckBoxEditor toggles the cell without opening.
|
||||
*/
|
||||
export function saveWithoutEditor(
|
||||
editorCtor: IEditorConstructor, editRow: DataRowModel, field: ViewFieldRec, typedVal: string|undefined
|
||||
editorCtor: IEditorConstructor,
|
||||
editRow: DataRowModel,
|
||||
field: ViewFieldRec,
|
||||
options: {typedVal?: string, event?: KeyboardEvent|MouseEvent}
|
||||
): boolean {
|
||||
const {typedVal, event} = options;
|
||||
// Never skip the editor if editing a formula. Also, check that skipEditor static function
|
||||
// exists (we don't bother adding it on old-style JS editors that don't need it).
|
||||
if (!field.column.peek().isRealFormula.peek() && editorCtor.skipEditor) {
|
||||
const origVal = editRow.cells[field.colId()].peek();
|
||||
const skipEditorValue = editorCtor.skipEditor(typedVal, origVal);
|
||||
const skipEditorValue = editorCtor.skipEditor(typedVal, origVal, {event});
|
||||
if (skipEditorValue !== undefined) {
|
||||
setAndSave(editRow, field, skipEditorValue).catch(reportError);
|
||||
return true;
|
||||
|
||||
@@ -54,9 +54,13 @@ export abstract class NewBaseEditor extends Disposable {
|
||||
|
||||
/**
|
||||
* Check if the typed-in value should change the cell without opening the editor, and if so,
|
||||
* returns the value to save. E.g. on typing " ", CheckBoxEditor toggles value without opening.
|
||||
* returns the value to save. E.g. on typing <enter>, CheckBoxEditor toggles value without opening.
|
||||
*/
|
||||
public static skipEditor(typedVal: string|undefined, origVal: CellValue): CellValue|undefined {
|
||||
public static skipEditor(
|
||||
typedVal: string|undefined,
|
||||
origVal: CellValue,
|
||||
options?: {event?: KeyboardEvent|MouseEvent}
|
||||
): CellValue|undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ export class ReferenceList extends Reference {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
}),
|
||||
testId('ref-list-link-icon'),
|
||||
),
|
||||
cssLabel(isBlankReference ? '[Blank]' : formattedValue,
|
||||
testId('ref-list-cell-token-label'),
|
||||
|
||||
@@ -18,11 +18,11 @@ abstract class ToggleBase extends NewAbstractWidget {
|
||||
return;
|
||||
}
|
||||
if (!this.field.column().isRealFormula()) {
|
||||
// Move the cursor here, and pretend that spacebar was pressed. This triggers an editing
|
||||
// Move the cursor here, and pretend that enter was pressed. This triggers an editing
|
||||
// flow which is handled by CheckBoxEditor.skipEditor(). This way the edit applies to
|
||||
// editRow, which handles setting default values based on widget linking.
|
||||
commands.allCommands.setCursor.run(row, this.field);
|
||||
commands.allCommands.input.run(' ');
|
||||
commands.allCommands.input.run('<enter>');
|
||||
}
|
||||
}),
|
||||
dom.on('dblclick', (event) => {
|
||||
|
||||
Reference in New Issue
Block a user