aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/index.js
diff options
context:
space:
mode:
authorAJ ONeal <coolaj86@gmail.com>2021-07-28 21:39:46 -0600
committerGitHub <noreply@github.com>2021-07-29 05:39:46 +0200
commitb9a0e33238da353ff39258af3f0befbb83da981e (patch)
treef2cd690133d498b966bdaf33678c786071c231a7 /web_src/js/index.js
parent4e68d6f41d21e7c5465be6bdb6713c36eb586dfd (diff)
downloadgitea-b9a0e33238da353ff39258af3f0befbb83da981e.tar.gz
gitea-b9a0e33238da353ff39258af3f0befbb83da981e.zip
Pre-fill suggested New File 'name' and 'content' with Query Params (#16556)
* feature: add (GitHub-style) querystrings for pre-filling new file content * docs: add query parameters for new files
Diffstat (limited to 'web_src/js/index.js')
-rw-r--r--web_src/js/index.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/web_src/js/index.js b/web_src/js/index.js
index 6156429deb..4900d37f3f 100644
--- a/web_src/js/index.js
+++ b/web_src/js/index.js
@@ -1825,7 +1825,7 @@ async function initEditor() {
const $editArea = $('.repository.editor textarea#edit_area');
if (!$editArea.length) return;
- await createCodeEditor($editArea[0], $editFilename[0], previewFileModes);
+ const editor = await createCodeEditor($editArea[0], $editFilename[0], previewFileModes);
// Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
// to enable or disable the commit button
@@ -1849,6 +1849,14 @@ async function initEditor() {
}
});
+ // Update the editor from query params, if available,
+ // only after the dirtyFileClass initialization
+ const params = new URLSearchParams(window.location.search);
+ const value = params.get('value');
+ if (value) {
+ editor.setValue(value);
+ }
+
$commitButton.on('click', (event) => {
// A modal which asks if an empty file should be committed
if ($editArea.val().length === 0) {