mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Merge pull request #1789 from MarcoPolo-PasTonMolo/fix/autocompletion_after_MAM
Fix quote and url autocompletion for MAM and history
This commit is contained in:
commit
0c24271a63
@ -141,7 +141,7 @@ autocomplete_update(Autocomplete ac, char** items)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
autocomplete_add_reverse(Autocomplete ac, const char* item)
|
autocomplete_add_unsorted(Autocomplete ac, const char* item, const gboolean is_reversed)
|
||||||
{
|
{
|
||||||
if (ac) {
|
if (ac) {
|
||||||
char* item_cpy;
|
char* item_cpy;
|
||||||
@ -153,7 +153,12 @@ autocomplete_add_reverse(Autocomplete ac, const char* item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
item_cpy = strdup(item);
|
item_cpy = strdup(item);
|
||||||
ac->items = g_list_prepend(ac->items, item_cpy);
|
|
||||||
|
if (is_reversed) {
|
||||||
|
ac->items = g_list_prepend(ac->items, item_cpy);
|
||||||
|
} else {
|
||||||
|
ac->items = g_list_append(ac->items, item_cpy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ void autocomplete_add_all(Autocomplete ac, char** items);
|
|||||||
void autocomplete_update(Autocomplete ac, char** items);
|
void autocomplete_update(Autocomplete ac, char** items);
|
||||||
void autocomplete_remove(Autocomplete ac, const char* const item);
|
void autocomplete_remove(Autocomplete ac, const char* const item);
|
||||||
void autocomplete_remove_all(Autocomplete ac, char** items);
|
void autocomplete_remove_all(Autocomplete ac, char** items);
|
||||||
void autocomplete_add_reverse(Autocomplete ac, const char* item);
|
void autocomplete_add_unsorted(Autocomplete ac, const char* item, const gboolean is_reversed);
|
||||||
|
|
||||||
// find the next item prefixed with search string
|
// find the next item prefixed with search string
|
||||||
gchar* autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote, gboolean previous);
|
gchar* autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote, gboolean previous);
|
||||||
|
@ -380,11 +380,13 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
|
|||||||
win_print_incoming(window, display_name, message);
|
win_print_incoming(window, display_name, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
wins_add_urls_ac(window, message);
|
if (!message->is_mam) {
|
||||||
wins_add_quotes_ac(window, message->plain);
|
wins_add_urls_ac(window, message, FALSE);
|
||||||
|
wins_add_quotes_ac(window, message->plain, FALSE);
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_BEEP) && !message->is_mam) {
|
if (prefs_get_boolean(PREF_BEEP)) {
|
||||||
beep();
|
beep();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notify) {
|
if (notify) {
|
||||||
@ -406,7 +408,7 @@ chatwin_outgoing_msg(ProfChatWin* chatwin, const char* const message, char* id,
|
|||||||
assert(chatwin != NULL);
|
assert(chatwin != NULL);
|
||||||
|
|
||||||
ProfWin* window = (ProfWin*)chatwin;
|
ProfWin* window = (ProfWin*)chatwin;
|
||||||
wins_add_quotes_ac(window, message);
|
wins_add_quotes_ac(window, message, FALSE);
|
||||||
|
|
||||||
char* enc_char;
|
char* enc_char;
|
||||||
if (chatwin->outgoing_char) {
|
if (chatwin->outgoing_char) {
|
||||||
|
@ -542,7 +542,7 @@ mucwin_outgoing_msg(ProfMucWin* mucwin, const char* const message, const char* c
|
|||||||
_mucwin_set_last_message(mucwin, id, message);
|
_mucwin_set_last_message(mucwin, id, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
wins_add_quotes_ac(window, message);
|
wins_add_quotes_ac(window, message, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -582,8 +582,8 @@ mucwin_incoming_msg(ProfMucWin* mucwin, const ProfMessage* const message, GSList
|
|||||||
}
|
}
|
||||||
|
|
||||||
win_insert_last_read_position_marker((ProfWin*)mucwin, mucwin->roomjid);
|
win_insert_last_read_position_marker((ProfWin*)mucwin, mucwin->roomjid);
|
||||||
wins_add_urls_ac(window, message);
|
wins_add_urls_ac(window, message, FALSE);
|
||||||
wins_add_quotes_ac(window, message->plain);
|
wins_add_quotes_ac(window, message->plain, FALSE);
|
||||||
|
|
||||||
if (g_slist_length(mentions) > 0) {
|
if (g_slist_length(mentions) > 0) {
|
||||||
_mucwin_print_mention(window, message->plain, message->from_jid->resourcepart, mynick, mentions, ch, flags);
|
_mucwin_print_mention(window, message->plain, message->from_jid->resourcepart, mynick, mentions, ch, flags);
|
||||||
|
@ -87,8 +87,8 @@ privwin_incoming_msg(ProfPrivateWin* privatewin, ProfMessage* message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wins_add_urls_ac(window, message);
|
wins_add_urls_ac(window, message, FALSE);
|
||||||
wins_add_quotes_ac(window, message->plain);
|
wins_add_quotes_ac(window, message->plain, TRUE);
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_BEEP)) {
|
if (prefs_get_boolean(PREF_BEEP)) {
|
||||||
beep();
|
beep();
|
||||||
@ -107,7 +107,7 @@ privwin_outgoing_msg(ProfPrivateWin* privwin, const char* const message)
|
|||||||
assert(privwin != NULL);
|
assert(privwin != NULL);
|
||||||
|
|
||||||
ProfWin* window = (ProfWin*)privwin;
|
ProfWin* window = (ProfWin*)privwin;
|
||||||
wins_add_quotes_ac(window, message);
|
wins_add_quotes_ac(window, message, FALSE);
|
||||||
win_print_outgoing((ProfWin*)privwin, "-", NULL, NULL, message);
|
win_print_outgoing((ProfWin*)privwin, "-", NULL, NULL, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "ui/window_list.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -1498,6 +1499,8 @@ win_print_history(ProfWin* window, const ProfMessage* const message)
|
|||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
|
|
||||||
buffer_append(window->layout->buffer, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
|
buffer_append(window->layout->buffer, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
|
||||||
|
wins_add_urls_ac(window, message, FALSE);
|
||||||
|
wins_add_quotes_ac(window, message->plain, FALSE);
|
||||||
_win_print_internal(window, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, message->plain, NULL);
|
_win_print_internal(window, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, message->plain, NULL);
|
||||||
|
|
||||||
free(display_name);
|
free(display_name);
|
||||||
@ -1526,6 +1529,8 @@ win_print_old_history(ProfWin* window, const ProfMessage* const message)
|
|||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
|
|
||||||
buffer_prepend(window->layout->buffer, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
|
buffer_prepend(window->layout->buffer, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
|
||||||
|
wins_add_urls_ac(window, message, TRUE);
|
||||||
|
wins_add_quotes_ac(window, message->plain, TRUE);
|
||||||
_win_print_internal(window, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, message->plain, NULL);
|
_win_print_internal(window, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, message->plain, NULL);
|
||||||
|
|
||||||
free(display_name);
|
free(display_name);
|
||||||
|
@ -1315,7 +1315,7 @@ wins_get_next_attention(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message)
|
wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message, const gboolean flip)
|
||||||
{
|
{
|
||||||
GRegex* regex;
|
GRegex* regex;
|
||||||
GMatchInfo* match_info;
|
GMatchInfo* match_info;
|
||||||
@ -1326,7 +1326,11 @@ wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message)
|
|||||||
while (g_match_info_matches(match_info)) {
|
while (g_match_info_matches(match_info)) {
|
||||||
gchar* word = g_match_info_fetch(match_info, 0);
|
gchar* word = g_match_info_fetch(match_info, 0);
|
||||||
|
|
||||||
autocomplete_add_reverse(win->urls_ac, word);
|
if (flip) {
|
||||||
|
autocomplete_add_unsorted(win->urls_ac, word, FALSE);
|
||||||
|
} else {
|
||||||
|
autocomplete_add_unsorted(win->urls_ac, word, TRUE);
|
||||||
|
}
|
||||||
// for people who run profanity a long time, we don't want to waste a lot of memory
|
// for people who run profanity a long time, we don't want to waste a lot of memory
|
||||||
autocomplete_remove_older_than_max_reverse(win->urls_ac, 20);
|
autocomplete_remove_older_than_max_reverse(win->urls_ac, 20);
|
||||||
|
|
||||||
@ -1339,9 +1343,14 @@ wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wins_add_quotes_ac(const ProfWin* const win, const char* const message)
|
wins_add_quotes_ac(const ProfWin* const win, const char* const message, const gboolean flip)
|
||||||
{
|
{
|
||||||
autocomplete_add_reverse(win->quotes_ac, message);
|
if (flip) {
|
||||||
|
autocomplete_add_unsorted(win->quotes_ac, message, FALSE);
|
||||||
|
} else {
|
||||||
|
autocomplete_add_unsorted(win->quotes_ac, message, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
// for people who run profanity a long time, we don't want to waste a lot of memory
|
// for people who run profanity a long time, we don't want to waste a lot of memory
|
||||||
autocomplete_remove_older_than_max_reverse(win->quotes_ac, 20);
|
autocomplete_remove_older_than_max_reverse(win->quotes_ac, 20);
|
||||||
}
|
}
|
||||||
|
@ -102,9 +102,9 @@ void win_reset_search_attempts(void);
|
|||||||
char* win_close_autocomplete(const char* const search_str, gboolean previous, void* context);
|
char* win_close_autocomplete(const char* const search_str, gboolean previous, void* context);
|
||||||
void win_close_reset_search_attempts(void);
|
void win_close_reset_search_attempts(void);
|
||||||
|
|
||||||
void wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message);
|
void wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message, const gboolean flip);
|
||||||
char* wins_get_url(const char* const search_str, gboolean previous, void* context);
|
char* wins_get_url(const char* const search_str, gboolean previous, void* context);
|
||||||
void wins_add_quotes_ac(const ProfWin* const win, const char* const message);
|
void wins_add_quotes_ac(const ProfWin* const win, const char* const message, const gboolean flip);
|
||||||
char* wins_get_quote(const char* const search_str, gboolean previous, void* context);
|
char* wins_get_quote(const char* const search_str, gboolean previous, void* context);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user