Skip to content

Commit

Permalink
Focus the line in textarea when error occurred (#348)
Browse files Browse the repository at this point in the history
* focus line in textarea when error occurred

* update aesr-config and pump 5.0.1

* fix option test configuration
  • Loading branch information
tilfin authored Oct 21, 2024
1 parent f5caa91 commit 718ca4b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"homepage": "https://github.com/tilfinltd/aws-extend-switch-roles#readme",
"dependencies": {
"aesr-config": "^0.4.1"
"aesr-config": "^0.5.1"
},
"devDependencies": {
"@playwright/test": "^1.38.1",
Expand Down
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();
}
2 changes: 1 addition & 1 deletion test/emulator/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ source_profile = src/B
[profile A/2]
aws_account_id = 000011112224
role_name=target-a2
color=#00cc33
color=00cc33
source_profile=src-A
; comment`);
await page.locator('#saveButton').click();
Expand Down

0 comments on commit 718ca4b

Please sign in to comment.