• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂590 (tree)
時間2013-11-25 00:56:33
作者ornse01

Log Message

implement caret moving for left and right.

Change Summary

差異

--- bchank/trunk/src/bchank_lines.c (revision 589)
+++ bchank/trunk/src/bchank_lines.c (revision 590)
@@ -82,6 +82,11 @@
8282 return line->pos[pos];
8383 }
8484
85+EXPORT W bchank_line_length(bchank_line_t *line)
86+{
87+ return line->pos_len;
88+}
89+
8590 LOCAL bchank_line_t* bchank_line_new()
8691 {
8792 bchank_line_t *line;
--- bchank/trunk/src/main.c (revision 589)
+++ bchank/trunk/src/main.c (revision 590)
@@ -495,7 +495,8 @@
495495
496496 LOCAL VOID bchank_hmi_keydown(bchank_t *bchank, UH keycode, TC ch, UW stat)
497497 {
498- W lines;
498+ W lines, chars;
499+ bchank_line_t *line;
499500
500501 switch (ch) {
501502 case KC_CC_U:
@@ -503,6 +504,11 @@
503504 break;
504505 }
505506 bchank->insert_pos.y--;
507+ line = bchank_linelist_get(bchank->text, bchank->insert_pos.y);
508+ chars = bchank_line_length(line);
509+ if (bchank->insert_pos.x > chars) {
510+ bchank->insert_pos.x = chars;
511+ }
506512 bchank_caretupdate(bchank);
507513 break;
508514 case KC_CC_D:
@@ -511,11 +517,42 @@
511517 break;
512518 }
513519 bchank->insert_pos.y++;
520+ line = bchank_linelist_get(bchank->text, bchank->insert_pos.y);
521+ chars = bchank_line_length(line);
522+ if (bchank->insert_pos.x > chars) {
523+ bchank->insert_pos.x = chars;
524+ }
514525 bchank_caretupdate(bchank);
515526 break;
516527 case KC_CC_R:
528+ line = bchank_linelist_get(bchank->text, bchank->insert_pos.y);
529+ chars = bchank_line_length(line);
530+ if (bchank->insert_pos.x + 1 > chars) {
531+ lines = bchank_linelist_length(bchank->text);
532+ if (bchank->insert_pos.y + 1 >= lines) {
533+ break;
534+ }
535+ bchank->insert_pos.x = 0;
536+ bchank->insert_pos.y++;
537+ } else {
538+ bchank->insert_pos.x++;
539+ }
540+ bchank_caretupdate(bchank);
517541 break;
518542 case KC_CC_L:
543+ if (bchank->insert_pos.x - 1 < 0) {
544+ if (bchank->insert_pos.y - 1 < 0) {
545+ break;
546+ }
547+ line = bchank_linelist_get(bchank->text, bchank->insert_pos.y - 1);
548+ chars = bchank_line_length(line);
549+
550+ bchank->insert_pos.x = chars;
551+ bchank->insert_pos.y--;
552+ } else {
553+ bchank->insert_pos.x--;
554+ }
555+ bchank_caretupdate(bchank);
519556 break;
520557 case KC_PG_U:
521558 break;
@@ -542,6 +579,7 @@
542579 if (editorwindow_startredisp(window, &r) == 0) {
543580 break;
544581 }
582+ bchank_caret_disappear(&bchank->caret);
545583 editorwindow_eraseworkarea(window, &r);
546584 bchank_draw(bchank, editorwindow_getGID(window), r);
547585 bchank_caret_appear(&bchank->caret, editorwindow_getGID(window));
--- bchank/trunk/src/bchank_lines.h (revision 589)
+++ bchank/trunk/src/bchank_lines.h (revision 590)
@@ -38,6 +38,7 @@
3838 IMPORT W bchank_line_inserttext(bchank_line_t *line, W pos, TC *str, W len);
3939 IMPORT W bchank_line_removetext(bchank_line_t *line, W pos, W len);
4040 IMPORT W bchank_line_getX(bchank_line_t *line, W pos);
41+IMPORT W bchank_line_length(bchank_line_t *line);
4142
4243 typedef struct bchank_linelist_t_ bchank_linelist_t;
4344
Show on old repository browser