diff --git a/src/common/cell.c b/src/common/cell.c index 4227fac..828dce6 100644 --- a/src/common/cell.c +++ b/src/common/cell.c @@ -150,6 +150,7 @@ void freecellcontents(Cell *faded) void copycell(Cell *to, const Cell *fromcell) { assert(to != NULLCELL); + if (to == fromcell) return; freecellcontents(to); if (fromcell != NULLCELL) { diff --git a/src/common/main.c b/src/common/main.c index 3327029..b9db34e 100644 --- a/src/common/main.c +++ b/src/common/main.c @@ -1201,6 +1201,19 @@ static int do_fill(Sheet *sheet) } /*}}}*/ +/* fill the entire marked region using the current cell */ +void fillwith(Sheet *she) +{ + do_mark(she, GET_MARK_ALL); + Cell *src = curcell(she); + Location dest; + bool scan_labels = (src != NULLCELL && getlabel(src) != (const char*)0); + /* the following is safe since we have handled copying a cell to itself */ + for (ALL_LOCS_IN_REGION(she, dest)) copycelltosheet(src, she, dest); + if (scan_labels) cachelabels(she); + forceupdate(she); +} + /* do_sort -- sort block */ /*{{{*/ static int do_sort(Sheet *sheet) { @@ -1515,6 +1528,7 @@ int do_sheetcmd(Sheet *cursheet, Key c, int moveonly) case BLOCK_MOVE: do_move(cursheet,0,0); redraw_sheet(cursheet); break; case BLOCK_COPY: do_move(cursheet,1,0); redraw_sheet(cursheet); break; case BLOCK_FILL: do_fill(cursheet); redraw_sheet(cursheet); break; + case FILL_BLOCK: fillwith(cursheet); redraw_sheet(cursheet); break; case BLOCK_SORT: do_sort(cursheet); redraw_sheet(cursheet); break; case BLOCK_MIRROR: do_mirror(cursheet); redraw_sheet(cursheet); break; case ADJUST_LEFT: diff --git a/src/common/main.h b/src/common/main.h index a12473a..6ad975e 100644 --- a/src/common/main.h +++ b/src/common/main.h @@ -80,7 +80,8 @@ typedef enum { K_ABOUT = -54, K_HELP = -55, K_DUMPCELL = -56, - ADJUST_UNDERLINE = -57 + ADJUST_UNDERLINE = -57, + FILL_BLOCK = -58 } Key; extern int do_sheetcmd(Sheet *cursheet, Key c, int moveonly); @@ -89,7 +90,8 @@ extern void moveto(Sheet *sheet, int x, int y, int z); extern void movetoloc(Sheet *sheet, const Location dest); extern void relmoveto(Sheet *sheet, int x, int y, int z); extern void do_mark(Sheet *cursheet, MarkState ms); - +void fillwith(Sheet *she); + #ifdef __cplusplus } #endif diff --git a/src/common/sheet.c b/src/common/sheet.c index e9c9b34..cbe3d14 100644 --- a/src/common/sheet.c +++ b/src/common/sheet.c @@ -46,18 +46,20 @@ int max_eval; /*}}}*/ /* copycelltosheet -- copy a cell into a sheet*/ /*{{{*/ -static void copycelltosheet(const Cell *fromcell, - Sheet *sheet2, const Location to) +void copycelltosheet(const Cell *fromcell, Sheet *sheet2, const Location to) { assert(sheet2 != (Sheet*)0); + Cell *tocell = safe_cell_at(sheet2, to); + if (fromcell == tocell) return; freecellofsheet(sheet2, to); if (fromcell != NULLCELL) /* copy first cell to second */ /*{{{*/ { sheet2->changed = 1; - Cell *tocell = initcellofsheet(sheet2, to); - copycell(tocell, fromcell); + Cell *alsotocell = initcellofsheet(sheet2, to); + assert(tocell == NULLCELL || tocell == alsotocell); + copycell(alsotocell, fromcell); } /*}}}*/ } diff --git a/src/common/sheet.h b/src/common/sheet.h index d79f125..8aab356 100644 --- a/src/common/sheet.h +++ b/src/common/sheet.h @@ -73,6 +73,7 @@ extern int max_eval; void initialize_sheet(Sheet *sheet); void resize(Sheet *sheet, int x, int y, int z); Cell *initcellofsheet(Sheet *sheet, const Location at); +void copycelltosheet(const Cell *fromcell, Sheet *sheet2, const Location to); Cell *safe_cell_at(Sheet *sheet, const Location at); Cell *curcell(Sheet *sheet); void cachelabels(Sheet *sheet); diff --git a/src/fteapot.fl b/src/fteapot.fl index 9ac13ef..0d2175c 100644 --- a/src/fteapot.fl +++ b/src/fteapot.fl @@ -428,6 +428,11 @@ table->redraw();} open user_data BLOCK_FILL xywh {0 0 36 21} shortcut 0x90066 } + MenuItem {} { + label {FillWith} + user_data FILL_BLOCK + xywh {0 0 36 30} + } MenuItem {} { label {C&lear} user_data BLOCK_CLEAR