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
This commit is contained in:
Raymond Hill 2023-03-12 17:47:21 -04:00
parent b3821e6869
commit 4bf3fe7b5b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 6 additions and 1 deletions

View File

@ -150,6 +150,10 @@ function updatePastURLs(url) {
/******************************************************************************/ /******************************************************************************/
async function setURL(resourceURL) { 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"]'); const input = qs$('#header input[type="url"]');
let to; let to;
try { try {
@ -174,7 +178,8 @@ async function setURL(resourceURL) {
cmEditor.setOption('mode', r.mime || ''); cmEditor.setOption('mode', r.mime || '');
cmEditor.setValue(r.text); cmEditor.setValue(r.text);
updatePastURLs(to.href); updatePastURLs(to.href);
cmEditor.focus(); // For unknown reasons, calling focus() synchronously does not work...
vAPI.setTimeout(( ) => { cmEditor.focus(); }, 1);
} }
/******************************************************************************/ /******************************************************************************/