Skip to content

Commit 9bd6bc1

Browse files
authored
Merge pull request #1495 from b4n/spellcheck-whitespaces
spellcheck: Fix wordchars restoration
2 parents cfb3f5d + d58aca5 commit 9bd6bc1

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

spellcheck/src/speller.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,28 @@ static gint sc_speller_check_word(GeanyDocument *doc, gint line_number, const gc
198198
}
199199

200200

201+
static gchar *get_chars(ScintillaObject *sci, unsigned int message, gint extra_alloc, gint *out_len)
202+
{
203+
gint len = scintilla_send_message(sci, message, 0, 0);
204+
gchar *chars = g_malloc0(len + 1 + extra_alloc);
205+
206+
scintilla_send_message(sci, message, 0, (sptr_t)chars);
207+
if (out_len)
208+
*out_len = len;
209+
210+
return chars;
211+
}
212+
213+
201214
gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
202215
{
203216
gint pos_start, pos_end;
204217
gint wstart, wend;
205218
gint suggestions_found = 0;
206219
gint wordchars_len;
207220
gchar *wordchars;
221+
gchar *whitespaces;
222+
gchar *punctuations;
208223
gchar *underscore_in_wordchars = NULL;
209224
gboolean wordchars_modified = FALSE;
210225

@@ -216,9 +231,10 @@ gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
216231

217232
/* add ' (single quote) temporarily to wordchars
218233
* to be able to check for "doesn't", "isn't" and similar */
219-
wordchars_len = scintilla_send_message(doc->editor->sci, SCI_GETWORDCHARS, 0, 0);
220-
wordchars = g_malloc0(wordchars_len + 2); /* 2 = temporarily added "'" and "\0" */
221-
scintilla_send_message(doc->editor->sci, SCI_GETWORDCHARS, 0, (sptr_t)wordchars);
234+
/* +1 to allocation to allow for temporarily added "'" */
235+
wordchars = get_chars(doc->editor->sci, SCI_GETWORDCHARS, 1, &wordchars_len);
236+
whitespaces = get_chars(doc->editor->sci, SCI_GETWHITESPACECHARS, 0, NULL);
237+
punctuations = get_chars(doc->editor->sci, SCI_GETPUNCTUATIONCHARS, 0, NULL);
222238
if (! strchr(wordchars, '\''))
223239
{
224240
/* temporarily add "'" to the wordchars */
@@ -267,8 +283,12 @@ gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
267283
/* reset wordchars for the current document */
268284
wordchars[wordchars_len] = '\0';
269285
scintilla_send_message(doc->editor->sci, SCI_SETWORDCHARS, 0, (sptr_t)wordchars);
286+
scintilla_send_message(doc->editor->sci, SCI_SETWHITESPACECHARS, 0, (sptr_t)whitespaces);
287+
scintilla_send_message(doc->editor->sci, SCI_SETPUNCTUATIONCHARS, 0, (sptr_t)punctuations);
270288
}
271289
g_free(wordchars);
290+
g_free(whitespaces);
291+
g_free(punctuations);
272292
return suggestions_found;
273293
}
274294

0 commit comments

Comments
 (0)