summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandmarti1424 <scim.spreadsheet@gmail.com>2015-08-22 19:00:28 -0300
committerandmarti1424 <scim.spreadsheet@gmail.com>2015-08-22 19:00:28 -0300
commit48203107dace8e0307ed76c074df173097648b0b (patch)
treef702b326ad404cf4d87663787f2217f4ec3adee3
parent794dca5a39ab03ac51d1e74d437f9ea1b1193d83 (diff)
C-v in NORMAL and INSERT mode starts VISUAL mode
-rw-r--r--src/cmds.c13
-rw-r--r--src/cmds_command.c22
-rw-r--r--src/cmds_command.h1
-rw-r--r--src/cmds_insert.c9
-rw-r--r--src/cmds_normal.c86
-rw-r--r--src/cmds_visual.c91
-rw-r--r--src/cmds_visual.h3
-rw-r--r--src/range.h16
8 files changed, 167 insertions, 74 deletions
diff --git a/src/cmds.c b/src/cmds.c
index 7bd6517..09f7ecb 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -524,7 +524,7 @@ void formatcol(int c) {
break;
}
scinfo("Current format is %d %d %d", fwidth[curcol], precision[curcol], realfmt[curcol]);
- update();
+ update(TRUE);
return;
}
@@ -946,7 +946,7 @@ void insert_or_edit_cell() {
curcol = forw_col(1)->col;
break;
}
- update();
+ update(TRUE);
return;
}
@@ -1029,7 +1029,6 @@ void clearent(struct ent *v) {
void scroll_left(int n) {
while (n--) {
if (! offscr_sc_cols ) {
- //update;
break;
}
int a = 1;
@@ -1450,14 +1449,16 @@ int is_single_command (struct block * buf, long timeout) {
int res = NO_CMD;
int bs = get_bufsize(buf);
- if (curmode == COMMAND_MODE && bs == 1 && buf->value != ctl('r')) {
+ if (curmode == COMMAND_MODE && bs == 1 && ( buf->value != ctl('r') ||
+ buf->value == ctl('v')) ) {
res = MOVEMENT_CMD;
} else if ( curmode == COMMAND_MODE && bs == 2 && buf->value == ctl('r') &&
(buf->pnext->value - ('a' - 1) < 1 || buf->pnext->value > 26)) {
res = MOVEMENT_CMD;
- } else if (curmode == INSERT_MODE && bs == 1 && buf->value != ctl('r')) {
+ } else if (curmode == INSERT_MODE && bs == 1 && ( buf->value != ctl('r') ||
+ buf->value == ctl('v')) ) {
res = MOVEMENT_CMD;
} else if (curmode == INSERT_MODE && bs == 2 && buf->value == ctl('r') &&
@@ -1665,6 +1666,8 @@ int is_single_command (struct block * buf, long timeout) {
buf->value == ctl('d') ||
buf->value == ctl('b') ||
buf->value == ctl('a') ||
+ buf->value == ctl('o') ||
+ buf->value == ctl('k') ||
buf->value == ':'
)
res = MOVEMENT_CMD;
diff --git a/src/cmds_command.c b/src/cmds_command.c
index 3b371de..de677ab 100644
--- a/src/cmds_command.c
+++ b/src/cmds_command.c
@@ -23,6 +23,8 @@
#include "xls.h"
#include "xlsx.h"
+#include "cmds_visual.h"
+
#ifdef UNDO
#include "undo.h"
#endif
@@ -152,6 +154,12 @@ void do_commandmode(struct block * sb) {
show_header(input_win);
return;
+ } else if (sb->value == ctl('v') ) { // VISUAL SUBMODE
+ visual_submode = ':';
+ chg_mode('v');
+ start_visualmode(currow, curcol, currow, curcol);
+ return;
+
} else if (sb->value == ctl('r') && get_bufsize(sb) == 2 && // C-r
(sb->pnext->value - ('a' - 1) < 1 || sb->pnext->value > 26)) {
char cline [BUFFERSIZE];
@@ -304,7 +312,7 @@ void do_commandmode(struct block * sb) {
readfile(cline, 0);
//EvalAll(); // es necesario???
modflg = 0;
- update();
+ update(TRUE);
}
} else if ( ! strncmp(inputline, "hiderow ", 8) ||
@@ -463,7 +471,7 @@ void do_commandmode(struct block * sb) {
scerror("Color support not compiled in");
chg_mode('.');
inputline[0]='\0';
- update();
+ update(TRUE);
return;
#endif
@@ -476,7 +484,7 @@ void do_commandmode(struct block * sb) {
scerror("Color support not compiled in");
chg_mode('.');
inputline[0]='\0';
- update();
+ update(TRUE);
return;
#endif
@@ -554,7 +562,7 @@ void do_commandmode(struct block * sb) {
scerror("XLS import support not compiled in");
chg_mode('.');
inputline[0]='\0';
- update();
+ update(TRUE);
return;
#endif
delim = 'x';
@@ -563,7 +571,7 @@ void do_commandmode(struct block * sb) {
scerror("XLSX import support not compiled in");
chg_mode('.');
inputline[0]='\0';
- update();
+ update(TRUE);
return;
#endif
delim = 'y';
@@ -591,7 +599,7 @@ void do_commandmode(struct block * sb) {
import_csv(cline, delim); // csv or tab delim import
}
modflg = 0;
- update();
+ update(TRUE);
}
} else {
@@ -611,7 +619,7 @@ void do_commandmode(struct block * sb) {
// clr_header(input_win); // COMENTADO el dia 22/06
inputline[0]='\0';
set_comp(0); // unmark tab completion
- update();
+ update(TRUE);
}
//show_header(input_win); // NO DESCOMENTAR.
return;
diff --git a/src/cmds_command.h b/src/cmds_command.h
index bfcb5c2..390b061 100644
--- a/src/cmds_command.h
+++ b/src/cmds_command.h
@@ -2,6 +2,7 @@
#include "buffer.h"
extern int shall_quit;
+
void do_commandmode(struct block * sb);
extern struct dictionary * user_conf_d;
diff --git a/src/cmds_insert.c b/src/cmds_insert.c
index 208fd7d..fad4114 100644
--- a/src/cmds_insert.c
+++ b/src/cmds_insert.c
@@ -7,10 +7,17 @@
#include "sc.h" // for rescol
#include "utils/string.h"
#include "marks.h"
+#include "cmds_visual.h"
void do_insertmode(struct block * sb) {
- if (sb->value == OKEY_LEFT) { // LEFT
+ if (sb->value == ctl('v') ) { // VISUAL SUBMODE
+ visual_submode = insert_edit_submode;
+ chg_mode('v');
+ start_visualmode(currow, curcol, currow, curcol);
+ return;
+
+ } else if (sb->value == OKEY_LEFT) { // LEFT
if (inputline_pos) inputline_pos--;
show_header(input_win);
diff --git a/src/cmds_normal.c b/src/cmds_normal.c
index 640334a..6af9d0a 100644
--- a/src/cmds_normal.c
+++ b/src/cmds_normal.c
@@ -32,54 +32,54 @@ void do_normalmode(struct block * buf) {
case OKEY_DOWN:
currow = forw_row(1)->row;
unselect_ranges();
- update();
+ update(TRUE);
break;
case 'k':
case OKEY_UP:
currow = back_row(1)->row;
unselect_ranges();
- update();
+ update(TRUE);
break;
case 'h':
case OKEY_LEFT:
curcol = back_col(1)->col;
unselect_ranges();
- update();
+ update(TRUE);
break;
case 'l':
case OKEY_RIGHT:
curcol = forw_col(1)->col;
unselect_ranges();
- update();
+ update(TRUE);
break;
case '0':
case OKEY_HOME:
curcol = left_limit()->col;
unselect_ranges();
- update();
+ update(TRUE);
break;
case '$':
case OKEY_END:
curcol = right_limit()->col;
unselect_ranges();
- update();
+ update(TRUE);
break;
case '^':
currow = goto_top()->row;
unselect_ranges();
- update();
+ update(TRUE);
break;
case '#':
currow = goto_bottom()->row;
unselect_ranges();
- update();
+ update(TRUE);
break;
// Tick
@@ -97,7 +97,7 @@ void do_normalmode(struct block * buf) {
}
currow = e->row;
curcol = e->col;
- update();
+ update(TRUE);
break;
// CTRL j
@@ -110,7 +110,7 @@ void do_normalmode(struct block * buf) {
cf = sr->brcol;
}
auto_justify(c, cf, DEFWIDTH); // auto justificado de columnas
- update();
+ update(TRUE);
break;
}
@@ -141,7 +141,7 @@ void do_normalmode(struct block * buf) {
return;
}
dateformat(lookat(r, c), lookat(rf, cf), f);
- update();
+ update(TRUE);
break;
#else
scinfo("Build made without USELOCALE enabled");
@@ -158,7 +158,7 @@ void do_normalmode(struct block * buf) {
currow = e->row;
unselect_ranges();
scroll_down(n);
- update();
+ update(TRUE);
break;
}
@@ -171,7 +171,7 @@ void do_normalmode(struct block * buf) {
currow = back_row(n)->row;
unselect_ranges();
scroll_up(n);
- update();
+ update(TRUE);
break;
}
@@ -180,7 +180,7 @@ void do_normalmode(struct block * buf) {
currow = e->row;
curcol = e->col;
unselect_ranges();
- update();
+ update(TRUE);
break;
case 'b':
@@ -188,7 +188,7 @@ void do_normalmode(struct block * buf) {
currow = e->row;
curcol = e->col;
unselect_ranges();
- update();
+ update(TRUE);
break;
case '/':
@@ -206,19 +206,19 @@ void do_normalmode(struct block * buf) {
case 'H':
currow = vert_top()->row;
unselect_ranges();
- update();
+ update(TRUE);
break;
case 'M':
currow = vert_middle()->row;
unselect_ranges();
- update();
+ update(TRUE);
break;
case 'L':
currow = vert_bottom()->row;
unselect_ranges();
- update();
+ update(TRUE);
break;
case 'G': // goto end
@@ -226,7 +226,7 @@ void do_normalmode(struct block * buf) {
currow = e->row;
curcol = e->col;
unselect_ranges();
- update();
+ update(TRUE);
break;
// GOTO goto
@@ -235,7 +235,7 @@ void do_normalmode(struct block * buf) {
curcol = e->col;
currow = e->row;
unselect_ranges();
- update();
+ update(TRUE);
break;
case 'g':
@@ -263,7 +263,7 @@ void do_normalmode(struct block * buf) {
send_to_interp(interp_line);
}
unselect_ranges();
- update();
+ update(TRUE);
break;
// repeat last command
@@ -337,7 +337,7 @@ void do_normalmode(struct block * buf) {
// del current cell or range
case 'x':
del_selected_cells();
- update();
+ update(TRUE);
break;
// format col
@@ -413,14 +413,14 @@ void do_normalmode(struct block * buf) {
}
if (atoi(get_conf_value("autocalc"))) EvalAll();
- update();
+ update(TRUE);
break;
}
// repeat last goto command
case 'n':
go_last();
- update();
+ update(TRUE);
break;
// range lock / unlock / valueize
@@ -441,7 +441,7 @@ void do_normalmode(struct block * buf) {
} else if (buf->pnext->value == 'v') {
valueize_area(r, c, rf, cf);
}
- update();
+ update(TRUE);
break;
}
@@ -449,7 +449,7 @@ void do_normalmode(struct block * buf) {
case 'R':
if (bs == 3) {
create_range(buf->pnext->value, buf->pnext->pnext->value, NULL, NULL);
- update();
+ update(TRUE);
}
break;
@@ -476,7 +476,7 @@ void do_normalmode(struct block * buf) {
show_col(c, arg);
}
cmd_multiplier = 0;
- update();
+ update(TRUE);
break;
}
@@ -544,7 +544,7 @@ void do_normalmode(struct block * buf) {
#endif
cmd_multiplier = 0;
unselect_ranges();
- update();
+ update(TRUE);
break;
}
@@ -595,7 +595,7 @@ void do_normalmode(struct block * buf) {
} else if (buf->pnext->value == 'd') {
del_selected_cells();
}
- update();
+ update(TRUE);
break;
}
@@ -623,7 +623,7 @@ void do_normalmode(struct block * buf) {
#ifdef UNDO
end_undo_action();
#endif
- update();
+ update(TRUE);
break;
}
@@ -655,7 +655,7 @@ void do_normalmode(struct block * buf) {
scerror("Locked cells encountered. Nothing changed");
break;
}
- update();
+ update(TRUE);
break;
case 'P':
@@ -667,7 +667,7 @@ void do_normalmode(struct block * buf) {
scerror("Locked cells encountered. Nothing changed");
break;
}
- update();
+ update(TRUE);
}
break;
@@ -677,7 +677,7 @@ void do_normalmode(struct block * buf) {
scerror("Locked cells encountered. Nothing changed");
break;
}
- update();
+ update(TRUE);
break;
// select inner range - Vir
@@ -767,19 +767,19 @@ void do_normalmode(struct block * buf) {
break;
}
- update();
+ update(TRUE);
break;
// scroll up a line
case ctl('y'):
scroll_up(1);
- update();
+ update(TRUE);
break;
// scroll down a line
case ctl('e'):
scroll_down(1);
- update();
+ update(TRUE);
break;
// undo
@@ -788,7 +788,7 @@ void do_normalmode(struct block * buf) {
do_undo();
// sync_refs();
EvalAll();
- update();
+ update(TRUE);
break;
#else
scerror("Build was done without UNDO support");
@@ -800,7 +800,7 @@ void do_normalmode(struct block * buf) {
do_redo();
// sync_refs();
EvalAll();
- update();
+ update(TRUE);
break;
#else
scerror("Build was done without UNDO support");
@@ -839,7 +839,7 @@ void do_normalmode(struct block * buf) {
end_undo_action();
#endif
cmd_multiplier = 0;
- update();
+ update(TRUE);
break;
}
@@ -847,17 +847,17 @@ void do_normalmode(struct block * buf) {
endwin();
start_screen();
clearok(stdscr, TRUE);
- update();
+ update(TRUE);
flushinp();
show_header(input_win);
show_celldetails(input_win);
wrefresh(input_win);
- update();
+ update(TRUE);
break;
case '@':
EvalAll();
- update();
+ update(TRUE);
break;
// increase or decrease numeric value of cell or range
@@ -908,7 +908,7 @@ void do_normalmode(struct block * buf) {
#endif
if (atoi(get_conf_value("autocalc"))) EvalAll();
cmd_multiplier = 0;
- update();
+ update(TRUE);
}
break;
diff --git a/src/cmds_visual.c b/src/cmds_visual.c
index 5796b1b..5526422 100644
--- a/src/cmds_visual.c
+++ b/src/cmds_visual.c
@@ -22,7 +22,10 @@ extern unsigned int curmode;
extern int cmd_multiplier;
extern struct history * commandline_history;
-srange * r; // SELECTED RANGE!
+char visual_submode = '0';
+
+srange * r; // SELECTED RANGE!
+int moving = FALSE;
void start_visualmode(int tlrow, int tlcol, int brrow, int brcol) {
unselect_ranges();
@@ -35,8 +38,10 @@ void start_visualmode(int tlrow, int tlcol, int brrow, int brcol) {
r->tlcol = tlcol;
r->brrow = brrow;
r->brcol = brcol;
- r->orig_row = currow;
- r->orig_col = curcol;
+ r->orig_row = currow; // original row before starting selection
+ r->orig_col = curcol; // original col before starting selection
+ r->startup_row = currow; // original row position before entering visual mode
+ r->startup_col = curcol; // original col position before entering visual mode
r->marks[0] = '\t';
r->marks[1] = '\t';
r->selected = 1;
@@ -49,23 +54,86 @@ void start_visualmode(int tlrow, int tlcol, int brrow, int brcol) {
ranges = r;
}
- update();
+ if (visual_submode == '0') {
+ update(TRUE);
+ } else {
+ update(FALSE);
+ moving = TRUE;
+ }
return;
}
void exit_visualmode() {
+ visual_submode = '0';
r->selected = 0;
- currow = r->orig_row;
- curcol = r->orig_col;
+ //currow = r->orig_row;
+ //curcol = r->orig_col;
+ currow = r->startup_row;
+ curcol = r->startup_col;
del_ranges_by_mark('\t');
return;
}
void do_visualmode(struct block * buf) {
-
+ if (moving == TRUE) {
+ switch (buf->value) {
+ case 'j':
+ case OKEY_DOWN:
+ currow = forw_row(1)->row;
+ break;
+
+ case 'k':
+ case OKEY_UP:
+ currow = back_row(1)->row;
+ break;
+
+ case 'h':
+ case OKEY_LEFT:
+ curcol = back_col(1)->col;
+ break;
+
+ case 'l':
+ case OKEY_RIGHT:
+ curcol = forw_col(1)->col;
+ break;
+
+ case ctl('o'):
+ moving = FALSE;
+ r->tlrow = currow;
+ r->tlcol = curcol;
+ r->brrow = currow;
+ r->brcol = curcol;
+ r->orig_row = currow;
+ r->orig_col = curcol;
+ break;
+ }
+ update(FALSE);
+ return;
+ }
+
+ // ENTER - ctl(k) - Confirm selection
+ if (buf->value == OKEY_ENTER || buf->value == ctl('k')) {
+ char cline [BUFFERSIZE];
+ sprintf(cline, "%s%d", coltoa(r->tlcol), r->tlrow);
+ if (r->tlrow != r->brrow || r->tlcol != r->brcol)
+ sprintf(cline + strlen(cline), ":%s%d", coltoa(r->brcol), r->brrow);
+ sprintf(inputline + strlen(inputline), "%s", cline);
+
+ char c = visual_submode;
+ exit_visualmode();
+ chg_mode(c);
+
+ inputline_pos += strlen(cline);
+ show_header(input_win);
+ return;
+
+ // moving to TRUE
+ //} else if (buf->value == ctl('m')) {
+ // moving = TRUE;
+
// MOVEMENT COMMANDS
// UP - ctl(b)
- if (buf->value == OKEY_UP || buf->value == 'k' || buf->value == ctl('b') ) {
+ } else if (buf->value == OKEY_UP || buf->value == 'k' || buf->value == ctl('b') ) {
int n, i;
if (buf->value == ctl('b')) {
n = LINES - RESROW - 1;
@@ -433,5 +501,10 @@ void do_visualmode(struct block * buf) {
inputline_pos = 0;
return;
}
- update();
+
+ if (visual_submode == '0')
+ update(TRUE);
+ else {
+ update(FALSE);
+ }
}
diff --git a/src/cmds_visual.h b/src/cmds_visual.h
index 5383b66..30e57db 100644
--- a/src/cmds_visual.h
+++ b/src/cmds_visual.h
@@ -1,5 +1,4 @@
-#include "buffer.h"
-
void start_visualmode(int tlrow, int tlcol, int brrow, int brcol);
void exit_visualmode();
void do_visualmode(struct block * sb);
+extern char visual_submode;
diff --git a/src/range.h b/src/range.h
index 0e7d9dc..5f1641b 100644
--- a/src/range.h
+++ b/src/range.h
@@ -1,13 +1,15 @@
#include "sc.h"
struct srange {
- int tlrow; // top left row
- int tlcol; // top left col
- int brrow; // bottom right row
- int brcol; // bottom right col
- int orig_row; // row of selected cell before creating range
- int orig_col; // col of selected cell before creating range
- char marks[2]; // marks used for creating the range
+ int tlrow; // top left row
+ int tlcol; // top left col
+ int brrow; // bottom right row
+ int brcol; // bottom right col
+ int orig_row; // original row before starting selection
+ int orig_col; // original col before starting selection
+ int startup_row; // row position before entering visual mode
+ int startup_col; // col position before entering visual mode
+ char marks[2]; // marks used for creating the range
int selected;
struct srange * pnext;
};