Merge branch '383_editor_autocomplete'
* 383_editor_autocomplete: Ticket #383 (Autocompletion in editor don't work) Autocomplete in editor now works with all words, not only a-zA-Z Fixed autocompletion in editor
Этот коммит содержится в:
Коммит
a93e6a60b5
@ -2234,7 +2234,7 @@ static int edit_find_word_start (WEdit *edit, long *word_start, int *word_len)
|
|||||||
|
|
||||||
c = (unsigned char) edit_get_byte (edit, edit->curs1 - 1);
|
c = (unsigned char) edit_get_byte (edit, edit->curs1 - 1);
|
||||||
/* return if not at end or in word */
|
/* return if not at end or in word */
|
||||||
if (isspace (c) || !(isalnum (c) || c == '_'))
|
if (isspace (c) || c == '_')
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* search start of word to be completed */
|
/* search start of word to be completed */
|
||||||
@ -2246,7 +2246,7 @@ static int edit_find_word_start (WEdit *edit, long *word_start, int *word_len)
|
|||||||
last = c;
|
last = c;
|
||||||
c = (unsigned char) edit_get_byte (edit, edit->curs1 - i);
|
c = (unsigned char) edit_get_byte (edit, edit->curs1 - i);
|
||||||
|
|
||||||
if (!(isalnum (c) || c == '_')) {
|
if (isspace (c) || c == '_') {
|
||||||
/* return if word starts with digit */
|
/* return if word starts with digit */
|
||||||
if (isdigit (last))
|
if (isdigit (last))
|
||||||
return 0;
|
return 0;
|
||||||
@ -2260,16 +2260,6 @@ static int edit_find_word_start (WEdit *edit, long *word_start, int *word_len)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (re)set search parameters to the given values */
|
|
||||||
static void edit_set_search_parameters (WEdit *edit, int replace_mode, int rb, int rc)
|
|
||||||
{
|
|
||||||
edit->replace_mode = replace_mode;
|
|
||||||
edit->replace_backwards = rb;
|
|
||||||
edit->replace_case = rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_WORD_COMPLETIONS 100 /* in listbox */
|
#define MAX_WORD_COMPLETIONS 100 /* in listbox */
|
||||||
|
|
||||||
/* collect the possible completions */
|
/* collect the possible completions */
|
||||||
@ -2278,52 +2268,64 @@ edit_collect_completions (WEdit *edit, long start, int word_len,
|
|||||||
char *match_expr, struct selection *compl,
|
char *match_expr, struct selection *compl,
|
||||||
int *num)
|
int *num)
|
||||||
{
|
{
|
||||||
int len = 0, max_len = 0, i, skip;
|
int max_len = 0, i, skip;
|
||||||
unsigned char *bufpos;
|
gsize len = 0;
|
||||||
|
GString *temp;
|
||||||
|
mc_search_t *srch;
|
||||||
|
|
||||||
|
srch = mc_search_new(match_expr, -1);
|
||||||
|
if (srch == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
srch->search_type = MC_SEARCH_T_REGEX;
|
||||||
|
srch->is_case_sentitive = TRUE;
|
||||||
|
srch->search_fn = edit_search_cmd_callback;
|
||||||
|
|
||||||
(void) match_expr;
|
|
||||||
/* collect max MAX_WORD_COMPLETIONS completions */
|
/* collect max MAX_WORD_COMPLETIONS completions */
|
||||||
|
start--;
|
||||||
while (*num < MAX_WORD_COMPLETIONS) {
|
while (*num < MAX_WORD_COMPLETIONS) {
|
||||||
/* get next match */
|
/* get next match */
|
||||||
/*
|
if (mc_search_run (srch, (void *) edit, start+1, edit->last_byte, &len) == FALSE)
|
||||||
start =
|
|
||||||
edit_find (start - 1, (unsigned char *) match_expr, &len,
|
|
||||||
edit->last_byte, edit_get_byte_ptr, (void *) edit, 0);
|
|
||||||
*/
|
|
||||||
start = -1;
|
|
||||||
/* not matched */
|
|
||||||
if (start < 0)
|
|
||||||
break;
|
break;
|
||||||
|
start = srch->normal_offset;
|
||||||
|
|
||||||
/* add matched completion if not yet added */
|
/* add matched completion if not yet added */
|
||||||
bufpos =
|
temp = g_string_new("");
|
||||||
&edit->
|
for (i = 0; i < len; i++){
|
||||||
buffers1[start >> S_EDIT_BUF_SIZE][start & M_EDIT_BUF_SIZE];
|
skip = edit_get_byte(edit, start+i);
|
||||||
|
if (isspace(skip))
|
||||||
|
continue;
|
||||||
|
g_string_append_c (temp, skip);
|
||||||
|
}
|
||||||
|
|
||||||
skip = 0;
|
skip = 0;
|
||||||
|
|
||||||
for (i = 0; i < *num; i++) {
|
for (i = 0; i < *num; i++) {
|
||||||
if (strncmp
|
if (strncmp
|
||||||
((char *) &compl[i].text[word_len],
|
(
|
||||||
(char *) &bufpos[word_len], max (len,
|
(char *) &compl[i].text[word_len],
|
||||||
compl[i].len) -
|
(char *) &temp->str[word_len],
|
||||||
word_len) == 0) {
|
max (len, compl[i].len) - word_len
|
||||||
|
) == 0) {
|
||||||
skip = 1;
|
skip = 1;
|
||||||
break; /* skip it, already added */
|
break; /* skip it, already added */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (skip)
|
if (skip) {
|
||||||
|
g_string_free(temp, TRUE);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
compl[*num].text = g_malloc (len + 1);
|
compl[*num].text = temp->str;
|
||||||
compl[*num].len = len;
|
compl[*num].len = temp->len;
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
compl[*num].text[i] = *(bufpos + i);
|
|
||||||
compl[*num].text[i] = '\0';
|
|
||||||
(*num)++;
|
(*num)++;
|
||||||
|
g_string_free(temp, FALSE);
|
||||||
|
|
||||||
/* note the maximal length needed for the completion dialog */
|
/* note the maximal length needed for the completion dialog */
|
||||||
if (len > max_len)
|
if (len > max_len)
|
||||||
max_len = len;
|
max_len = len;
|
||||||
}
|
}
|
||||||
|
mc_search_free(srch);
|
||||||
return max_len;
|
return max_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2340,11 +2342,6 @@ edit_complete_word_cmd (WEdit *edit)
|
|||||||
char *match_expr;
|
char *match_expr;
|
||||||
struct selection compl[MAX_WORD_COMPLETIONS]; /* completions */
|
struct selection compl[MAX_WORD_COMPLETIONS]; /* completions */
|
||||||
|
|
||||||
/* don't want to disturb another search */
|
|
||||||
int old_replace_mode = edit->replace_mode;
|
|
||||||
int old_rb = edit->replace_backwards;
|
|
||||||
int old_rc = edit->replace_case;
|
|
||||||
|
|
||||||
/* search start of word to be completed */
|
/* search start of word to be completed */
|
||||||
if (!edit_find_word_start (edit, &word_start, &word_len))
|
if (!edit_find_word_start (edit, &word_start, &word_len))
|
||||||
return;
|
return;
|
||||||
@ -2353,14 +2350,12 @@ edit_complete_word_cmd (WEdit *edit)
|
|||||||
bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE]
|
bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE]
|
||||||
[word_start & M_EDIT_BUF_SIZE];
|
[word_start & M_EDIT_BUF_SIZE];
|
||||||
|
|
||||||
match_expr = g_strdup_printf ("%.*s[a-zA-Z_0-9]+", word_len, bufpos);
|
match_expr = g_strdup_printf ("(^|\\s)%.*s[^\\s\\.=\\+\\{\\}\\[\\]\\(\\)\\\\\\!\\,<>\\?\\/@#\\$%\\^&\\*\\~\\|\\\"'\\:\\;]+", word_len, bufpos);
|
||||||
/* init search: backward, regexp, whole word, case sensitive */
|
|
||||||
edit_set_search_parameters (edit, 0, 1, 1);
|
|
||||||
|
|
||||||
/* collect the possible completions */
|
/* collect the possible completions */
|
||||||
/* start search from curs1 down to begin of file */
|
/* start search from begin to end of file */
|
||||||
max_len =
|
max_len =
|
||||||
edit_collect_completions (edit, word_start, word_len, match_expr,
|
edit_collect_completions (edit, 0, word_len, match_expr,
|
||||||
(struct selection *) &compl, &num_compl);
|
(struct selection *) &compl, &num_compl);
|
||||||
|
|
||||||
if (num_compl > 0) {
|
if (num_compl > 0) {
|
||||||
@ -2388,8 +2383,6 @@ edit_complete_word_cmd (WEdit *edit)
|
|||||||
for (i = 0; i < num_compl; i++)
|
for (i = 0; i < num_compl; i++)
|
||||||
g_free (compl[i].text);
|
g_free (compl[i].text);
|
||||||
|
|
||||||
/* restore search parameters */
|
|
||||||
edit_set_search_parameters (edit, old_replace_mode, old_rb, old_rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user