diff options
-rw-r--r-- | CHANGES | 33 | ||||
-rw-r--r-- | examples/sc/transpose.sc | 25 | ||||
-rwxr-xr-x | src/Makefile | 9 | ||||
-rw-r--r-- | src/cmds/cmds.c | 4 | ||||
-rw-r--r-- | src/cmds/cmds_normal.c | 2 | ||||
-rw-r--r-- | src/conf.c | 1 | ||||
-rwxr-xr-x | src/doc | 63 | ||||
-rw-r--r-- | src/file.c | 25 | ||||
-rw-r--r-- | src/formats/xlsx.c | 7 | ||||
-rwxr-xr-x | src/gram.y | 8 | ||||
-rw-r--r-- | src/input.c | 5 | ||||
-rw-r--r-- | src/interp.c | 21 | ||||
-rw-r--r-- | src/tui.c | 21 | ||||
-rw-r--r-- | src/yank.c | 50 | ||||
-rw-r--r-- | src/yank.h | 1 | ||||
-rw-r--r-- | tests/tests_to_add | 6 |
16 files changed, 219 insertions, 62 deletions
@@ -1,9 +1,31 @@ CHANGES FILE ------------ + + +Please open a discussion on GitHub to comment on these and other feature requests. + +*********** +v0.8.4 +06/12/2023: :datefmt does not remove text content anymore allowing future edition - work on item 3 of issue 769 +06/11/2023: avoid changing cell's color after :format - issue 819 +06/11/2023: avoid blanking cell's text content after :datefmt - issue 769 +06/10/2023: fix number 2 of issue 769 +06/02/2023: fix configuration variable name in file.c: import_delimited_to_text +06/01/2023: restore transpose +06/01/2023: added input_edit_mode setting PR 626 +06/01/2023: work on issue 708: xlsx file import +06/01/2023: Fix issue 784: get row number and column or cell that calls a LUA script with PR 814. +06/01/2023: merged PR 783 that gets rid of issue 778 - changed load_rc load_file order. +06/01/2023: merged PR 776 +06/01/2023: merged PR 789 +06/01/2023: fix issue in csv import - 816 + + + Ideas for v0.8.5 ---------------- -+ restore transpose + + Add is_deleted flag on sheets that are deleted. So ents have a chance to update its references to that sheet. Then rebuild graph. + arv should have priority over scimrc. @@ -17,16 +39,9 @@ this could allow future use of registers to copy to and paste from. -Please open a discussion on GitHub to comment on these and other feature requests. -*********** -v0.8.4 -06/01/2023: fix issue in csv import - 816 -06/01/2023: merged PR 789 -06/01/2023: merged PR 776 -06/01/2023: merged PR 783 that gets rid of issue 778 - changed load_rc load_file order. -06/01/2023: Fix issue 784: get row number and column or cell that calls a LUA script with PR 814. + *********** diff --git a/examples/sc/transpose.sc b/examples/sc/transpose.sc new file mode 100644 index 0000000..cff0d02 --- /dev/null +++ b/examples/sc/transpose.sc @@ -0,0 +1,25 @@ +# This data file was generated by the Spreadsheet Calculator Improvised (sc-im) +# You almost certainly shouldn't edit it. + +newsheet "Sheet1" +movetosheet "Sheet1" +offscr_sc_cols 0 +offscr_sc_rows 0 +nb_frozen_rows 0 +nb_frozen_cols 0 +nb_frozen_screenrows 0 +nb_frozen_screencols 0 +let A0 = 9-H0 +let B0 = 4 +let D0 = 9 +let E0 = 8 +let F0 = 7 +let H0 = 8 +let A1 = 2 +let B1 = 5 +rightstring D1 = "a" +rightstring E1 = "b" +rightstring F1 = "c" +let A2 = 3 +let B2 = 6 +goto A0 diff --git a/src/Makefile b/src/Makefile index defd77a..0915f41 100755 --- a/src/Makefile +++ b/src/Makefile @@ -134,12 +134,13 @@ ifneq (, $(shell which pkg-config)) endif # NOTE: lua support - ifneq ($(shell pkg-config --exists lua || echo 'no'),no) # Check for user's default lua - CFLAGS += -DXLUA $(shell pkg-config --cflags lua) + LUA_PKGNAME ?= $(shell pkg-config --list-all | awk '/^lua-?[0-9.]+[[:space:]]/ { p=$$1; gsub("[^[0-9]", "", p); print p " " $$1; }' | LC_ALL=C sort -nrk1 | uniq | head -n 1 | awk '{print $$2}') + ifneq ($(LUA_PKGNAME),) + CFLAGS += -DXLUA $(shell pkg-config --cflags $(LUA_PKGNAME)) ifneq ($(shell uname -s),Darwin) - LDLIBS += $(shell pkg-config --libs lua) -Wl,--export-dynamic + LDLIBS += $(shell pkg-config --libs $(LUA_PKGNAME)) -Wl,--export-dynamic else - LDLIBS += $(shell pkg-config --libs lua) -rdynamic + LDLIBS += $(shell pkg-config --libs $(LUA_PKGNAME)) -rdynamic endif else ifneq ($(shell pkg-config --exists luajit || echo 'no'),no) # If not found, check for luajit CFLAGS += -DXLUA $(shell pkg-config --cflags luajit) diff --git a/src/cmds/cmds.c b/src/cmds/cmds.c index e029d8d..ba2fba8 100644 --- a/src/cmds/cmds.c +++ b/src/cmds/cmds.c @@ -366,11 +366,11 @@ void copyent(struct ent * n, struct sheet * sh_p, struct ent * p, int dr, int dc sc_error("copyent: internal error"); return; } - n->flags = may_sync; if (p->flags & is_deleted) n->flags |= is_deleted; if (special != 'f') { + n->flags = may_sync; if (p->flags & is_valid) { n->v = p->v; n->flags |= p->flags & is_valid; @@ -2934,11 +2934,13 @@ int is_single_command (struct block * buf, long timeout) { else if (buf->value == L'P' && bs == 2 && ( buf->pnext->value == L'v' || buf->pnext->value == L'f' || ++ buf->pnext->value == L't' || buf->pnext->value == L'c' ) ) result = EDITION_CMD; // paste yanked cells below or left else if (buf->value == L'T' && bs == 2 && ( buf->pnext->value == L'v' || buf->pnext->value == L'f' || ++ buf->pnext->value == L't' || buf->pnext->value == L'c' ) ) result = EDITION_CMD; // paste yanked cells above or right else if (buf->value == L'a' && bs == 2 && // autofit diff --git a/src/cmds/cmds_normal.c b/src/cmds/cmds_normal.c index 27b8841..62e0adc 100644 --- a/src/cmds/cmds_normal.c +++ b/src/cmds/cmds_normal.c @@ -915,7 +915,7 @@ void do_normalmode(struct block * buf) { case L'P': case L'T': if (bs != 2) break; - if (buf->pnext->value == L'v' || buf->pnext->value == L'f' || buf->pnext->value == L'c') { + if (buf->pnext->value == L'v' || buf->pnext->value == L'f' || buf->pnext->value == L'c' || buf->pnext->value == L't') { int res = buf->value == L'P' ? paste_yanked_ents(sh, 0, buf->pnext->value) : paste_yanked_ents(sh, 1, buf->pnext->value); // paste cell above or right if (res == -1) { sc_error("Locked cells encountered. Nothing changed"); @@ -79,6 +79,7 @@ const char default_config[] = "version=0\n" "help=0\n" "input_bar_bottom=0\n" + "input_edit_mode=0\n" "underline_grid=0\n" #ifdef AUTOBACKUP @@ -150,6 +150,7 @@ Commands for handling cell content: leaving cell formatting intact. Pc Works like 'p' except that all cell references are adjusted in the same way that they are for the copy command. + Pt Paste a range of cells but transposed. t Same as 'p' but if yr was used to yank a row, create a new row above and paste content there. @@ -1232,22 +1233,47 @@ Commands for handling cell content: Dates are internally stored in sc-im as numeric values, and they are displayed as dates if a date format is applied to the cells that store - them. You have 3 options for entering them: + them. You have 3 options for entering dates: 1. Dates can be entered as text and then converted to a numeric - value with the :datefmt command. - - The :datefmt command takes the cell's text content that represents a date, - and uses a given format to set the numeric value of the cell. - Its format is ':datefmt "{strftime_format}"', taking a strftime-compatible - format string. The format is applied to the cell (as could be done with - the :format function) so that the value is displayed as a date. - - Example: \12/03/2020 - :datefmt "%d/%m/%Y" - - NOTE: The <C-d> command, used in NORMAL and VISUAL modes, acts as the - `:datefmt` described above, but uses the locale's D_FMT format. + value with <C-d> or with the :datefmt command. + + a. With <C-d> keybinding: + The <C-d> command works on NORMAL and VISUAL modes, and converts + cell's text content that represents a date, and sets the numeric + value of the cell using using locale's D_FMT format. + After convertion, the same format is applied automatically to the + cell so that the value is displayed as a date. + You can then change the date format with :format command or + just leave it as it is with the current locale D_FMT format. + + Example: + \03/04/1984 + <C-d> + :format "d %b %Y" + will output 'Mar 1984' with my current locale. + + NOTES: + You can edit the date value by changing the text content + of the cell with 'E' command. + + To get current locale's D_FMT format, you might want to + issue ``locale -k d_fmt`` on your current shell. + + + b. With :datefmt command: + This command works like <C-d> but instead of using locale's D_FMT + format for convertion, it takes a strftime-compatible format string as + a parameter. Its syntax is ':datefmt "{strftime_format}"' + After convertion, the same format is applied automatically to the cell + so that the value is displayed as a date. + + Example: \12/03/2020 + :datefmt "%d/%m/%Y" + + NOTE: Take note here that if you edit the date with the 'E' command, + sc-im will nevertheless convert the date using locale's D_FMT format + and not the one you used with datefmt. + You will need to reapply :datefmt "%d/%m/%Y" or whatever format + you used earlier to reapply the format after the modification. 2. You can also enter dates using the @date and @dts functions. Example: \"@date(@dts(2015, 23, 2), "%d/%m/%Y") @@ -1355,6 +1381,9 @@ Commands for handling cell content: 'input_bar_bottom' [default off] Place the input bar at the bottom of the screen. + 'input_edit_mode' [default off] + Always go from INSERT_MODE to EDIT_MODE when pressing ESC in the former. + 'underline_grid' [default off] Underline cells to make a nicer grid @@ -1789,6 +1818,12 @@ Commands for handling cell content: ============================================================================== &Other functions& + @myrow + references current row + + @mycol + references current column + @if({expr}, {expr}, {expr}) Conditional: If the first expression is true then the value of the second is returned, otherwise the value of the third. @@ -515,7 +515,7 @@ void write_fd(FILE * f, struct roman * doc) { sprintf(strcolor, " fg=%.*s", BUFFERSIZE-5, &line[0]); free(e); } else if ((cc = get_custom_color_by_number((*pp)->ucolor->fg - 7)) != NULL) { - sprintf(strcolor, " fg=%.*s", BUFFERSIZE, cc->name); + sprintf(strcolor, " fg=%.*s", BUFFERSIZE-5, cc->name); } } @@ -526,10 +526,10 @@ void write_fd(FILE * f, struct roman * doc) { decompile(e, 0); uppercase(line); del_char(line, 0); - sprintf(strcolor + strlen(strcolor), " bg=%s", &line[0]); + sprintf(strcolor + strlen(strcolor), " bg=%.*s", BUFFERSIZE-5, &line[0]); free(e); } else if ((cc = get_custom_color_by_number((*pp)->ucolor->bg - 7)) != NULL) { - sprintf(strcolor + strlen(strcolor), " bg=%.*s", BUFFERSIZE, cc->name); + sprintf(strcolor + strlen(strcolor), " bg=%.*s", BUFFERSIZE-5, cc->name); } } @@ -1177,7 +1177,7 @@ int import_csv(char * fname, char d) { char * st = str_replace (token, repls, replb); // handle "," case // number import - if (strlen(st) && isnumeric(st) && ! get_conf_int("import_delimited_as_text") + if (strlen(st) && isnumeric(st) && ! get_conf_int("import_delimited_to_text") ) { //wide char swprintf(line_interp, BUFFERSIZE, L"let %s%d=%s", coltoa(c), r, st); @@ -1324,7 +1324,7 @@ int import_markdown(char * fname) { char * st = str_replace(token, "\"", "''"); //replace double quotes inside string // number import - if (isnumeric(st) && strlen(st) && ! atoi(get_conf_value("import_delimited_as_text"))) { + if (isnumeric(st) && strlen(st) && ! atoi(get_conf_value("import_delimited_to_text"))) { //wide char swprintf(line_interp, BUFFERSIZE, L"let %s%d=%s", coltoa(c), rownr, st); @@ -2214,15 +2214,20 @@ void readfile_argv(int argc, char ** argv) { */ void load_file(char * file) { if (file == NULL || file[0] == '\0') return; - struct roman * roman = calloc(1, sizeof(struct roman)); + // Do not calloc a new roman struct everytime. See 783 PR discussion. + // use the one allocated when loading rc file. + struct roman * roman = session->cur_doc; + if (roman == NULL) { + roman = calloc(1, sizeof(struct roman)); + // save roman inside session + INSERT(roman, (session->first_doc), (session->last_doc), next, prev); + session->cur_doc = roman; // important: set cur_doc! + } + roman->name = ! strlen(file) ? NULL : strdup(file); roman->first_sh = NULL; roman->cur_sh = NULL; - // save roman inside session - INSERT(roman, (session->first_doc), (session->last_doc), next, prev); - session->cur_doc = roman; // important: set cur_doc! - // malloc a clean sheet // to make old sc file loading backwards compatible, mark it as is_allocated roman->cur_sh = roman->first_sh = new_sheet(roman, "Sheet1"); diff --git a/src/formats/xlsx.c b/src/formats/xlsx.c index 048633c..b8b5dff 100644 --- a/src/formats/xlsx.c +++ b/src/formats/xlsx.c @@ -158,7 +158,10 @@ char * get_xlsx_number_format_by_id(xmlDocPtr doc_styles, int id) { // we go forward up to numFmts section xmlNode * cur_node = xmlDocGetRootElement(doc_styles)->xmlChildrenNode; - while (cur_node != NULL && !(cur_node->type == XML_ELEMENT_NODE && !strcmp((char *) cur_node->name, "numFmts"))) + //while (cur_node != NULL && !(cur_node->type == XML_ELEMENT_NODE && !strcmp((char *) cur_node->name, "numFmts"))) + while ((cur_node != NULL) && !(cur_node->type == XML_ELEMENT_NODE && + (!strcmp((char *) cur_node->name, "numFmts") || !strcmp((char *) cur_node->name, "cellStyleXfs") || + !strcmp((char *) cur_node->name, "cellXfs")))) cur_node = cur_node->next; cur_node = cur_node->xmlChildrenNode; @@ -573,7 +576,7 @@ int export_xlsx(char * filename) { struct sheet * sh = roman->first_sh; while (sh != NULL) { - lxw_worksheet * worksheet = workbook_add_worksheet(workbook, NULL); + lxw_worksheet * worksheet = workbook_add_worksheet(workbook, sh->name); int bkp_currow = sh->currow; sh->currow = 0; insert_row(sh, 0); //add a row so that scim formulas apply to excel @@ -273,6 +273,7 @@ token S_YANKCOL %token K_INPUT_BAR_BOTTOM %token K_IGNORE_HIDDEN %token K_NOIGNORE_HIDDEN +%token K_INPUT_EDIT_MODE %token K_UNDERLINE_GRID %token K_TRUNCATE %token K_NOTRUNCATE @@ -1565,6 +1566,13 @@ setitem : ui_mv_bottom_bar(); } + | K_INPUT_EDIT_MODE '=' NUMBER { if ($3 == 0) parse_str(user_conf_d, "input_edit_mode=0", TRUE); + else parse_str(user_conf_d, "input_edit_mode=1", TRUE); + ui_mv_bottom_bar(); } + | K_INPUT_EDIT_MODE { parse_str(user_conf_d, "input_edit_mode=1", TRUE); + ui_mv_bottom_bar(); + } + | K_UNDERLINE_GRID '=' NUMBER { if ($3 == 0) parse_str(user_conf_d, "underline_grid=0", TRUE); else parse_str(user_conf_d, "underline_grid=1", TRUE); } | K_UNDERLINE_GRID { parse_str(user_conf_d, "underline_grid=1", TRUE); diff --git a/src/input.c b/src/input.c index 7df6b16..46f2451 100644 --- a/src/input.c +++ b/src/input.c @@ -238,7 +238,10 @@ void break_waitcmd_loop(struct block * buffer) { } else if (curmode == VISUAL_MODE) { exit_visualmode(); } - if (curmode == INSERT_MODE && lastmode == EDIT_MODE) { + if ( + curmode == INSERT_MODE && + ( lastmode == EDIT_MODE || get_conf_int("input_edit_mode") ) + ) { if (inputline_pos && wcslen(inputline) >= inputline_pos) { real_inputline_pos--; int l = wcwidth(inputline[real_inputline_pos]); diff --git a/src/interp.c b/src/interp.c index b67b3fc..a8a1656 100644 --- a/src/interp.c +++ b/src/interp.c @@ -1604,10 +1604,24 @@ void slet(struct roman * roman, struct sheet * sh, struct ent * v, struct enode if (v->format && v->format[0] == 'd') { struct tm tm; memset(&tm, 0, sizeof(struct tm)); - strptime(v->label, &v->format[1], &tm); + + // change for number 3 of issue 769: + // reconvert numeric value based on locale's D_FMT format instead of current format + char * f = &v->format[1]; + #ifdef USELOCALE + #include <locale.h> + #include <langinfo.h> + char * loc = NULL; + f = NULL; + loc = setlocale(LC_TIME, ""); + if (loc != NULL) f = nl_langinfo(D_FMT); + #endif + // reconvert numeric value based on locale's D_FMT format instead of current format + strptime(v->label, f, &tm); v->v = (double) mktime(&tm); v->flags |= ( is_changed | is_valid ); - label(v, "", -1); // free label + //commented for number 3 of issue 769 + //label(v, "", -1); // free label } } else { if (p) free(p); // This prevents leaks in string formulas - missing in old sc @@ -2351,7 +2365,8 @@ int dateformat(struct sheet * sh, struct ent *v1, struct ent *v2, char * fmt) { strptime((n)->label, fmt, &tm); n->v = (double) mktime(&tm); n->flags |= ( is_changed | is_valid ); - label(n, "", -1); // free label + //commented for number 3 of issue 769 + //label(n, "", -1); // free label // agrego formato de fecha n->format = 0; @@ -871,7 +871,7 @@ int ui_show_content(WINDOW * win, int nb_mobile_rows, int nb_mobile_cols) { ui_set_ucolor(win, &ucolors[EXPRESSION], ucolors[EXPRESSION].bg != DEFAULT_COLOR ? DEFAULT_COLOR : col % 2 == 0 ? ucolors[GRID_EVEN].bg : ucolors[GRID_ODD].bg); } else if ((*p) && (*p)->label) { // string ui_set_ucolor(win, &ucolors[STRG], ucolors[STRG].bg != DEFAULT_COLOR ? DEFAULT_COLOR : col % 2 == 0 ? ucolors[GRID_EVEN].bg : ucolors[GRID_ODD].bg); - } else if ((*p) && (*p)->flags & is_valid && ! (*p)->format) { // numeric value + } else if ((*p) && (*p)->flags & is_valid) { // numeric value ui_set_ucolor(win, &ucolors[NUMB], ucolors[NUMB].bg != DEFAULT_COLOR ? DEFAULT_COLOR : col % 2 == 0 ? ucolors[GRID_EVEN].bg : ucolors[GRID_ODD].bg); } else if ((*p) && (*p)->format && (*p)->format[0] == 'd') { // date format ui_set_ucolor(win, &ucolors[DATEF], ucolors[DATEF].bg != DEFAULT_COLOR ? DEFAULT_COLOR : col % 2 == 0 ? ucolors[GRID_EVEN].bg : ucolors[GRID_ODD].bg); @@ -1007,6 +1007,10 @@ int ui_show_content(WINDOW * win, int nb_mobile_rows, int nb_mobile_cols) { // else if get_conf_int("hide_number_from_combined")) // num[0]='\0'; // } + // + // AVOID showing text content and date formated numeric value both at the same time - number 3 of issue 769 + if ((*p) && (*p)->format && (*p)->format[0] == 'd') text[0]='\0'; + pad_and_align(text, num, fieldlen, align, (*p)->pad, out, sh->row_format[row]); #ifdef USECOLORS @@ -1087,6 +1091,17 @@ int ui_show_content(WINDOW * win, int nb_mobile_rows, int nb_mobile_cols) { void ui_add_cell_detail(char * d, struct ent * p1) { if ( ! p1 ) return; + /* show date if date value + if (p1->format && p1->format[0] == 'd') { // date format + strcat(d, "["); + time_t v = (time_t) p1->v; + char dvalue[FBUFLEN] = ""; + strftime(dvalue, sizeof(char) * FBUFLEN, p1->format+1, localtime(&v)); + strcat(d, dvalue); + strcat(d, "] "); + } + */ + /* string expressions if (p1->expr && (p1->flags & is_strexpr)) { if (p1->flags & is_label) @@ -1095,7 +1110,7 @@ void ui_add_cell_detail(char * d, struct ent * p1) { strcat(d, (p1->flags & is_leftflush) ? "<{" : ">{"); strcat(d, "??? } "); // and this '}' is for vi % - } else*/ + } else */ if (p1->label) { /* has constant label only */ @@ -1251,7 +1266,7 @@ void yyerror(char * err) { * \param[in] err * \return 0 datetime format - number in p->v represents a date - format "d" - * \return 1 if format of number - (numbers with format) - puede harber label. + * \return 1 if format of number - (numbers with format) - (label can exists) * \return -1 if there is no format in the cell */ int ui_get_formated_value(struct ent ** p, int col, char * value) { @@ -230,7 +230,7 @@ void yank_area(struct sheet * sh, int tlrow, int tlcol, int brrow, int brcol, ch * When implementing column sorting, diffc should be zero as well! * type indicates if pasting format only, valuue only for the * whole content. - * yank type: c=col, r=row, a=range, e=cell, '\0'=no yanking. + * type_paste: c=col, r=row, a=range, e=cell, '\0'=no yanking, t=transpose * * \param[in] struct sheet * sh * \param[in] above @@ -248,7 +248,6 @@ int paste_yanked_ents(struct sheet * sh, int above, int type_paste) { int diffr = 0, diffc = 0 , ignorelock = 0; extern struct ent_ptr * deps; - //FIXME: if (yl->sheet == NULL) yl->sheet = roman->cur_sh; #ifdef UNDO @@ -296,11 +295,18 @@ int paste_yanked_ents(struct sheet * sh, int above, int type_paste) { if (type_of_yank == YANK_RANGE || type_of_yank == YANK_CELL) { // first check if there are any locked cells over destination // if so, just return + int r, c; while (yll != NULL) { - int r = yll->vp->row + diffr; - int c = yll->vp->col + diffc; + if (type_paste == YANK_TRANSPOSE) { + r = yll->vp->col + diffr; + c = yll->vp->row + diffc; + } else { + r = yll->vp->row + diffr; + c = yll->vp->col + diffc; + } checkbounds(sh, &r, &c); - if (any_locked_cells(sh, yll->vp->row + diffr, yll->vp->col + diffc, yll->vp->row + diffr, yll->vp->col + diffc)) { + if ((type_paste == YANK_TRANSPOSE && any_locked_cells(sh, yll->vp->col + diffr, yll->vp->row + diffc, yll->vp->col + diffr, yll->vp->row + diffc)) + || any_locked_cells(sh, yll->vp->row + diffr, yll->vp->col + diffc, yll->vp->row + diffr, yll->vp->col + diffc)) { #ifdef UNDO dismiss_undo_item(NULL); #endif @@ -324,18 +330,28 @@ int paste_yanked_ents(struct sheet * sh, int above, int type_paste) { // paste each ent in yank list while (yl != NULL) { - //FIXME: if (yl->sheet == NULL) yl->sheet = roman->cur_sh; #ifdef UNDO - copy_cell_to_undostruct(y_cells++, sh, lookat(sh, yl->vp->row + diffr, yl->vp->col + diffc), UNDO_DEL); + if (type_paste == YANK_TRANSPOSE) + copy_cell_to_undostruct(y_cells++, sh, lookat(sh, yl->vp->col + diffr, yl->vp->row + diffc), UNDO_DEL); + else + copy_cell_to_undostruct(y_cells++, sh, lookat(sh, yl->vp->row + diffr, yl->vp->col + diffc), UNDO_DEL); #endif // here we delete current content of "destino" ent. - if (type_paste == YANK_RANGE || type_paste == YANK_SORT) + if (type_paste == YANK_RANGE || type_paste == YANK_SORT) { erase_area(sh, yl->vp->row + diffr, yl->vp->col + diffc, yl->vp->row + diffr, yl->vp->col + diffc, ignorelock, 0); + } else if (type_paste == YANK_TRANSPOSE) { + erase_area(sh, yl->vp->col + diffc, yl->vp->row + diffr, yl->vp->col + diffc, yl->vp->row + diffr, ignorelock, 0); + } - struct ent * destino = lookat(sh, yl->vp->row + diffr, yl->vp->col + diffc); + struct ent * destino; + if (type_paste == YANK_TRANSPOSE) { + destino = lookat(sh, yl->vp->col + diffr, yl->vp->row + diffc); + } else { + destino = lookat(sh, yl->vp->row + diffr, yl->vp->col + diffc); + } if (type_paste == YANK_RANGE || type_paste == YANK_SORT) { (void) copyent(destino, sh, yl->vp, 0, 0, 0, 0, 0, 0, 0); @@ -349,9 +365,16 @@ int paste_yanked_ents(struct sheet * sh, int above, int type_paste) { } } else if (type_paste == YANK_REF) { (void) copyent(destino, sh, yl->vp, diffr, diffc, 0, 0, sh->maxrows, sh->maxcols, 'c'); + } else if (type_paste == YANK_TRANSPOSE) { + (void) copyent(destino, sh, yl->vp, 0, 0, 0, 0, 0, 0, 0); + } + if (type_paste == YANK_TRANSPOSE) { + destino->row = yl->vp->col + diffr; + destino->col = yl->vp->row + diffc; + } else { + destino->row += diffr; + destino->col += diffc; } - destino->row += diffr; - destino->col += diffc; /******************** this might be put outside the loop */ // if so, use EvalRange @@ -371,7 +394,10 @@ int paste_yanked_ents(struct sheet * sh, int above, int type_paste) { } /*******************/ #ifdef UNDO - copy_cell_to_undostruct(y_cells++, sh, lookat(sh, yl->vp->row + diffr, yl->vp->col + diffc), UNDO_ADD); + if (type_paste == YANK_TRANSPOSE) + copy_cell_to_undostruct(y_cells++, sh, lookat(sh, yl->vp->col + diffr, yl->vp->row + diffc), UNDO_ADD); + else + copy_cell_to_undostruct(y_cells++, sh, lookat(sh, yl->vp->row + diffr, yl->vp->col + diffc), UNDO_ADD); #endif yl = yl->next; } @@ -53,6 +53,7 @@ #define YANK_FORMAT 'f' #define YANK_VALUE 'v' #define YANK_REF 'c' +#define YANK_TRANSPOSE 't' void init_yanklist(); struct ent_ptr * get_yanklist(); diff --git a/tests/tests_to_add b/tests/tests_to_add index 190cc74..0b76ec9 100644 --- a/tests/tests_to_add +++ b/tests/tests_to_add @@ -9,8 +9,10 @@ test8: delete columns and rows repeatedly with undo. test9: delete last alloc'ed column (ZZ) with undo. TODO: -+ test7: yanking and pasting ents keeping references (Pc) (with undo and redo) +transpose + +test7: yanking and pasting ents keeping references (Pc) (with undo and redo) fails to restore some ents formulas. -+ test10: copiar un rango de 10filas x 1 columna con +test10: copiar un rango de 10filas x 1 columna con referencias y pegar en la misma ubicaciĆ³n con Pv daba segfault. crear prueba. |