Skip to content

Commit

Permalink
Add option to merge cell text (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiolo authored Oct 13, 2023
1 parent 92ad1ff commit 50e1fad
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,8 @@ struct Document {
if (uk == WXK_NONE || (k < ' ' && k) || k == WXK_DELETE) {
switch (k) {
case WXK_BACK: // no menu shortcut available in wxwidgets
if (!ctrl) {
return Action(dc, A_BACKSPACE);
} else { // prevent Ctrl+H from being treated as Backspace
break;
}
if (!ctrl) return Action(dc, A_BACKSPACE);
break; // Prevent Ctrl+H from being treated as Backspace
case WXK_RETURN: return Action(dc, shift ? A_ENTERGRID : A_ENTERCELL);
case WXK_ESCAPE: // docs say it can be used as a menu accelerator, but it does not
// trigger from there?
Expand Down Expand Up @@ -1429,6 +1426,29 @@ struct Document {
}
return nullptr;

case A_COLLAPSE: {
if (selected.xs * selected.ys == 1) return _(L"More than one cell must be selected.");
auto fc = selected.GetFirst();
wxString ct = "";
loopallcellssel(ci, true) if (ci != fc && ci->text.t.Len()) ct += " " + ci->text.t;
if (!fc->HasContent() && !ct.Len()) return _(L"There is no content to collapse.");
fc->parent->AddUndo(this);
fc->text.t += ct;
loopallcellssel(ci, false) if (ci != fc) ci->Clear();
Selection deletesel(
selected.g,
selected.x + int(selected.xs > 1), // sidestep is possible?
selected.y + int(selected.ys > 1),
selected.xs - int(selected.xs > 1),
selected.ys - int(selected.ys > 1)
);
selected.g->MultiCellDeleteSub(this, deletesel);
SetSelect(Selection(selected.g, selected.x, selected.y, 1, 1));
fc->ResetLayout();
Refresh();
return nullptr;
}

case A_SELALL:
selected.SelAll();
Refresh();
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum {
A_CUT,
A_COPY,
A_PASTE,
A_COLLAPSE,
A_NEWGRID,
A_UNDO,
A_ABOUT,
Expand Down
1 change: 1 addition & 0 deletions src/myframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ struct MyFrame : wxFrame {
MyAppend(editmenu, A_PASTE, _(L"&Paste\tCTRL+v"));
MyAppend(editmenu, A_PASTESTYLE, _(L"Paste Style Only\tCTRL+SHIFT+v"),
_(L"only sets the colors and style of the copied cell, and keeps the text"));
MyAppend(editmenu, A_COLLAPSE, _(L"Collapse Ce&lls\tCTRL+l"));
editmenu->AppendSeparator();
MyAppend(editmenu, A_UNDO, _(L"&Undo\tCTRL+z"), _(L"revert the changes, one step at a time"));
MyAppend(editmenu, A_REDO, _(L"&Redo\tCTRL+y"),
Expand Down

0 comments on commit 50e1fad

Please sign in to comment.