Permalink
Browse files

Fix bug in ee command when horizontal offset was > 0

  • Loading branch information...
1 parent ddb7187 commit a68e6dc22130a57ad589ea0002e47c2800c6b961 James Garlick committed Feb 14, 2012
Showing with 32 additions and 12 deletions.
  1. +7 −9 src/cmd_cursor.c
  2. +16 −3 src/cmd_text.c
  3. +1 −0 src/include/editor.h
  4. +6 −0 src/pad.c
  5. +2 −0 src/tools.c
View
16 src/cmd_cursor.c
@@ -179,16 +179,17 @@ void cmd_tr (int argc, char *argv[])
void cmd_goto (int argc, char *argv[])
{
- int line = e->cpad->offset_y + e->cpad->curs_y;
- int col = e->cpad->offset_x + e->cpad->curs_x;
+ pad_t *pad = e->cepad;
+ int row = pad_pos_y(pad);
+ int col = pad_pos_x(pad);
if (argc > 1 && strlen(argv[1]) > 0) {
if (argv[1][0] == '+')
- line += atoi(argv[1] + 1);
+ row += atoi(argv[1] + 1);
else if (argv[1][0] == '-')
- line -= atoi(argv[1] + 1);
+ row -= atoi(argv[1] + 1);
else
- line = atoi(argv[1]);
+ row = atoi(argv[1]);
}
if (argc > 2 && strlen(argv[2]) > 0) {
if (argv[2][0] == '+')
@@ -198,8 +199,5 @@ void cmd_goto (int argc, char *argv[])
else
col = atoi(argv[2]);
}
- line = line - e->cpad->offset_y;
- col = col - e->cpad->offset_x;
- cursor_set_pos (e->cpad, line, col, ADJUST_RIGHT);
- move_cursor_into_view(e->cpad);
+ pad_goto(pad, row, col, ADJUST_RIGHT);
}
View
19 src/cmd_text.c
@@ -234,6 +234,7 @@ void cmd_ee (int argc, char *argv[])
{
pad_t *pad = e->cpad;
int wordwrap = 0;
+ int pos_x, pos_y;
if (!(e->cpad->flags & FILE_WRITE))
{
@@ -244,11 +245,23 @@ void cmd_ee (int argc, char *argv[])
if (argc > 1 && strcmp (argv[1], "-w") == 0)
wordwrap = 1;
- if ((pad->curs_x + pad->offset_x) == 1
- && (!wordwrap || (pad->curs_y + pad->offset_y == 1)))
+ /* hack to stop ee -w working in the input pad */
+ /* remove once local key definitions are implemented */
+ if(e->cpad == e->input_pad) wordwrap = 0;
+
+ pos_x = pad_pos_x(pad);
+ pos_y = pad_pos_y(pad);
+
+ if (pos_x == 1 && (!wordwrap || (pos_y == 1)))
return;
- cmd_al (argc, argv);
+ if(pos_x > 1) {
+ pad_goto(pad, pos_y, pos_x - 1, ADJUST_LEFT);
+ } else {
+ pad_goto(pad, pos_y - 1, pos_x, ADJUST_LEFT);
+ cmd_tr(0, NULL);
+ }
+
cmd_ed (0, NULL);
}
View
1 src/include/editor.h
@@ -183,6 +183,7 @@ int pad_pos_y(pad_t *pad);
void pad_set_prompt(pad_t *pad, char *str, void (*callback) ());
void pad_clear_prompt(pad_t *pad);
void pad_read_file(pad_t *pad, char *filename);
+void pad_goto(pad_t *pad, int row, int col, int adjust);
/* signals.c */
void sig_init (void);
View
6 src/pad.c
@@ -140,6 +140,12 @@ int pad_pos_y(pad_t *pad) {
return pad->curs_y + pad->offset_y;
}
+/* move the cursor to an absolute position in the pad and scroll into view if needed */
+void pad_goto(pad_t *pad, int row, int col, int adjust) {
+ cursor_set_pos(pad, row - pad->offset_y, col - pad->offset_x, adjust);
+ move_cursor_into_view(pad);
+}
+
void pad_set_prompt(pad_t *pad, char *str, void (*callback) ()) {
string_truncate(pad->prompt, 0);
string_append(pad->prompt, str);
View
2 src/tools.c
@@ -393,6 +393,7 @@ void cursor_set_pos (pad_t *p, int curs_y, int curs_x, int adjust)
void move_cursor_into_view(pad_t *pad) {
if (pad->curs_y < 1) {
pad->offset_y += (pad->curs_y - 1);
+ if(pad->offset_y < 0) pad->offset_y = 0;
pad->curs_y = 1;
} else if (pad->curs_y > pad->height) {
pad->offset_y += (pad->curs_y - pad->height);
@@ -401,6 +402,7 @@ void move_cursor_into_view(pad_t *pad) {
if (pad->curs_x < 1) {
pad->offset_x += (pad->curs_x - 1);
+ if(pad->offset_x < 0) pad->offset_x = 0;
pad->curs_x = 1;
} else if (pad->curs_x > pad->width) {
pad->offset_x += (pad->curs_x - pad->width);

0 comments on commit a68e6dc

Please sign in to comment.