Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix bug in ee command when horizontal offset was > 0

  • Loading branch information...
commit a68e6dc22130a57ad589ea0002e47c2800c6b961 1 parent ddb7187
James Garlick authored
16 src/cmd_cursor.c
@@ -179,16 +179,17 @@ void cmd_tr (int argc, char *argv[])
179 179
180 180 void cmd_goto (int argc, char *argv[])
181 181 {
182   - int line = e->cpad->offset_y + e->cpad->curs_y;
183   - int col = e->cpad->offset_x + e->cpad->curs_x;
  182 + pad_t *pad = e->cepad;
  183 + int row = pad_pos_y(pad);
  184 + int col = pad_pos_x(pad);
184 185
185 186 if (argc > 1 && strlen(argv[1]) > 0) {
186 187 if (argv[1][0] == '+')
187   - line += atoi(argv[1] + 1);
  188 + row += atoi(argv[1] + 1);
188 189 else if (argv[1][0] == '-')
189   - line -= atoi(argv[1] + 1);
  190 + row -= atoi(argv[1] + 1);
190 191 else
191   - line = atoi(argv[1]);
  192 + row = atoi(argv[1]);
192 193 }
193 194 if (argc > 2 && strlen(argv[2]) > 0) {
194 195 if (argv[2][0] == '+')
@@ -198,8 +199,5 @@ void cmd_goto (int argc, char *argv[])
198 199 else
199 200 col = atoi(argv[2]);
200 201 }
201   - line = line - e->cpad->offset_y;
202   - col = col - e->cpad->offset_x;
203   - cursor_set_pos (e->cpad, line, col, ADJUST_RIGHT);
204   - move_cursor_into_view(e->cpad);
  202 + pad_goto(pad, row, col, ADJUST_RIGHT);
205 203 }
19 src/cmd_text.c
@@ -234,6 +234,7 @@ void cmd_ee (int argc, char *argv[])
234 234 {
235 235 pad_t *pad = e->cpad;
236 236 int wordwrap = 0;
  237 + int pos_x, pos_y;
237 238
238 239 if (!(e->cpad->flags & FILE_WRITE))
239 240 {
@@ -244,11 +245,23 @@ void cmd_ee (int argc, char *argv[])
244 245 if (argc > 1 && strcmp (argv[1], "-w") == 0)
245 246 wordwrap = 1;
246 247
247   - if ((pad->curs_x + pad->offset_x) == 1
248   - && (!wordwrap || (pad->curs_y + pad->offset_y == 1)))
  248 + /* hack to stop ee -w working in the input pad */
  249 + /* remove once local key definitions are implemented */
  250 + if(e->cpad == e->input_pad) wordwrap = 0;
  251 +
  252 + pos_x = pad_pos_x(pad);
  253 + pos_y = pad_pos_y(pad);
  254 +
  255 + if (pos_x == 1 && (!wordwrap || (pos_y == 1)))
249 256 return;
250 257
251   - cmd_al (argc, argv);
  258 + if(pos_x > 1) {
  259 + pad_goto(pad, pos_y, pos_x - 1, ADJUST_LEFT);
  260 + } else {
  261 + pad_goto(pad, pos_y - 1, pos_x, ADJUST_LEFT);
  262 + cmd_tr(0, NULL);
  263 + }
  264 +
252 265 cmd_ed (0, NULL);
253 266 }
254 267
1  src/include/editor.h
@@ -183,6 +183,7 @@ int pad_pos_y(pad_t *pad);
183 183 void pad_set_prompt(pad_t *pad, char *str, void (*callback) ());
184 184 void pad_clear_prompt(pad_t *pad);
185 185 void pad_read_file(pad_t *pad, char *filename);
  186 +void pad_goto(pad_t *pad, int row, int col, int adjust);
186 187
187 188 /* signals.c */
188 189 void sig_init (void);
6 src/pad.c
@@ -140,6 +140,12 @@ int pad_pos_y(pad_t *pad) {
140 140 return pad->curs_y + pad->offset_y;
141 141 }
142 142
  143 +/* move the cursor to an absolute position in the pad and scroll into view if needed */
  144 +void pad_goto(pad_t *pad, int row, int col, int adjust) {
  145 + cursor_set_pos(pad, row - pad->offset_y, col - pad->offset_x, adjust);
  146 + move_cursor_into_view(pad);
  147 +}
  148 +
143 149 void pad_set_prompt(pad_t *pad, char *str, void (*callback) ()) {
144 150 string_truncate(pad->prompt, 0);
145 151 string_append(pad->prompt, str);
2  src/tools.c
@@ -393,6 +393,7 @@ void cursor_set_pos (pad_t *p, int curs_y, int curs_x, int adjust)
393 393 void move_cursor_into_view(pad_t *pad) {
394 394 if (pad->curs_y < 1) {
395 395 pad->offset_y += (pad->curs_y - 1);
  396 + if(pad->offset_y < 0) pad->offset_y = 0;
396 397 pad->curs_y = 1;
397 398 } else if (pad->curs_y > pad->height) {
398 399 pad->offset_y += (pad->curs_y - pad->height);
@@ -401,6 +402,7 @@ void move_cursor_into_view(pad_t *pad) {
401 402
402 403 if (pad->curs_x < 1) {
403 404 pad->offset_x += (pad->curs_x - 1);
  405 + if(pad->offset_x < 0) pad->offset_x = 0;
404 406 pad->curs_x = 1;
405 407 } else if (pad->curs_x > pad->width) {
406 408 pad->offset_x += (pad->curs_x - pad->width);

0 comments on commit a68e6dc

Please sign in to comment.
Something went wrong with that request. Please try again.