Don't try to use the contents of the file as the file name when using the save shortcut... closes #2266

This commit is contained in:
Dane Everitt 2020-08-25 18:47:26 -07:00
parent 9e60cf9f53
commit 96fef94578
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 15 additions and 15 deletions

View File

@ -28,7 +28,7 @@ export interface Props {
filename?: string; filename?: string;
onModeChanged: (mode: string) => void; onModeChanged: (mode: string) => void;
fetchContent: (callback: () => Promise<string>) => void; fetchContent: (callback: () => Promise<string>) => void;
onContentSaved: (content: string) => void; onContentSaved: () => void;
} }
export default ({ style, initialContent, filename, mode, fetchContent, onContentSaved, onModeChanged }: Props) => { export default ({ style, initialContent, filename, mode, fetchContent, onContentSaved, onModeChanged }: Props) => {
@ -70,7 +70,7 @@ export default ({ style, initialContent, filename, mode, fetchContent, onContent
editor.commands.addCommand({ editor.commands.addCommand({
name: 'Save', name: 'Save',
bindKey: { win: 'Ctrl-s', mac: 'Command-s' }, bindKey: { win: 'Ctrl-s', mac: 'Command-s' },
exec: (editor: Editor) => onContentSaved(editor.session.getValue()), exec: () => onContentSaved(),
}); });
fetchContent(() => Promise.resolve(editor.session.getValue())); fetchContent(() => Promise.resolve(editor.session.getValue()));

View File

@ -35,8 +35,9 @@ export default () => {
let fetchFileContent: null | (() => Promise<string>) = null; let fetchFileContent: null | (() => Promise<string>) = null;
if (action !== 'new') {
useEffect(() => { useEffect(() => {
if (action === 'new') return;
setLoading(true); setLoading(true);
setError(''); setError('');
getFileContents(uuid, hash.replace(/^#/, '')) getFileContents(uuid, hash.replace(/^#/, ''))
@ -46,8 +47,7 @@ export default () => {
setError(httpErrorToHuman(error)); setError(httpErrorToHuman(error));
}) })
.then(() => setLoading(false)); .then(() => setLoading(false));
}, [ uuid, hash ]); }, [ action, uuid, hash ]);
}
const save = (name?: string) => { const save = (name?: string) => {
if (!fetchFileContent) { if (!fetchFileContent) {