EDIT: Refresh selection without redrawing whole screen (for cursor left/right)

This commit is contained in:
Bobbi Webber-Manners 2020-08-04 19:14:52 -04:00
parent 69ddaab305
commit 78b992d404

View File

@ -7,7 +7,7 @@
// TODO: Maybe rework load_file() again to avoid memmove() // TODO: Maybe rework load_file() again to avoid memmove()
// TODO: Adjust beep() sound // TODO: Adjust beep() sound
// TODO: Should be smarter about redrawing when updating selection!!! // TODO: Redrawing selection on cursor_up()/cursor_down()
// TODO: Make use of aux mem // TODO: Make use of aux mem
#include <conio.h> #include <conio.h>
@ -518,6 +518,7 @@ done:
* rowlen[] - length of each screen row in chars * rowlen[] - length of each screen row in chars
*/ */
uint8_t read_char_update_pos(void) { uint8_t read_char_update_pos(void) {
uint16_t delta = gapend - gapbegin;
char c; char c;
if ((c = gapbuf[pos++]) == EOL) { if ((c = gapbuf[pos++]) == EOL) {
if (do_print) { if (do_print) {
@ -529,7 +530,8 @@ uint8_t read_char_update_pos(void) {
col = 0; col = 0;
return 1; return 1;
} }
if ((pos > startsel) && (pos <= endsel)) if (((pos > startsel) && (pos <= endsel)) || // Left of cursor
((pos - delta > endsel) && (pos - delta <= startsel + 1))) // Right of cursor
revers(1); revers(1);
else else
revers(0); revers(0);
@ -805,6 +807,13 @@ void cursor_left(void) {
} else } else
--curscol; --curscol;
gotoxy(curscol, cursrow); gotoxy(curscol, cursrow);
if (mode > SEL_MOVE2) {
endsel = gapbegin;
revers(gapbegin < startsel ? 1 : 0);
cputc(gapbuf[gapbegin]);
revers(0);
}
gotoxy(curscol, cursrow);
} }
#pragma code-name (pop) #pragma code-name (pop)
@ -831,7 +840,7 @@ void cursor_right(void) {
done: done:
if (mode > SEL_MOVE2) { if (mode > SEL_MOVE2) {
endsel = gapbegin; endsel = gapbegin;
revers(1); revers(gapbegin > startsel ? 1 : 0);
cputc(gapbuf[gapbegin - 1]); cputc(gapbuf[gapbegin - 1]);
revers(0); revers(0);
} }
@ -1152,33 +1161,17 @@ int edit(char *fname) {
break; break;
case 0x80 + 0x08: // OA-Left "Word left" case 0x80 + 0x08: // OA-Left "Word left"
word_left(); word_left();
if (mode > SEL_MOVE2) {
endsel = gapbegin;
draw_screen();
}
break; break;
case 0x80 + 0x15: // OA-Right "Word right" case 0x80 + 0x15: // OA-Right "Word right"
word_right(); word_right();
if (mode > SEL_MOVE2) {
endsel = gapbegin;
draw_screen();
}
break; break;
case 0x80 + ',': // OA-< "Home" case 0x80 + ',': // OA-< "Home"
case 0x80 + '<': case 0x80 + '<':
goto_bol(); goto_bol();
if (mode > SEL_MOVE2) {
endsel = gapbegin;
draw_screen();
}
break; break;
case 0x80 + '.': // OA-> "End" case 0x80 + '.': // OA-> "End"
case 0x80 + '>': case 0x80 + '>':
goto_eol(); goto_eol();
if (mode > SEL_MOVE2) {
endsel = gapbegin;
draw_screen();
}
break; break;
case 0x8b: // OA-Up "Page Up" case 0x8b: // OA-Up "Page Up"
page_up(); page_up();
@ -1385,10 +1378,6 @@ int edit(char *fname) {
break; break;
case 0x08: // Left case 0x08: // Left
cursor_left(); cursor_left();
if (mode > SEL_MOVE2) {
endsel = gapbegin;
draw_screen();
}
break; break;
case 0x15: // Right case 0x15: // Right
cursor_right(); cursor_right();