feat(UX): cancel new row with escape key (#23928)

* feat: (UX) cancel new row with escape key

* fix: linters

* fix: more linters

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
This commit is contained in:
avc 2024-01-01 07:19:24 +01:00 committed by GitHub
parent 1fe3b5d5bc
commit c00d5ac258
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1135,8 +1135,8 @@ export default class GridRow {
let ignore_fieldtypes = ["Text", "Small Text", "Code", "Text Editor", "HTML Editor"];
if (field.$input) {
field.$input.on("keydown", function (e) {
var { TAB, UP: UP_ARROW, DOWN: DOWN_ARROW } = frappe.ui.keyCode;
if (![TAB, UP_ARROW, DOWN_ARROW].includes(e.which)) {
var { ESCAPE, TAB, UP: UP_ARROW, DOWN: DOWN_ARROW } = frappe.ui.keyCode;
if (![TAB, UP_ARROW, DOWN_ARROW, ESCAPE].includes(e.which)) {
return;
}
@ -1171,6 +1171,14 @@ export default class GridRow {
return true;
};
// ESC
if (e.which === ESCAPE && !e.shiftKey) {
if (me.doc.__unedited) {
me.grid.grid_rows[me.doc.idx - 1].remove();
}
return false;
}
// TAB
if (e.which === TAB && !e.shiftKey) {
var last_column = me.wrapper.find(":input:enabled:last").get(0);