spellcheck.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. diff -r 7c0c3c912f80 modules/pgsc_spellcheck.py
  2. --- a/modules/pgsc_spellcheck.py Mon May 26 23:18:46 2014 +0200
  3. +++ b/modules/pgsc_spellcheck.py Tue May 27 12:03:10 2014 -0400
  4. @@ -42,6 +42,40 @@
  5. # public objects
  6. __all__ = ['SpellChecker', 'NoDictionariesFound', 'NoGtkBindingFound']
  7. +# apostrophe workaround from gtkspell3
  8. +def gtk_spell_forward_word_end(i):
  9. +
  10. + # heuristic:
  11. + # if we're on an singlequote/apostrophe and
  12. + # if the next letter is alphanumeric,
  13. + # this is an apostrophe (either single quote, or U+2019 = 8217.
  14. +
  15. + if not i.forward_word_end():
  16. + return False
  17. +
  18. + if i.get_char() != '\'' and \
  19. + i.get_char() != 8217:
  20. + return True
  21. +
  22. + it = i.copy()
  23. + if it.forward_char() and \
  24. + it.get_char().isalpha():
  25. + return i.forward_word_end()
  26. +
  27. + return True
  28. +
  29. +def gtk_spell_backward_word_start(i):
  30. + if not i.backward_word_start():
  31. + return False
  32. +
  33. + it = i.copy()
  34. + if it.get_char().isalpha() and \
  35. + it.backward_char() and \
  36. + (it.get_char() == '\'' or \
  37. + it.get_char() == 8217):
  38. + return i.backward_word_start()
  39. +
  40. + return True
  41. class NoDictionariesFound(Exception):
  42. """
  43. @@ -132,10 +166,10 @@
  44. def word(self):
  45. start = self.iter
  46. if not start.starts_word():
  47. - start.backward_word_start()
  48. + gtk_spell_backward_word_start(start)
  49. end = self.iter
  50. if end.inside_word():
  51. - end.forward_word_end()
  52. + gtk_spell_forward_word_end(end)
  53. return start, end
  54. def move(self, location):
  55. @@ -361,21 +395,21 @@
  56. return
  57. if start.equal(end):
  58. return
  59. - if end.inside_word(): end.forward_word_end()
  60. + if end.inside_word(): gtk_spell_forward_word_end(end)
  61. if not start.starts_word() and (start.inside_word() or start.ends_word()):
  62. - start.backward_word_start()
  63. + gtk_spell_backward_word_start(start)
  64. self._buffer.remove_tag(self._misspelled, start, end)
  65. cursor = self._buffer.get_iter_at_mark(self._buffer.get_insert())
  66. precursor = cursor.copy()
  67. precursor.backward_char()
  68. highlight = (cursor.has_tag(self._misspelled) or precursor.has_tag(self._misspelled))
  69. if not start.get_offset():
  70. - start.forward_word_end()
  71. - start.backward_word_start()
  72. + gtk_spell_forward_word_end(start)
  73. + gtk_spell_backward_word_start(start)
  74. word_start = start.copy()
  75. while word_start.compare(end) < 0:
  76. word_end = word_start.copy()
  77. - word_end.forward_word_end()
  78. + gtk_spell_forward_word_end(word_end)
  79. in_word = ((word_start.compare(cursor) < 0) and
  80. (cursor.compare(word_end) <= 0))
  81. if in_word and not force_all:
  82. @@ -386,8 +420,8 @@
  83. else:
  84. self._check_word(word_start, word_end)
  85. self._deferred_check = False
  86. - word_end.forward_word_end()
  87. - word_end.backward_word_start()
  88. + gtk_spell_forward_word_end(word_end)
  89. + gtk_spell_backward_word_start(word_end)
  90. if word_start.equal(word_end):
  91. break
  92. word_start = word_end.copy()