FIX: Initial browse mode within sheets
This commit is contained in:
@@ -1126,8 +1126,16 @@ export default class WorksheetCanvas {
|
|||||||
cellOutlineHandle.style.visibility = "hidden";
|
cellOutlineHandle.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.style.left = `${x + 3}px`;
|
if (this.workbookState.getEditingCell()?.sheet === selectedSheet) {
|
||||||
editor.style.top = `${y + 3}px`;
|
editor.style.left = `${x + 3}px`;
|
||||||
|
editor.style.top = `${y + 3}px`;
|
||||||
|
} else {
|
||||||
|
// If the editing cell is not in the same sheet as the selected sheet
|
||||||
|
// we take the editor out of view
|
||||||
|
editor.style.left = "-9999px";
|
||||||
|
editor.style.top = "-9999px";
|
||||||
|
}
|
||||||
|
|
||||||
editor.style.width = `${width - 1}px`;
|
editor.style.width = `${width - 1}px`;
|
||||||
editor.style.height = `${height - 1}px`;
|
editor.style.height = `${height - 1}px`;
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ const Editor = (options: EditorOptions) => {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const cell = workbookState.getEditingCell();
|
const cell = workbookState.getEditingCell();
|
||||||
if (cell) {
|
if (cell) {
|
||||||
workbookState.clearEditingCell();
|
|
||||||
model.setUserInput(
|
model.setUserInput(
|
||||||
cell.sheet,
|
cell.sheet,
|
||||||
cell.row,
|
cell.row,
|
||||||
@@ -126,7 +125,9 @@ const Editor = (options: EditorOptions) => {
|
|||||||
cell.text + (cell.referencedRange?.str || ""),
|
cell.text + (cell.referencedRange?.str || ""),
|
||||||
);
|
);
|
||||||
const sign = shiftKey ? -1 : 1;
|
const sign = shiftKey ? -1 : 1;
|
||||||
|
model.setSelectedSheet(cell.sheet);
|
||||||
model.setSelectedCell(cell.row + sign, cell.column);
|
model.setSelectedCell(cell.row + sign, cell.column);
|
||||||
|
workbookState.clearEditingCell();
|
||||||
}
|
}
|
||||||
onEditEnd();
|
onEditEnd();
|
||||||
}, 0);
|
}, 0);
|
||||||
@@ -145,6 +146,7 @@ const Editor = (options: EditorOptions) => {
|
|||||||
cell.text + (cell.referencedRange?.str || ""),
|
cell.text + (cell.referencedRange?.str || ""),
|
||||||
);
|
);
|
||||||
const sign = shiftKey ? -1 : 1;
|
const sign = shiftKey ? -1 : 1;
|
||||||
|
model.setSelectedSheet(cell.sheet);
|
||||||
model.setSelectedCell(cell.row, cell.column + sign);
|
model.setSelectedCell(cell.row, cell.column + sign);
|
||||||
if (textareaRef.current) {
|
if (textareaRef.current) {
|
||||||
textareaRef.current.value = "";
|
textareaRef.current.value = "";
|
||||||
@@ -158,6 +160,10 @@ const Editor = (options: EditorOptions) => {
|
|||||||
}
|
}
|
||||||
case "Escape": {
|
case "Escape": {
|
||||||
// quit editing without modifying the cell
|
// quit editing without modifying the cell
|
||||||
|
const cell = workbookState.getEditingCell();
|
||||||
|
if (cell) {
|
||||||
|
model.setSelectedSheet(cell.sheet);
|
||||||
|
}
|
||||||
workbookState.clearEditingCell();
|
workbookState.clearEditingCell();
|
||||||
onEditEnd();
|
onEditEnd();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { ChevronLeft, ChevronRight, Menu, Plus } from "lucide-react";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { StyledButton } from "../toolbar";
|
import { StyledButton } from "../toolbar";
|
||||||
|
import type { WorkbookState } from "../workbookState";
|
||||||
import SheetListMenu from "./menus";
|
import SheetListMenu from "./menus";
|
||||||
import Sheet from "./sheet";
|
import Sheet from "./sheet";
|
||||||
import type { SheetOptions } from "./types";
|
import type { SheetOptions } from "./types";
|
||||||
@@ -10,6 +11,7 @@ import type { SheetOptions } from "./types";
|
|||||||
export interface NavigationProps {
|
export interface NavigationProps {
|
||||||
sheets: SheetOptions[];
|
sheets: SheetOptions[];
|
||||||
selectedIndex: number;
|
selectedIndex: number;
|
||||||
|
workbookState: WorkbookState;
|
||||||
onSheetSelected: (index: number) => void;
|
onSheetSelected: (index: number) => void;
|
||||||
onAddBlankSheet: () => void;
|
onAddBlankSheet: () => void;
|
||||||
onSheetColorChanged: (hex: string) => void;
|
onSheetColorChanged: (hex: string) => void;
|
||||||
@@ -19,7 +21,7 @@ export interface NavigationProps {
|
|||||||
|
|
||||||
function Navigation(props: NavigationProps) {
|
function Navigation(props: NavigationProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { onSheetSelected, sheets, selectedIndex } = props;
|
const { workbookState, onSheetSelected, sheets, selectedIndex } = props;
|
||||||
const [anchorEl, setAnchorEl] = useState<null | HTMLButtonElement>(null);
|
const [anchorEl, setAnchorEl] = useState<null | HTMLButtonElement>(null);
|
||||||
const open = Boolean(anchorEl);
|
const open = Boolean(anchorEl);
|
||||||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
@@ -63,6 +65,7 @@ function Navigation(props: NavigationProps) {
|
|||||||
onDeleted={(): void => {
|
onDeleted={(): void => {
|
||||||
props.onSheetDeleted();
|
props.onSheetDeleted();
|
||||||
}}
|
}}
|
||||||
|
workbookState={workbookState}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</SheetInner>
|
</SheetInner>
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import { Button, Menu, MenuItem, styled } from "@mui/material";
|
|||||||
import { ChevronDown } from "lucide-react";
|
import { ChevronDown } from "lucide-react";
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import ColorPicker from "../colorPicker";
|
import ColorPicker from "../colorPicker";
|
||||||
|
import { isInReferenceMode } from "../editor/util";
|
||||||
|
import type { WorkbookState } from "../workbookState";
|
||||||
import { SheetRenameDialog } from "./menus";
|
import { SheetRenameDialog } from "./menus";
|
||||||
|
|
||||||
interface SheetProps {
|
interface SheetProps {
|
||||||
name: string;
|
name: string;
|
||||||
color: string;
|
color: string;
|
||||||
@@ -11,9 +14,11 @@ interface SheetProps {
|
|||||||
onColorChanged: (hex: string) => void;
|
onColorChanged: (hex: string) => void;
|
||||||
onRenamed: (name: string) => void;
|
onRenamed: (name: string) => void;
|
||||||
onDeleted: () => void;
|
onDeleted: () => void;
|
||||||
|
workbookState: WorkbookState;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Sheet(props: SheetProps) {
|
function Sheet(props: SheetProps) {
|
||||||
const { name, color, selected, onSelected } = props;
|
const { name, color, selected, workbookState, onSelected } = props;
|
||||||
const [anchorEl, setAnchorEl] = useState<null | HTMLButtonElement>(null);
|
const [anchorEl, setAnchorEl] = useState<null | HTMLButtonElement>(null);
|
||||||
const [colorPickerOpen, setColorPickerOpen] = useState(false);
|
const [colorPickerOpen, setColorPickerOpen] = useState(false);
|
||||||
const colorButton = useRef(null);
|
const colorButton = useRef(null);
|
||||||
@@ -35,8 +40,18 @@ function Sheet(props: SheetProps) {
|
|||||||
<>
|
<>
|
||||||
<Wrapper
|
<Wrapper
|
||||||
style={{ borderBottomColor: color, fontWeight: selected ? 600 : 400 }}
|
style={{ borderBottomColor: color, fontWeight: selected ? 600 : 400 }}
|
||||||
onClick={() => {
|
onClick={(event) => {
|
||||||
onSelected();
|
onSelected();
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
|
onPointerDown={(event) => {
|
||||||
|
// If it is in browse mode stop he event
|
||||||
|
const cell = workbookState.getEditingCell();
|
||||||
|
if (cell && isInReferenceMode(cell.text, cell.cursorStart)) {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
ref={colorButton}
|
ref={colorButton}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ const usePointer = (options: PointerSettings): PointerEvents => {
|
|||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { canvasElement, worksheetCanvas } = options;
|
const { canvasElement, model, worksheetCanvas } = options;
|
||||||
const canvas = canvasElement.current;
|
const canvas = canvasElement.current;
|
||||||
const worksheet = worksheetCanvas.current;
|
const worksheet = worksheetCanvas.current;
|
||||||
// Silence the linter
|
// Silence the linter
|
||||||
@@ -78,7 +78,14 @@ const usePointer = (options: PointerSettings): PointerEvents => {
|
|||||||
const range = editingCell.referencedRange.range;
|
const range = editingCell.referencedRange.range;
|
||||||
range.rowEnd = cell.row;
|
range.rowEnd = cell.row;
|
||||||
range.columnEnd = cell.column;
|
range.columnEnd = cell.column;
|
||||||
editingCell.referencedRange.str = rangeToStr(range, 0);
|
|
||||||
|
const sheetNames = model.getWorksheetsProperties().map((s) => s.name);
|
||||||
|
|
||||||
|
editingCell.referencedRange.str = rangeToStr(
|
||||||
|
range,
|
||||||
|
editingCell.sheet,
|
||||||
|
sheetNames[range.sheet],
|
||||||
|
);
|
||||||
workbookState.setEditingCell(editingCell);
|
workbookState.setEditingCell(editingCell);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
@@ -169,15 +176,22 @@ const usePointer = (options: PointerSettings): PointerEvents => {
|
|||||||
const text = editingCell.text;
|
const text = editingCell.text;
|
||||||
if (isInReferenceMode(text, editingCell.cursorEnd)) {
|
if (isInReferenceMode(text, editingCell.cursorEnd)) {
|
||||||
const range = {
|
const range = {
|
||||||
sheet: 0,
|
sheet: model.getSelectedSheet(),
|
||||||
rowStart: cell.row,
|
rowStart: cell.row,
|
||||||
rowEnd: cell.row,
|
rowEnd: cell.row,
|
||||||
columnStart: cell.column,
|
columnStart: cell.column,
|
||||||
columnEnd: cell.column,
|
columnEnd: cell.column,
|
||||||
};
|
};
|
||||||
|
const sheetNames = model
|
||||||
|
.getWorksheetsProperties()
|
||||||
|
.map((s) => s.name);
|
||||||
editingCell.referencedRange = {
|
editingCell.referencedRange = {
|
||||||
range,
|
range,
|
||||||
str: rangeToStr(range, 0),
|
str: rangeToStr(
|
||||||
|
range,
|
||||||
|
editingCell.sheet,
|
||||||
|
sheetNames[range.sheet],
|
||||||
|
),
|
||||||
};
|
};
|
||||||
workbookState.setEditingCell(editingCell);
|
workbookState.setEditingCell(editingCell);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|||||||
@@ -50,9 +50,10 @@ export function rangeToStr(
|
|||||||
columnEnd: number;
|
columnEnd: number;
|
||||||
},
|
},
|
||||||
referenceSheet: number,
|
referenceSheet: number,
|
||||||
|
referenceName: string,
|
||||||
): string {
|
): string {
|
||||||
const { sheet, rowStart, rowEnd, columnStart, columnEnd } = range;
|
const { sheet, rowStart, rowEnd, columnStart, columnEnd } = range;
|
||||||
const sheetName = sheet === referenceSheet ? "" : "other!";
|
const sheetName = sheet === referenceSheet ? "" : `${referenceName}!`;
|
||||||
if (rowStart === rowEnd && columnStart === columnEnd) {
|
if (rowStart === rowEnd && columnStart === columnEnd) {
|
||||||
return `${sheetName}${columnNameFromNumber(columnStart)}${rowStart}`;
|
return `${sheetName}${columnNameFromNumber(columnStart)}${rowStart}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -385,6 +385,7 @@ const Workbook = (props: { model: Model; workbookState: WorkbookState }) => {
|
|||||||
<Navigation
|
<Navigation
|
||||||
sheets={info}
|
sheets={info}
|
||||||
selectedIndex={model.getSelectedSheet()}
|
selectedIndex={model.getSelectedSheet()}
|
||||||
|
workbookState={workbookState}
|
||||||
onSheetSelected={(sheet: number): void => {
|
onSheetSelected={(sheet: number): void => {
|
||||||
model.setSelectedSheet(sheet);
|
model.setSelectedSheet(sheet);
|
||||||
setRedrawId((value) => value + 1);
|
setRedrawId((value) => value + 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user