allow tab input in editor plus dont delete empty

This commit is contained in:
joshuaboud 2021-06-08 16:04:20 -03:00
parent 239fafba92
commit cf9f7f012a
No known key found for this signature in database
GPG Key ID: 17EFB59E2A8BF50E

View File

@ -548,7 +548,10 @@ class NavFile extends NavEntry {
async write_to_file() {
var new_contents = document.getElementById("nav-edit-contents-textarea").value;
try {
await cockpit.file(this.path_str(), {superuser: "try"}).replace(new_contents); // cockpit.script("echo -n \"$1\" > $2", [new_contents, this.path_str()], {superuser: "try"});
if (new_contents.length)
await cockpit.file(this.path_str(), {superuser: "try"}).replace(new_contents);
else
await cockpit.script("echo -n > $1", [this.path_str()], {superuser: "try"});
} catch (e) {
window.alert(e.message);
}
@ -2130,6 +2133,16 @@ function set_up_buttons() {
if (e.keyCode === 13)
nav_window.search_filter(e);
});
// fix tab in editor input
document.getElementById('nav-edit-contents-textarea').addEventListener('keydown', (e) => {
if (e.key == 'Tab') {
e.preventDefault();
var start = e.target.selectionStart;
var end = e.target.selectionEnd;
e.target.value = `${e.target.value.substring(0, start)}\t${e.target.value.substring(end)}`;
e.target.selectionStart = e.target.selectionEnd = start + 1;
}
});
}
async function main() {