From ab8b0034fec1f17f97cfaa96d83c030180ffaa37 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Wed, 31 Jul 2019 23:28:36 -0500 Subject: [PATCH] ttable delete up/left --- src/jexer/TTableWidget.java | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/jexer/TTableWidget.java b/src/jexer/TTableWidget.java index 548acf6..f25f429 100644 --- a/src/jexer/TTableWidget.java +++ b/src/jexer/TTableWidget.java @@ -801,7 +801,7 @@ public class TTableWidget extends TWidget { public void onResize(final TResizeEvent event) { super.onResize(event); - alignGrid(); + bottomRightCorner(); } /** @@ -1276,6 +1276,24 @@ public class TTableWidget extends TWidget { return rows.size(); } + + /** + * Push top and left to the bottom-most right corner of the available + * grid. + */ + private void bottomRightCorner() { + int viewColumns = getWidth(); + if (showRowLabels == true) { + viewColumns -= ROW_LABEL_WIDTH; + } + + // Set left and top such that the table stays on screen if possible. + top = rows.size() - getHeight(); + left = columns.size() - (getWidth() / (viewColumns / (COLUMN_DEFAULT_WIDTH + 1))); + // Now ensure the selection is visible. + alignGrid(); + } + /** * Align the grid so that the selected cell is fully visible. */ @@ -1768,7 +1786,7 @@ public class TTableWidget extends TWidget { if (selectedRow == rows.size()) { selectedRow--; } - alignGrid(); + bottomRightCorner(); } /** @@ -1878,21 +1896,29 @@ public class TTableWidget extends TWidget { if (selectedColumn == columns.size()) { selectedColumn--; } - alignGrid(); + bottomRightCorner(); } /** * Delete the selected cell, shifting cells over to the left. */ public void deleteCellShiftLeft() { - // TODO + // All we do is copy the text from every cell in this row over. + for (int i = selectedColumn + 1; i < columns.size(); i++) { + setCellText(i - 1, selectedRow, getCellText(i, selectedRow)); + } + setCellText(columns.size() - 1, selectedRow, ""); } /** * Delete the selected cell, shifting cells from below up. */ public void deleteCellShiftUp() { - // TODO + // All we do is copy the text from every cell in this column up. + for (int i = selectedRow + 1; i < rows.size(); i++) { + setCellText(selectedColumn, i - 1, getCellText(selectedColumn, i)); + } + setCellText(selectedColumn, rows.size() - 1, ""); } /** -- 2.27.0