Add arrow left/right, /w alias, auto /msg on Tab in window 1

- Arrow left/right to move cursor in input (UTF-8 aware)
- /w as alias for /msg
- Tab on window 1 with empty input auto-inserts /msg <nick>
- Tab after /msg completes from PM nick list
- Improved Swedish word filter (ASCII-only + UTF-8 variants)
This commit is contained in:
2026-04-30 21:46:23 +02:00
parent 7ea04be9ee
commit 6f1c8d1f5b
+50 -6
View File
@@ -195,11 +195,14 @@ static int needs_translation(const char *text)
if (words < 1 && strlen(text) < 6) return 0; if (words < 1 && strlen(text) < 6) return 0;
/* Pre-filter: if text contains common words from skip languages, skip */ /* Pre-filter: if text contains common words from skip languages, skip */
static const struct { const char *lang; const char *words[23]; } lang_words[] = { static const struct { const char *lang; const char *words[33]; } lang_words[] = {
{"swedish", {"jag", "och", "att", "det", "inte", "var", {"swedish", {"jag", "och", "att", "det", "inte", "var",
"som", "för", "med", "har", "den", "kan", "som", "med", "har", "den", "kan",
"ska", "till", "eller", "men", "där", "ska", "till", "eller", "men",
"när", "från", "ett", "en", "ta", "ett", "en", "ta", "vad", "hur",
"dig", "du", "vi", "de", "sig",
"hade", "sedan", "bara",
"\xc3\xa4r", "\xc3\xa5", "f\xc3\xb6r",
NULL}}, NULL}},
{"english", {"the", "and", "that", "this", "with", {"english", {"the", "and", "that", "this", "with",
"have", "was", "are", "you", "not", "have", "was", "are", "you", "not",
@@ -1178,7 +1181,7 @@ static void handle_input(char *line)
const char *chan = args ? args : current_channel(); const char *chan = args ? args : current_channel();
if (chan[0]) if (chan[0])
irc_send_raw("PART %s", chan); irc_send_raw("PART %s", chan);
} else if (strcasecmp(cmd, "msg") == 0 && args) { } else if ((strcasecmp(cmd, "msg") == 0 || strcasecmp(cmd, "w") == 0) && args) {
char *target = args; char *target = args;
char *text = strchr(args, ' '); char *text = strchr(args, ' ');
if (text) { if (text) {
@@ -1663,6 +1666,24 @@ int main(int argc, char *argv[])
input_pos = 0; input_pos = 0;
redraw_input(input_line, input_len, input_pos); redraw_input(input_line, input_len, input_pos);
} }
} else if (ch == 'C') {
/* Arrow right */
if (input_pos < input_len) {
unsigned char c = input_line[input_pos];
size_t clen = 1;
if ((c & 0xE0) == 0xC0) clen = 2;
else if ((c & 0xF0) == 0xE0) clen = 3;
else if ((c & 0xF8) == 0xF0) clen = 4;
input_pos += clen;
if (input_pos > input_len) input_pos = input_len;
redraw_input(input_line, input_len, input_pos);
}
} else if (ch == 'D') {
/* Arrow left */
if (input_pos > 0) {
input_pos -= utf8_back(input_line, input_pos);
redraw_input(input_line, input_len, input_pos);
}
} }
continue; continue;
} }
@@ -1732,7 +1753,30 @@ int main(int argc, char *argv[])
char (*nlist)[NICK_LEN] = NULL; char (*nlist)[NICK_LEN] = NULL;
int ncount = 0; int ncount = 0;
if (current_level >= WL_CHAN) { /* Check if completing after /msg or /w */
int after_msg = 0;
input_line[input_len] = '\0';
if (strncasecmp(input_line, "/msg ", 5) == 0 ||
strncasecmp(input_line, "/w ", 3) == 0) {
after_msg = 1;
}
/* On window 1 with empty input, auto-insert /msg <nick> */
if (current_level == WL_STATUS && input_len == 0 && pm_nick_count > 0) {
after_msg = 1;
memcpy(input_line, "/msg ", 5);
input_len = 5;
input_pos = 5;
tab_start = 5;
tab_prefix_len = 0;
tab_end = 5;
tab_idx = 0;
}
if (after_msg) {
nlist = pm_nicks;
ncount = pm_nick_count;
} else if (current_level >= WL_CHAN) {
int cidx = current_level - WL_CHAN; int cidx = current_level - WL_CHAN;
nlist = win_chans[cidx].nicks; nlist = win_chans[cidx].nicks;
ncount = win_chans[cidx].nick_count; ncount = win_chans[cidx].nick_count;