Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to merge cell text #539

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,11 +914,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 @@ -1435,6 +1432,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