Skip to content

Commit

Permalink
made it so that CTRL-W works while "browsing"
Browse files Browse the repository at this point in the history
i.e. users can now remove text from the middle as well
  • Loading branch information
ajccosta committed Oct 12, 2023
1 parent 2f62afe commit f349c89
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,26 @@ static void get_input(char* in) {
case 23:
//CTRL-W
inp = '\0';
while(in[pos-1] == ' ' && pos > 1) { //Delete trailing spaces
if(pos == 0)
continue;

int jump = 0; //Amount of characters removed
while(in[pos-1] == ' ' && pos > 0) { //Delete trailing spaces
pos--; len--; //Delete 1 character
jump++;
}
while(in[pos] != ' ' && pos > 0) { //Delete last typed word
while(in[pos-1] != ' ' && pos > 0) { //Delete last typed word
pos--; len--;
jump++;
}
in[pos] = '\0';

if(browsing) {
for (int i = pos; i <= len + jump; i++) {
in[i] = in[i + jump - 1];
}
}

in[len + 1] = '\0';

break;

Expand Down

0 comments on commit f349c89

Please sign in to comment.