Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: anon users can't double click to edit #694

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 40 additions & 37 deletions src/gridGL/interaction/keyboard/keyboardCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export function keyboardCell(options: {
sheet_controller,
} = options;

const hasPermission = isEditorOrAbove(editorInteractionState.permission);

if (event.key === 'Tab') {
// move single cursor one right
const delta = event.shiftKey ? -1 : 1;
Expand All @@ -43,8 +45,45 @@ export function keyboardCell(options: {
event.preventDefault();
}

if (event.key === 'Enter') {
const x = interactionState.cursorPosition.x;
const y = interactionState.cursorPosition.y;
const cell = sheet_controller.sheet.getCellCopy(x, y);

if (cell) {
if (cell.type === 'TEXT' || cell.type === 'COMPUTED') {
// open single line
if (hasPermission) {
setInteractionState({
...interactionState,

showInput: true,
inputInitialValue: cell.value,
});
}
} else {
// Open code editor, or move code editor if already open.
setEditorInteractionState({
...editorInteractionState,
showCellTypeMenu: false,
showCodeEditor: true,
selectedCell: { x: x, y: y },
mode: cell.type,
});
}
} else if (hasPermission) {
setInteractionState({
...interactionState,
showInput: true,
inputInitialValue: '',
});
}

event.preventDefault();
}

// Don't allow actions beyond here for certain users
if (!isEditorOrAbove(editorInteractionState.permission)) {
if (!hasPermission) {
return false;
}

Expand Down Expand Up @@ -74,42 +113,6 @@ export function keyboardCell(options: {
event.preventDefault();
}

if (event.key === 'Enter') {
const x = interactionState.cursorPosition.x;
const y = interactionState.cursorPosition.y;
const cell = sheet_controller.sheet.getCellCopy(x, y);
if (cell) {
if (cell.type === 'TEXT' || cell.type === 'COMPUTED') {
// open single line
setInteractionState({
...interactionState,
...{
showInput: true,
inputInitialValue: cell.value,
},
});
} else {
// Open code editor, or move code editor if already open.
setEditorInteractionState({
...editorInteractionState,
showCellTypeMenu: false,
showCodeEditor: true,
selectedCell: { x: x, y: y },
mode: cell.type,
});
}
} else {
setInteractionState({
...interactionState,
...{
showInput: true,
inputInitialValue: '',
},
});
}
event.preventDefault();
}

if (event.key === '/' || event.key === '=') {
const x = interactionState.cursorPosition.x;
const y = interactionState.cursorPosition.y;
Expand Down
48 changes: 0 additions & 48 deletions src/gridGL/interaction/onDoubleClickCanvas.ts

This file was deleted.

17 changes: 11 additions & 6 deletions src/gridGL/interaction/pointer/doubleClickCell.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isEditorOrAbove } from '../../../actions';
import { Cell } from '../../../schemas';
import { PixiApp } from '../../pixiApp/PixiApp';

Expand All @@ -7,13 +8,17 @@ export function doubleClickCell(options: { cell?: Cell; app: PixiApp }): void {

if (!settings.setInteractionState || !settings.setEditorInteractionState) return;

const hasPermission = isEditorOrAbove(settings.editorInteractionState.permission);

if (cell) {
if (cell.type === 'TEXT' || cell.type === 'COMPUTED') {
settings.setInteractionState({
...settings.interactionState,
showInput: true,
inputInitialValue: cell.value,
});
if (hasPermission) {
settings.setInteractionState({
...settings.interactionState,
showInput: true,
inputInitialValue: cell.value,
});
}
} else {
// Open code editor, or move code editor if already open.
settings.setEditorInteractionState({
Expand All @@ -24,7 +29,7 @@ export function doubleClickCell(options: { cell?: Cell; app: PixiApp }): void {
mode: cell.type,
});
}
} else {
} else if (hasPermission) {
// If no previous value, open single line Input
settings.setInteractionState({
...settings.interactionState,
Expand Down
Loading