Skip to content

Commit

Permalink
chore: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
righ committed Aug 17, 2024
1 parent b5e3b40 commit ec388c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ export const Editor: React.FC = () => {
const rowId = `${y2r(y)}`;
const colId = x2c(x);
const address = `${colId}${rowId}`;
const [origin, setOrigin] = React.useState('');
const [before, setBefore] = React.useState('');
const editing = editingCell === address;

const cell = table.getByPoint({ y, x });
const value: any = cell?.value;
const { y: top, x: left, height, width } = editorRect;

const writeCell = (value: string) => {
if (origin !== value) {
if (before !== value) {
dispatch(write(value));
}
//setBefore('');
Expand Down Expand Up @@ -398,7 +398,7 @@ export const Editor: React.FC = () => {
const input = e.currentTarget;
if (!editing) {
input.value = table.stringify({ y, x }, value);
setOrigin(input.value);
setBefore(input.value);
dispatch(setEditingCell(address));
input.style.width = `${width}px`;
input.style.height = `${height}px`;
Expand All @@ -411,7 +411,7 @@ export const Editor: React.FC = () => {
}
}}
onBlur={(e) => {
dispatch(setLastEdited(origin));
dispatch(setLastEdited(before));
if (e.target.value.startsWith('=')) {
return true;
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/components/FormulaBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Props = {

export const FormulaBar: React.FC<Props> = ({ width }) => {
const { store, dispatch } = React.useContext(Context);
const [origin, setOrigin] = React.useState('');
const [before, setBefore] = React.useState('');
const { choosing, editorRef, largeEditorRef, table } = store;

const [, sheetContext] = useSheetContext();
Expand All @@ -23,11 +23,11 @@ export const FormulaBar: React.FC<Props> = ({ width }) => {
// debug to remove this line
value = table.stringify(choosing, value);
largeEditorRef.current!.value = value;
setOrigin(value as string);
setBefore(value as string);
}, [address, table]);

const writeCell = (value: string) => {
if (origin !== value) {
if (before !== value) {
dispatch(write(value));
}
dispatch(setEditingCell(''));
Expand Down Expand Up @@ -63,7 +63,7 @@ export const FormulaBar: React.FC<Props> = ({ width }) => {
onFocus={sync}
onChange={sync}
onBlur={(e) => {
dispatch(setLastEdited(origin));
dispatch(setLastEdited(before));
if (e.target.value.startsWith('=')) {
return true;
} else {
Expand Down Expand Up @@ -94,7 +94,7 @@ export const FormulaBar: React.FC<Props> = ({ width }) => {
break;
}
case 'Escape': {
input.value = origin;
input.value = before;
dispatch(setEditingCell(''));
e.preventDefault();
editorRef.current!.focus();
Expand Down

0 comments on commit ec388c2

Please sign in to comment.