Can clear selected cells with delete or backspace

This commit is contained in:
Matthew Welch 2021-01-23 20:51:50 -08:00
parent 80847801f4
commit a302b37b0d

View File

@ -598,7 +598,6 @@ function headerContextMenu(event, header_id) {
function navContextMenu(event, table_id) {
if (is_positioning) {return;}
let data = getSelectionData();
let menu = $("<div>")
.attr("id", "context-menu-"+table_id)
.addClass("border context-menu text-nowrap list-group")
@ -617,7 +616,7 @@ function navContextMenu(event, table_id) {
.text("Delete Table")
.attr({"data-bs-toggle": "modal", "data-bs-target": "#delete-table"})
.on("click", () => {
$("#confirm-delete-table").one("click", (event) => {
$("#confirm-delete-table").one("click", () => {
deleteTable(table_id);
})
menu.remove();
@ -883,7 +882,7 @@ function getDeselectingNodes() {
});
}
function getSelectedCells() {
function getSelectedCells(): Array<string> {
let selectable = getSelectable();
let nodes = selectable.getSelectedNodes();
if (nodes.length === 0) {
@ -914,19 +913,6 @@ function copyToClipboard(cut=false) {
row = "header";
}
let item_text = el.text();
if (cut) {
el.text("");
let data = getSelectionData();
let table_index = data["table_index"];
let col_index = el.index();
if (el.prop("tagName") === "TH") {
tables_data[table_index]["columns"][col_index]["title"] = "";
} else {
let row_key = tables_data[table_index]["columns"][col_index]["field"];
let row_index = el.parent().index();
tables_data[table_index]["rows"][row_index][row_key] = "";
}
}
if (!previous_row) {
selection += item_text;
previous_row_elm.append("<td>"+item_text+"</td>");
@ -941,6 +927,9 @@ function copyToClipboard(cut=false) {
}
previous_row = row;
}
if (cut) {
clearCells(getSelectedCells());
}
table.append(previous_row_elm);
clipboard.clear();
clipboard.write({
@ -957,7 +946,7 @@ function pasteFromClipboard() {
row_cols[i] = rows[i].split("\t");
}
let selectable = getSelectable();
let selected_items = selectable.getSelectedItems();
let selected_items = selectable.getSelectedItems(false);
selected_items.splice(0, 1);
if(selected_items.length > 0) {
selectable.deselect(selected_items);
@ -1007,9 +996,32 @@ function selectAll(event) {
}
function backspaceDelete(event: JQuery.KeyDownEvent) {
if (!event.ctrlKey && !event.shiftKey && !event.altKey && (event.key == "Backspace" || event.key == "Delete")) {
let cells = getSelectedCells();
if (cells.length > 0) {
clearCells(cells);
}
}
}
function getColumnIDs(columns) {
function clearCells(cells: Array<string>) {
for (let cell of cells) {
let el = $("#"+cell);
el.text("");
let data = getSelectionData();
let table_index = data["table_index"];
let col_index = el.index();
if (el.prop("tagName") === "TH") {
tables_data[table_index]["columns"][col_index]["title"] = "";
} else {
let row_key = tables_data[table_index]["columns"][col_index]["field"];
let row_index = el.parent().index();
tables_data[table_index]["rows"][row_index][row_key] = "";
}
}
}
function getColumnIDs(columns): Array<string> {
let ids = [];
for (let col of columns) {
ids.push(col["field"]);
@ -1017,7 +1029,7 @@ function getColumnIDs(columns) {
return ids;
}
function getRowIDs(rows) {
function getRowIDs(rows): Array<string> {
let ids = [];
for (let row of rows) {
ids.push(row["uid"]);
@ -1025,7 +1037,7 @@ function getRowIDs(rows) {
return ids;
}
function getTableIDs() {
function getTableIDs(): Array<string> {
let ids = [];
for (let table of tables_data) {
ids.push(table["id"]);