diff --git a/htdocs/js/FileManager/filemanager.js b/htdocs/js/FileManager/filemanager.js index 4883ebd15a..bd2a2be640 100644 --- a/htdocs/js/FileManager/filemanager.js +++ b/htdocs/js/FileManager/filemanager.js @@ -54,8 +54,8 @@ } }); - // If on the confirmation page, then focus the "name" input. - form.querySelector('input[name="name"]')?.focus(); + // If on the confirmation page (and not the edit page), then focus the "name" input. + if (!form.getElementsByName('data')[0]) form.getElementsByName('name')[0]?.focus(); } // The bits for types from least to most significant digit are set in the directoryListing method of diff --git a/lib/WeBWorK/ContentGenerator/Instructor/FileManager.pm b/lib/WeBWorK/ContentGenerator/Instructor/FileManager.pm index d5d480b530..edc7747da2 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/FileManager.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/FileManager.pm @@ -588,20 +588,11 @@ sub unpack_archive ($c, $archive) { return $num_extracted == @members; } -# Make a new file and edit it +# Open the edit page with no contents. This does not actually create a file. +# That is done when the user clicks save on the edit page. sub NewFile ($c) { - if ($c->param('confirmed')) { - my $name = $c->param('name'); - if (my $file = $c->verifyName($name, 'file')) { - if (open(my $NEWFILE, '>:encoding(UTF-8)', $file)) { - close $NEWFILE; - return $c->RefreshEdit('', $name); - } else { - $c->addbadmessage($c->maketext(q{Can't create file: [_1]}, $!)); - } - } - } - + return $c->RefreshEdit('', $c->param('name')) + if $c->param('confirmed') && $c->verifyName($c->param('name'), 'file'); return $c->Confirm($c->maketext('New file name:'), '', $c->maketext('New File')); } diff --git a/templates/ContentGenerator/Instructor/FileManager/refresh_edit.html.ep b/templates/ContentGenerator/Instructor/FileManager/refresh_edit.html.ep index d54c3e0f53..ab15cf84e3 100644 --- a/templates/ContentGenerator/Instructor/FileManager/refresh_edit.html.ep +++ b/templates/ContentGenerator/Instructor/FileManager/refresh_edit.html.ep @@ -12,10 +12,17 @@