Reset content when press / and ESC

This commit is contained in:
Night Kaly 2024-09-26 12:04:01 +01:00
parent f8dd9e6ee3
commit 9407946738
Signed by: night0721
GPG key ID: 957D67B8DB7A119B

View file

@ -533,6 +533,14 @@ void add_username(char *username)
arraylist_add(users, username, randomco, false, false); arraylist_add(users, username, randomco, false, false);
} }
void reset_content()
{
/* Reset for new input */
curs_pos = 0;
/* Set content[0] for printing purposes */
content[0] = '\0';
}
void update_panel() void update_panel()
{ {
wclear(panel); wclear(panel);
@ -692,12 +700,8 @@ void get_panel_content(int ch)
send_message(); send_message();
} else if (current_mode == COMMAND) { } else if (current_mode == COMMAND) {
use_command(); use_command();
return;
} }
/* Reset for new input */ reset_content();
curs_pos = 0;
/* Set content[0] for printing purposes */
content[0] = '\0';
} else if (curs_pos < MAX_MESSAGE_LENGTH - 1) { } else if (curs_pos < MAX_MESSAGE_LENGTH - 1) {
/* Append it to the content if it is normal character */ /* Append it to the content if it is normal character */
@ -786,6 +790,7 @@ void ui(int *fd)
int ch = getch(); int ch = getch();
switch (ch) { switch (ch) {
case ESC: case ESC:
reset_content();
current_mode = NORMAL; current_mode = NORMAL;
current_window = USERS_WINDOW; current_window = USERS_WINDOW;
draw_border(users_border, true); draw_border(users_border, true);
@ -799,8 +804,6 @@ void ui(int *fd)
case '/': case '/':
if (current_mode == NORMAL) { if (current_mode == NORMAL) {
current_mode = COMMAND; current_mode = COMMAND;
curs_pos = 0;
content[0] = '\0';
update_panel(); update_panel();
} else { } else {
get_panel_content(ch); get_panel_content(ch);
@ -843,8 +846,7 @@ void ui(int *fd)
case CLEAR_INPUT: case CLEAR_INPUT:
if (current_window == CHAT_WINDOW) { if (current_window == CHAT_WINDOW) {
curs_pos = 0; reset_content();
content[0] = '\0';
} }
break; break;