summaryrefslogtreecommitdiffstats
path: root/src/cmd/acme/text.c
diff options
context:
space:
mode:
authorbt <bt@rctt.net>2026-02-20 16:04:44 +0100
committerbt <bt@rctt.net>2026-02-24 22:55:48 +0100
commite14493abb20ab0c808f109bb56aaf141ad08d178 (patch)
treefbfed0aae4d4cca733a2ecbcb7fa92c2a35cfeb2 /src/cmd/acme/text.c
parentcb7001c8d27f22f7229be302f53012bb1db52418 (diff)
downloadplan9port-patch.tar.gz
plan9port-patch.zip
Custom shortcuts and other minor changespatch
Diffstat (limited to 'src/cmd/acme/text.c')
-rw-r--r--src/cmd/acme/text.c103
1 files changed, 98 insertions, 5 deletions
diff --git a/src/cmd/acme/text.c b/src/cmd/acme/text.c
index 09422dda..220dcdf7 100644
--- a/src/cmd/acme/text.c
+++ b/src/cmd/acme/text.c
@@ -12,6 +12,7 @@
#include <complete.h>
#include "dat.h"
#include "fns.h"
+#include "keyboard-extras.h"
Image *tagcols[NCOL];
Image *textcols[NCOL];
@@ -540,7 +541,7 @@ textbswidth(Text *t, Rune c)
int skipping;
/* there is known to be at least one character to erase */
- if(c == 0x08) /* ^H: erase character */
+ if(c == 0x08 || c == Kdel) /* ^H or ^?: erase character */
return 1;
q = t->q0;
skipping = TRUE;
@@ -686,16 +687,44 @@ texttype(Text *t, Rune r)
if(t->q0 > 0)
textshow(t, t->q0-1, t->q0-1, TRUE);
return;
+ case Ksh + Kleft: /* Shift + Left */
+ typecommit(t);
+ if(t->q0 > 0)
+ textshow(t, t->q0-1, t->q1, TRUE);
+ return;
case Kright:
typecommit(t);
if(t->q1 < t->file->b.nc)
textshow(t, t->q1+1, t->q1+1, TRUE);
return;
+ case Ksh + Kright: /* Shift + Right */
+ typecommit(t);
+ if(t->q1 < t->file->b.nc)
+ textshow(t, t->q0, t->q1+1, TRUE);
+ return;
case Kdown:
+ case Ksh + Kdown:
if(t->what == Tag)
goto Tagdown;
- n = t->fr.maxlines/3;
- goto case_Down;
+ typecommit(t);
+ nnb = 0;
+ if(t->q0>0 && textreadc(t, t->q0-1)!='\n')
+ nnb = textbswidth(t, 0x15);
+ q1 = t->q1;
+ while(q1<t->file->b.nc && textreadc(t, q1)!='\n')
+ q1++;
+ if(q1<t->file->b.nc){
+ q1++;
+ while(q1<t->file->b.nc && nnb > 0 && textreadc(t, q1)!='\n') {
+ nnb--;
+ q1++;
+ }
+ if(r == Kdown)
+ textshow(t, q1, q1, TRUE);
+ else /* Shift + Down */
+ textshow(t, t->q0, q1, TRUE);
+ }
+ return;
case Kscrollonedown:
if(t->what == Tag)
goto Tagdown;
@@ -712,8 +741,23 @@ texttype(Text *t, Rune r)
case Kup:
if(t->what == Tag)
goto Tagup;
- n = t->fr.maxlines/3;
- goto case_Up;
+ typecommit(t);
+ nnb = 0;
+ if(t->q0>0 && textreadc(t, t->q0-1)!='\n')
+ nnb = textbswidth(t, 0x15);
+ q0 = t->q0 - nnb;
+ if(q0 > 0){
+ nb = q0;
+ q0--;
+ while(q0 > 0 && textreadc(t, q0-1)!='\n')
+ q0--;
+ q1 = (q0 + nnb >= nb) ? nb - 1 : q0 + nnb;
+ if(r == Kup)
+ textshow(t, q1, q1, TRUE);
+ else /* Shift + Up */
+ textshow(t, q1, t->q1, TRUE);
+ }
+ return;
case Kscrolloneup:
if(t->what == Tag)
goto Tagup;
@@ -753,6 +797,13 @@ texttype(Text *t, Rune r)
nnb = textbswidth(t, 0x15);
textshow(t, t->q0-nnb, t->q0-nnb, TRUE);
return;
+ case Ksh + (Kleft&0x9f): /* Ctrl + Shift + Left */
+ typecommit(t);
+ nnb = 0;
+ if(t->q0>0 && textreadc(t, t->q0-1)!='\n')
+ nnb = textbswidth(t, 0x15);
+ textshow(t, t->q0-nnb, t->q1, TRUE);
+ return;
case 0x05: /* ^E: end of line */
typecommit(t);
q0 = t->q0;
@@ -760,18 +811,41 @@ texttype(Text *t, Rune r)
q0++;
textshow(t, q0, q0, TRUE);
return;
+ case Ksh + (Kright&0x9f): /* Ctrl + Shift + Right */
+ typecommit(t);
+ q1 = t->q1;
+ while(q1<t->file->b.nc && textreadc(t, q1)!='\n')
+ q1++;
+ textshow(t, t->q0, q1, TRUE);
+ return;
case Kcmd+'c': /* %C: copy */
+ case Ketx:
typecommit(t);
cut(t, t, nil, TRUE, FALSE, nil, 0);
return;
case Kcmd+'z': /* %Z: undo */
+ case Ksub:
typecommit(t);
undo(t, nil, nil, TRUE, 0, nil, 0);
return;
case Kcmd+'Z': /* %-shift-Z: redo */
+ case Keom:
typecommit(t);
undo(t, nil, nil, FALSE, 0, nil, 0);
return;
+ case Kdc3: /* ^S: put */
+ case Kcmd+'s':
+ typecommit(t);
+ put(t, nil, nil, XXX, XXX, nil, 0);
+ return;
+ case Kcret: /* Ctrl + Return */
+ typecommit(t);
+ execute(t, t->q0, t->q1, FALSE, nil);
+ return;
+ case Ksh + Kcret: /* Ctrl + Shift + Return */
+ typecommit(t);
+ look3(t, t->q0, t->q1, 0, FALSE);
+ return;
Tagdown:
/* expand tag to show all text */
@@ -797,6 +871,7 @@ texttype(Text *t, Rune r)
/* cut/paste must be done after the seq++/filemark */
switch(r){
case Kcmd+'x': /* %X: cut */
+ case Kcan: /* ^X: cut */
typecommit(t);
if(t->what == Body){
seq++;
@@ -807,6 +882,7 @@ texttype(Text *t, Rune r)
t->iq1 = t->q0;
return;
case Kcmd+'v': /* %V: paste */
+ case Ksyn:
typecommit(t);
if(t->what == Body){
seq++;
@@ -844,6 +920,13 @@ texttype(Text *t, Rune r)
typecommit(t);
t->iq1 = t->q0;
return;
+ case Kdel: /* ^? erase forwards */
+ if(t->q1 == t->file->b.nc) /* nothing to erase */
+ return;
+ nnb = textbswidth(t, r);
+ q0 = t->q1;
+ q1 = q0+nnb;
+ goto Erase;
case 0x08: /* ^H: erase character */
case 0x15: /* ^U: erase line */
case 0x17: /* ^W: erase word */
@@ -859,6 +942,7 @@ texttype(Text *t, Rune r)
}
if(nnb <= 0)
return;
+ Erase:
for(i=0; i<t->file->ntext; i++){
u = t->file->text[i];
u->nofill = TRUE;
@@ -887,6 +971,15 @@ texttype(Text *t, Rune r)
textfill(t->file->text[i]);
t->iq1 = t->q0;
return;
+ case Ksh + Ketx:
+ case Ksh + Kdc3:
+ case Ksh + Ksyn:
+ case Ksh + Kcan:
+ case Ksh + Keom:
+ case Ksh + Ksub:
+ case Ksh + Kdel:
+ r -= Ksh; /* Send control codes without shift modifier */
+ break; /* fall through to insertion */
case '\n':
if(t->w->autoindent){
/* find beginning of previous line using backspace code */