From 4bf3fe7b5b89b00566094b2be884bf8244122587 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 12 Mar 2023 17:47:21 -0400 Subject: [PATCH] Fix minor details in new code viewer - Automatically remove quotes around URLs pasted in input field - Fix editor not getting the focus after interacting with input field --- src/js/code-viewer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/js/code-viewer.js b/src/js/code-viewer.js index 0a95a34a6..aff962af8 100644 --- a/src/js/code-viewer.js +++ b/src/js/code-viewer.js @@ -150,6 +150,10 @@ function updatePastURLs(url) { /******************************************************************************/ async function setURL(resourceURL) { + // For convenience, remove potentially existing quotes around the URL + if ( /^(["']).+\1$/.test(resourceURL) ) { + resourceURL = resourceURL.slice(1, -1); + } const input = qs$('#header input[type="url"]'); let to; try { @@ -174,7 +178,8 @@ async function setURL(resourceURL) { cmEditor.setOption('mode', r.mime || ''); cmEditor.setValue(r.text); updatePastURLs(to.href); - cmEditor.focus(); + // For unknown reasons, calling focus() synchronously does not work... + vAPI.setTimeout(( ) => { cmEditor.focus(); }, 1); } /******************************************************************************/