Fix command key handling. - sam - An updated version of the sam text editor.
(HTM) git clone git://vernunftzentrum.de/sam.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 7776eb1dd3c6958ae4f1b31b1b1c10cc66e8c8ac
(DIR) parent acd47eb278b12d22ba95ee1b190f2e0d2f3112a0
(HTM) Author: Rob King <jking@deadpixi.com>
Date: Thu, 11 Aug 2016 13:04:17 -0500
Fix command key handling.
Diffstat:
config.h | 3 +--
samterm/main.c | 136 +++++++++++++++----------------
2 files changed, 65 insertions(+), 74 deletions(-)
---
(DIR) diff --git a/config.h b/config.h
@@ -12,8 +12,7 @@
#define USE64BITS 1
/* Command key definitions. These should generally be ASCII control codes.
- * They should be unique. Set them to (still unique) negative values to
- * disable them.
+ * Define them to 0 to disable a key.
*/
#define LINEUP 0x05 /* Ctrl-E */
#define LINEDOWN 0x18 /* Ctrl-X */
(DIR) diff --git a/samterm/main.c b/samterm/main.c
@@ -560,78 +560,70 @@ type(Flayer *l, int res) /* what a bloody mess this is */
outTsll(Torigin, t->tag, l->origin, l->f.maxlines+1);
/* backspacing immediately after outcmd(): sorry */
} else if (moving){
- switch(c){
- case CHARLEFT: /* ctrl-s */
- flsetselect(l, a, a);
- flushtyping(0);
- if (a > 0)
- a--;
- flsetselect(l, a, a);
- center(l, a);
- break;
-
- case CHARRIGHT: /* ctrl-d */
- flsetselect(l, a, a);
- flushtyping(0);
- if (a < t->rasp.nrunes)
- a++;
- flsetselect(l, a, a);
- center(l, a);
- break;
-
- case LINEUP: /* ctrl-e */
- flsetselect(l, a, a);
- flushtyping(1);
- if (a > 0){
- long n0, n1, count = 0;
- while (a > 0 && raspc(&t->rasp, a - 1) != '\n'){
- a--;
- count++;
- }
- if (a > 0){
- n1 = a;
- a--;
- while (a > 0 && raspc(&t->rasp, a - 1) != '\n')
- a--;
-
- n0 = a;
- a = (n0 + count >= n1) ? n1 - 1 : n0 + count;
- flsetselect(l, a, a);
- center(l, a);
- }
- }
- break;
-
- case LINEDOWN: /* ctrl-x */
- flsetselect(l, a, a);
- flushtyping(1);
- if (a < t->rasp.nrunes){
- long p0, count = 0;
-
- p0 = a;
- while (a > 0 && raspc(&t->rasp, a - 1) != '\n'){
- a--;
- count++;
- }
-
- a = p0;
- while (a < t->rasp.nrunes && raspc(&t->rasp, a) != '\n')
- a++;
-
- if (a < t->rasp.nrunes){
- a++;
- while (a < t->rasp.nrunes && count > 0 && raspc(&t->rasp, a) != '\n'){
- a++;
- count--;
- }
- if (a != p0){
- flsetselect(l, a, a);
- center(l, a);
- }
- }
- }
- break;
- }
+ if (c == CHARLEFT){
+ flsetselect(l, a, a);
+ flushtyping(0);
+ if (a > 0)
+ a--;
+ flsetselect(l, a, a);
+ center(l, a);
+ } else if (c == CHARRIGHT){
+ flsetselect(l, a, a);
+ flushtyping(0);
+ if (a < t->rasp.nrunes)
+ a++;
+ flsetselect(l, a, a);
+ center(l, a);
+ } else if (c == LINEUP){
+ flsetselect(l, a, a);
+ flushtyping(1);
+ if (a > 0){
+ long n0, n1, count = 0;
+ while (a > 0 && raspc(&t->rasp, a - 1) != '\n'){
+ a--;
+ count++;
+ }
+ if (a > 0){
+ n1 = a;
+ a--;
+ while (a > 0 && raspc(&t->rasp, a - 1) != '\n')
+ a--;
+
+ n0 = a;
+ a = (n0 + count >= n1) ? n1 - 1 : n0 + count;
+ flsetselect(l, a, a);
+ center(l, a);
+ }
+ }
+ } else if (c == LINEDOWN){
+ flsetselect(l, a, a);
+ flushtyping(1);
+ if (a < t->rasp.nrunes){
+ long p0, count = 0;
+
+ p0 = a;
+ while (a > 0 && raspc(&t->rasp, a - 1) != '\n'){
+ a--;
+ count++;
+ }
+
+ a = p0;
+ while (a < t->rasp.nrunes && raspc(&t->rasp, a) != '\n')
+ a++;
+
+ if (a < t->rasp.nrunes){
+ a++;
+ while (a < t->rasp.nrunes && count > 0 && raspc(&t->rasp, a) != '\n'){
+ a++;
+ count--;
+ }
+ if (a != p0){
+ flsetselect(l, a, a);
+ center(l, a);
+ }
+ }
+ }
+ }
}else if(backspacing && !lock){
if(l->f.p0>0 && a>0){
switch(c){