Skip to content

Commit

Permalink
fixes bug #611
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkircos committed Jul 25, 2023
1 parent bce8fcf commit 56d1dba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/hooks/useAlertOnUnsavedChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export default function useAlertOnUnsavedChanges(hasUnsavedChanges: boolean) {
useEffect(() => {
if (hasUnsavedChanges) {
window.addEventListener('beforeunload', beforeUnloadListener);
return;
} else {
window.removeEventListener('beforeunload', beforeUnloadListener);
}
window.removeEventListener('beforeunload', beforeUnloadListener);

return () => window.removeEventListener('beforeunload', beforeUnloadListener);
}, [hasUnsavedChanges]);
}
44 changes: 23 additions & 21 deletions src/ui/menus/CodeEditor/CodeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import React, { useRef, useState, useEffect, useMemo } from 'react';
import Editor, { Monaco, loader } from '@monaco-editor/react';
import monaco from 'monaco-editor';
import { colors } from '../../../theme/colors';
import { QuadraticEditorTheme } from './quadraticEditorTheme';
import { Cell } from '../../../schemas';
import { Close, FiberManualRecord, PlayArrow, Subject } from '@mui/icons-material';
import {
Button,
CircularProgress,
Expand All @@ -15,30 +11,34 @@ import {
IconButton,
useTheme,
} from '@mui/material';
import { Console } from './Console';
import { focusGrid } from '../../../helpers/focusGrid';
import mixpanel from 'mixpanel-browser';
import monaco from 'monaco-editor';
import { provideCompletionItems, provideHover } from 'quadratic-core';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import {
editorHighlightedCellsStateAtom,
editorHighlightedCellsStateDefault,
} from '../../../atoms/editorHighlightedCellsStateAtom';
import { editorInteractionStateAtom } from '../../../atoms/editorInteractionStateAtom';
import { SheetController } from '../../../grid/controller/sheetController';
import { loadedStateAtom } from '../../../atoms/loadedStateAtom';
import { updateCellAndDCells } from '../../../grid/actions/updateCellAndDCells';
import { FormulaLanguageConfig, FormulaTokenizerConfig } from './FormulaLanguageModel';
import { provideCompletionItems, provideHover } from 'quadratic-core';
import { CellEvaluationResult } from '../../../grid/computations/types';
import { Close, FiberManualRecord, PlayArrow, Subject } from '@mui/icons-material';
import { AI, Formula, Python } from '../../icons';
import { TooltipHint } from '../../components/TooltipHint';
import { SheetController } from '../../../grid/controller/sheetController';
import { focusGrid } from '../../../helpers/focusGrid';
import { KeyboardSymbols } from '../../../helpers/keyboardSymbols';
import { ResizeControl } from './ResizeControl';
import { CodeEditorPlaceholder } from './CodeEditorPlaceholder';
import mixpanel from 'mixpanel-browser';
import useAlertOnUnsavedChanges from '../../../hooks/useAlertOnUnsavedChanges';
import { useEditorCellHighlights } from '../../../hooks/useEditorCellHighlights';
import { useEditorOnSelectionChange } from '../../../hooks/useEditorOnSelectionChange';
import {
editorHighlightedCellsStateAtom,
editorHighlightedCellsStateDefault,
} from '../../../atoms/editorHighlightedCellsStateAtom';
import { loadedStateAtom } from '../../../atoms/loadedStateAtom';
import { Cell } from '../../../schemas';
import { colors } from '../../../theme/colors';
import { TooltipHint } from '../../components/TooltipHint';
import { AI, Formula, Python } from '../../icons';
import { CodeEditorPlaceholder } from './CodeEditorPlaceholder';
import { Console } from './Console';
import { FormulaLanguageConfig, FormulaTokenizerConfig } from './FormulaLanguageModel';
import { ResizeControl } from './ResizeControl';
import { QuadraticEditorTheme } from './quadraticEditorTheme';

loader.config({ paths: { vs: '/monaco/vs' } });

Expand Down Expand Up @@ -90,6 +90,8 @@ export const CodeEditor = (props: CodeEditorProps) => {
const [showSaveChangesAlert, setShowSaveChangesAlert] = useState<boolean>(false);

const hasUnsavedChanges =
// can't have unsaved changes with no cell selected
selectedCell !== undefined &&
// new cell and no content
!(cell === undefined && !editorContent) &&
// existing cell and content has changed
Expand Down

0 comments on commit 56d1dba

Please sign in to comment.