webclient: tab key support
Tabulation key adds 4 spaces at current cursor position Signed-off-by: Simon LEONARD <git-1001af4@sinux.sh>
This commit is contained in:
committed by
Gunwant Jain
parent
0305742d6d
commit
78f8398382
@@ -22,10 +22,29 @@ const onInput = () => {
|
|||||||
textarea.addEventListener('input', onInput);
|
textarea.addEventListener('input', onInput);
|
||||||
onInput();
|
onInput();
|
||||||
|
|
||||||
|
const indent = (spaces = 4) => {
|
||||||
|
let cursorPosition = textarea.selectionStart;
|
||||||
|
const before = textarea.value.substring(0, cursorPosition);
|
||||||
|
const after = textarea.value.substring(cursorPosition, textarea.value.length);
|
||||||
|
|
||||||
|
// add 4 spaces
|
||||||
|
textarea.value = before + ' '.repeat(spaces) + after;
|
||||||
|
cursorPosition += spaces;
|
||||||
|
|
||||||
|
// place the cursor accordingly
|
||||||
|
textarea.selectionStart = cursorPosition;
|
||||||
|
textarea.selectionEnd = cursorPosition;
|
||||||
|
textarea.focus();
|
||||||
|
}
|
||||||
|
|
||||||
document.body.addEventListener('keydown', (e) => {
|
document.body.addEventListener('keydown', (e) => {
|
||||||
if (e.key === 'Enter' && e.ctrlKey) {
|
if (e.key === 'Enter' && e.ctrlKey) {
|
||||||
form.submit();
|
form.submit();
|
||||||
}
|
}
|
||||||
|
if (e.key === 'Tab' && !e.ctrlKey) {
|
||||||
|
preventDefaults(e);
|
||||||
|
indent();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function postData(url = '', data) {
|
async function postData(url = '', data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user