Skip to content

Commit

Permalink
focus line in textarea when error occurred
Browse files Browse the repository at this point in the history
  • Loading branch information
tilfin committed Jul 5, 2024
1 parent 19e1ff7 commit aa6b683
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ window.onload = function() {
msg = "Configuration cannot be saved while using Private Browsing."
}
updateMessage('msgSpan', msg, 'warn');
if (typeof lastError.line === 'number') focusConfigTextArea(lastError.line);
});
} catch (e) {
updateMessage('msgSpan', `Failed to save because ${e.message}`, 'warn');
Expand Down Expand Up @@ -260,3 +261,19 @@ function updateRemoteFieldsState(state) {
elById('configHubPanel').style.display = 'none';
}
}

function focusConfigTextArea(ln) {
const ta = document.getElementById('awsConfigTextArea');
ta.scrollTop = ln < 10 ? 0 : 16 * (ln - 10);
const lines = ta.value.split('\n');
if (ln === 1) {
ta.setSelectionRange(0, lines[0].length + 1);
ta.focus();
return;
}
ln--;
const start = lines.slice(0, ln).join('\n').length + 1;
const end = start + lines[ln].length;
ta.setSelectionRange(start, end);
ta.focus();
}

0 comments on commit aa6b683

Please sign in to comment.