added keybinds from lmumar's fork

This commit is contained in:
Iris Lightshard 2019-11-21 14:43:04 -05:00
parent 91397e2c43
commit 12944bdf68

104
text.c
View file

@ -388,7 +388,7 @@ textinsert(Text *t, uint q0, Rune *r, uint n, int tofile)
textscrdraw(u); textscrdraw(u);
} }
} }
} }
if(q0 < t->iq1) if(q0 < t->iq1)
t->iq1 += n; t->iq1 += n;
@ -549,7 +549,7 @@ textbswidth(Text *t, Rune c)
if(r == '\n'){ /* eat at most one more character */ if(r == '\n'){ /* eat at most one more character */
if(q == t->q0) /* eat the newline */ if(q == t->q0) /* eat the newline */
--q; --q;
break; break;
} }
if(c == 0x17){ if(c == 0x17){
eq = isalnum(r); eq = isalnum(r);
@ -663,7 +663,6 @@ textcomplete(Text *t)
free(path); free(path);
return rp; return rp;
} }
void void
texttype(Text *t, Rune r) texttype(Text *t, Rune r)
{ {
@ -692,10 +691,27 @@ texttype(Text *t, Rune r)
textshow(t, t->q1+1, t->q1+1, TRUE); textshow(t, t->q1+1, t->q1+1, TRUE);
return; return;
case Kdown: case Kdown:
if(t->what == Tag) typecommit(t);
goto Tagdown; q0 = t->q0;
n = t->fr.maxlines/3; nnb = 0;
goto case_Down; if(t->q0>0 && textreadc(t, t->q0-1)!='\n')
nnb = textbswidth(t, 0x15);
while(q0<t->file->b.nc && textreadc(t, q0)!='\n')
q0++;
if (q0 == t->file->b.nc) {
textshow(t, q0, q0, TRUE);
return;
}
q0++;
while(nnb>=0 && q0<t->file->b.nc) {
if (textreadc(t, q0)=='\n')
break;
nnb--;
if (nnb >= 0)
q0++;
}
textshow(t, q0, q0, TRUE);
return;
case Kscrollonedown: case Kscrollonedown:
if(t->what == Tag) if(t->what == Tag)
goto Tagdown; goto Tagdown;
@ -710,10 +726,26 @@ texttype(Text *t, Rune r)
textsetorigin(t, q0, TRUE); textsetorigin(t, q0, TRUE);
return; return;
case Kup: case Kup:
if(t->what == Tag) typecommit(t);
goto Tagup; nnb = 0;
n = t->fr.maxlines/3; if(t->q0>0 && textreadc(t, t->q0-1)!='\n')
goto case_Up; nnb = textbswidth(t, 0x15);
q1 = nnb;
if(t->q0-nnb > 1 && textreadc(t, t->q0-nnb-1)=='\n')
nnb++;
q0 = t->q0-nnb;
textshow(t, q0, q0, TRUE);
nnb = textbswidth(t, 0x15);
if (nnb <= 1)
return;
q0 = q0-nnb;
while (q1>0 && textreadc(t, q0)!='\n') {
q1--;
q0++;
}
textshow(t, q0, q0, TRUE);
return;
case Kscrolloneup: case Kscrolloneup:
if(t->what == Tag) if(t->what == Tag)
goto Tagup; goto Tagup;
@ -726,25 +758,6 @@ texttype(Text *t, Rune r)
textsetorigin(t, q0, TRUE); textsetorigin(t, q0, TRUE);
return; return;
case Khome: case Khome:
typecommit(t);
if(t->org > t->iq1) {
q0 = textbacknl(t, t->iq1, 1);
textsetorigin(t, q0, TRUE);
} else
textshow(t, 0, 0, FALSE);
return;
case Kend:
typecommit(t);
if(t->iq1 > t->org+t->fr.nchars) {
if(t->iq1 > t->file->b.nc) {
// should not happen, but does. and it will crash textbacknl.
t->iq1 = t->file->b.nc;
}
q0 = textbacknl(t, t->iq1, 1);
textsetorigin(t, q0, TRUE);
} else
textshow(t, t->file->b.nc, t->file->b.nc, FALSE);
return;
case 0x01: /* ^A: beginning of line */ case 0x01: /* ^A: beginning of line */
typecommit(t); typecommit(t);
/* go to where ^U would erase, if not already at BOL */ /* go to where ^U would erase, if not already at BOL */
@ -753,6 +766,7 @@ texttype(Text *t, Rune r)
nnb = textbswidth(t, 0x15); nnb = textbswidth(t, 0x15);
textshow(t, t->q0-nnb, t->q0-nnb, TRUE); textshow(t, t->q0-nnb, t->q0-nnb, TRUE);
return; return;
case Kend:
case 0x05: /* ^E: end of line */ case 0x05: /* ^E: end of line */
typecommit(t); typecommit(t);
q0 = t->q0; q0 = t->q0;
@ -760,19 +774,26 @@ texttype(Text *t, Rune r)
q0++; q0++;
textshow(t, q0, q0, TRUE); textshow(t, q0, q0, TRUE);
return; return;
case 0x03: /* Ctrl-c: copy */
case Kcmd+'c': /* %C: copy */ case Kcmd+'c': /* %C: copy */
typecommit(t); typecommit(t);
cut(t, t, nil, TRUE, FALSE, nil, 0); cut(t, t, nil, TRUE, FALSE, nil, 0);
return; return;
case 0x1a: /* Ctrl-z: undo */
case Kcmd+'z': /* %Z: undo */ case Kcmd+'z': /* %Z: undo */
typecommit(t); typecommit(t);
undo(t, nil, nil, TRUE, 0, nil, 0); undo(t, nil, nil, TRUE, 0, nil, 0);
return; return;
case 0x19: /* Ctrl-y: redo */
case Kcmd+'Z': /* %-shift-Z: redo */ case Kcmd+'Z': /* %-shift-Z: redo */
typecommit(t); typecommit(t);
undo(t, nil, nil, FALSE, 0, nil, 0); undo(t, nil, nil, FALSE, 0, nil, 0);
return; return;
case 0x13: /* Ctrl-S: put file */
case Kcmd+'s':
typecommit(t);
put(&(t->w)->body, nil, nil, XXX, XXX, nil, 0);
return;
Tagdown: Tagdown:
/* expand tag to show all text */ /* expand tag to show all text */
if(!t->w->tagexpand){ if(!t->w->tagexpand){
@ -780,7 +801,7 @@ texttype(Text *t, Rune r)
winresize(t->w, t->w->r, FALSE, TRUE); winresize(t->w, t->w->r, FALSE, TRUE);
} }
return; return;
Tagup: Tagup:
/* shrink tag to single line */ /* shrink tag to single line */
if(t->w->tagexpand){ if(t->w->tagexpand){
@ -796,6 +817,7 @@ texttype(Text *t, Rune r)
} }
/* cut/paste must be done after the seq++/filemark */ /* cut/paste must be done after the seq++/filemark */
switch(r){ switch(r){
case 0x18: /* Ctrl-X: cut */
case Kcmd+'x': /* %X: cut */ case Kcmd+'x': /* %X: cut */
typecommit(t); typecommit(t);
if(t->what == Body){ if(t->what == Body){
@ -806,6 +828,7 @@ texttype(Text *t, Rune r)
textshow(t, t->q0, t->q0, 1); textshow(t, t->q0, t->q0, 1);
t->iq1 = t->q0; t->iq1 = t->q0;
return; return;
case 0x16: /* Ctrl-V: paste */
case Kcmd+'v': /* %V: paste */ case Kcmd+'v': /* %V: paste */
typecommit(t); typecommit(t);
if(t->what == Body){ if(t->what == Body){
@ -940,6 +963,7 @@ texttype(Text *t, Rune r)
t->iq1 = t->q0; t->iq1 = t->q0;
} }
void void
textcommit(Text *t, int tofile) textcommit(Text *t, int tofile)
{ {
@ -1192,7 +1216,7 @@ void
textsetselect(Text *t, uint q0, uint q1) textsetselect(Text *t, uint q0, uint q1)
{ {
int p0, p1, ticked; int p0, p1, ticked;
/* t->fr.p0 and t->fr.p1 are always right; t->q0 and t->q1 may be off */ /* t->fr.p0 and t->fr.p1 are always right; t->q0 and t->q1 may be off */
t->q0 = q0; t->q0 = q0;
t->q1 = q1; t->q1 = q1;
@ -1345,7 +1369,7 @@ textselect23(Text *t, uint *q0, uint *q1, Image *high, int mask)
{ {
uint p0, p1; uint p0, p1;
int buts; int buts;
p0 = xselect(&t->fr, mousectl, high, &p1); p0 = xselect(&t->fr, mousectl, high, &p1);
buts = mousectl->m.buttons; buts = mousectl->m.buttons;
if((buts & mask) == 0){ if((buts & mask) == 0){
@ -1412,7 +1436,7 @@ textdoubleclick(Text *t, uint *q0, uint *q1)
if(textclickhtmlmatch(t, q0, q1)) if(textclickhtmlmatch(t, q0, q1))
return; return;
for(i=0; left[i]!=nil; i++){ for(i=0; left[i]!=nil; i++){
q = *q0; q = *q0;
l = left[i]; l = left[i];
@ -1444,7 +1468,7 @@ textdoubleclick(Text *t, uint *q0, uint *q1)
return; return;
} }
} }
/* try filling out word to right */ /* try filling out word to right */
while(*q1<t->file->b.nc && isalnum(textreadc(t, *q1))) while(*q1<t->file->b.nc && isalnum(textreadc(t, *q1)))
(*q1)++; (*q1)++;
@ -1518,7 +1542,7 @@ static int
ishtmlend(Text *t, uint q, uint *q0) ishtmlend(Text *t, uint q, uint *q0)
{ {
int c, c1, c2; int c, c1, c2;
if(q < 2) if(q < 2)
return 0; return 0;
if(textreadc(t, --q) != '>') if(textreadc(t, --q) != '>')
@ -1546,7 +1570,7 @@ textclickhtmlmatch(Text *t, uint *q0, uint *q1)
{ {
int depth, n; int depth, n;
uint q, nq; uint q, nq;
q = *q0; q = *q0;
// after opening tag? scan forward for closing tag // after opening tag? scan forward for closing tag
if(ishtmlend(t, q, nil) == 1) { if(ishtmlend(t, q, nil) == 1) {
@ -1583,7 +1607,7 @@ textclickhtmlmatch(Text *t, uint *q0, uint *q1)
q--; q--;
} }
} }
return 0; return 0;
} }