summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrés <andmarti@gmail.com>2021-03-16 16:47:52 -0300
committerAndrés <andmarti@gmail.com>2021-03-16 16:47:52 -0300
commitbb3616d75bac0cdc27bd4219b2ddd512f9214cd7 (patch)
treee0809def7a967185ae27e7358828ab8223c30501
parent4e58a7d2bc242ed58e4385ee8e33e9051d3c5c3d (diff)
EDIT_MODE: added t T dt dT ct cT commands
-rw-r--r--src/cmds_edit.c58
-rwxr-xr-xsrc/doc6
-rw-r--r--src/input.c6
3 files changed, 68 insertions, 2 deletions
diff --git a/src/cmds_edit.c b/src/cmds_edit.c
index 3a26aad..149a812 100644
--- a/src/cmds_edit.c
+++ b/src/cmds_edit.c
@@ -75,6 +75,7 @@ static wint_t wi; /**< char read from stdin */
void do_editmode(struct block * sb) {
int pos;
+ int initial_position;
if (sb->value == L'h' || sb->value == OKEY_LEFT) { // LEFT
if (real_inputline_pos) {
@@ -241,6 +242,19 @@ void do_editmode(struct block * sb) {
}
return;
+ } else if (sb->value == L't') { // t
+ if (ui_getch_b(&wi) == -1) return;
+ int initial_position = inputline_pos;
+ if (inputline_pos < wcswidth(inputline, wcslen(inputline))) inputline_pos++ ;
+ pos = look_for((wchar_t) wi); // this returns real_inputline_pos !
+ if (pos != -1) {
+ real_inputline_pos = pos - 1;
+ inputline_pos = wcswidth(inputline, real_inputline_pos);
+ } else {
+ inputline_pos = initial_position;
+ }
+ ui_show_header();
+ return;
} else if (sb->value == L'F') { // F
if (ui_getch_b(&wi) == -1) return;
@@ -252,6 +266,20 @@ void do_editmode(struct block * sb) {
}
return;
+ } else if (sb->value == L'T') { // T
+ if (ui_getch_b(&wi) == -1) return;
+ int initial_position = inputline_pos;
+ if (inputline_pos) inputline_pos--;
+ pos = look_back((wchar_t) wi); // this returns real_inputline_pos !
+ if (pos != -1) {
+ real_inputline_pos = pos + 1;
+ inputline_pos = wcswidth(inputline, real_inputline_pos);
+ } else {
+ inputline_pos = initial_position;
+ }
+ ui_show_header();
+ return;
+
} else if (sb->value == L'w') { // w
real_inputline_pos = for_word(0, 0, 0);
inputline_pos = wcswidth(inputline, real_inputline_pos);
@@ -324,6 +352,19 @@ void do_editmode(struct block * sb) {
if (pos != -1) del_range_wchars(inputline, real_inputline_pos, pos);
break;
+ case L't':
+ if (ui_getch_b(&wi) == -1) return;
+ initial_position = inputline_pos;
+ if (inputline_pos < wcswidth(inputline, wcslen(inputline))) inputline_pos++ ;
+ pos = look_for((wchar_t) wi);
+ if (pos != -1) {
+ del_range_wchars(inputline, real_inputline_pos, pos - 1);
+ inputline_pos = wcswidth(inputline, real_inputline_pos);
+ } else {
+ inputline_pos = initial_position;
+ }
+ break;
+
case L'0': // 0
del_range_wchars(inputline, 0, real_inputline_pos-1);
real_inputline_pos = 0;
@@ -372,6 +413,21 @@ void do_editmode(struct block * sb) {
inputline_pos = wcswidth(inputline, real_inputline_pos);
break;
+ case L'T':
+ if (ui_getch_b(&wi) == -1) return;
+ initial_position = inputline_pos;
+ if (inputline_pos) inputline_pos--;
+ pos = look_back((wchar_t) wi);
+
+ if (pos != -1) {
+ del_range_wchars(inputline, pos+1, real_inputline_pos-1);
+ real_inputline_pos = pos;
+ inputline_pos = wcswidth(inputline, real_inputline_pos);
+ } else {
+ inputline_pos = initial_position;
+ }
+ break;
+
case L'l': // dl or cl
case OKEY_RIGHT:
del_back_char();
@@ -424,7 +480,7 @@ int look_for(wchar_t cb) {
int c, cpos = inputline_pos;
while (++cpos < wcslen(inputline))
if ((c = inputline[cpos]) && c == cb) return cpos;
- if (cpos > 0 && cpos == wcslen(inputline)) return real_inputline_pos;
+ //if (cpos > 0 && cpos == wcslen(inputline)) return real_inputline_pos;
return -1;
}
diff --git a/src/doc b/src/doc
index fceab33..e20f8b6 100755
--- a/src/doc
+++ b/src/doc
@@ -267,6 +267,8 @@ Commands for handling cell content:
$ Move to the end of the line.
f{char} Move to the next occurrence of {char} to the right.
F{char} Move to the previous occurrence of {char} to the left.
+ t{char} Move until the next occurrence of {char} to the right.
+ T{char} Move until the previous occurrence of {char} to the left.
r{char} Replaces the character under the cursor with {char}.
R{word} Each character you type replaces an existing character,
starting with the character under the cursor.
@@ -293,6 +295,8 @@ Commands for handling cell content:
d<LEFT> Delete the character before the cursor.
df{char} Delete until the first occurence of {char} to the right.
dF{char} Delete until the previous occurence of {char} to the left.
+ dt{char} Delete until the next occurrence of {char} to the right.
+ dT{char} Delete until the previous occurrence of {char} to the left.
ce Same as "de", then enter Insert mode.
@@ -311,6 +315,8 @@ Commands for handling cell content:
c<LEFT> Same as "d<LEFT>", then enter Insert mode.
cf{char} Same as "df{char}", then enter Insert mode.
cF{char} Same as "dF{char}", then enter Insert mode.
+ ct{char} Same as "dt{char}", then enter Insert mode.
+ cT{char} Same as "dT{char}", then enter Insert mode.
x Delete the character under the cursor.
X Delete the character before the cursor.
diff --git a/src/input.c b/src/input.c
index 716be6c..d0a30c1 100644
--- a/src/input.c
+++ b/src/input.c
@@ -348,7 +348,11 @@ void handle_mult(int * cmd_multiplier, struct block * buf, long timeout) {
//if (is_single_command(buf, timeout) == EDITION_CMD)
// copybuffer(buf, lastcmd_buffer); // save stdin buffer content in lastcmd buffer
exec_mult(buf, timeout);
- if (*cmd_multiplier > 1) { *cmd_multiplier = 1; ui_update(TRUE); }
+ if (*cmd_multiplier > 1) {
+ *cmd_multiplier = 1;
+ if (curmode != EDIT_MODE) ui_update(TRUE);
+ }
+
*cmd_multiplier = 0;
return;