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

fixes bug #611 #621

Merged
merged 1 commit into from
Jul 26, 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
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';

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the imports are the same, they are just sorted now.

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
Loading