0
我正在爲Gedit編寫插件,它根據正則表達式對某些詞進行更改。在某些情況下,這是將標籤應用於超出預期單詞的幾個字符。Gtk TextBuffer get_iter_at_offset
所以match.start()和match.end()返回的值在get_iter_at_offset中無效。
def on_save(self, doc, location, *args, **kwargs):
"""called when document is saved"""
for match in WORD_RE.finditer(get_text(doc)):
if not self._checker.check(match.group().strip()):
self.apply_tag(doc, match.start(), match.end())
def apply_tag(self, doc, start, end):
"""apply the tag to the text between start and end"""
istart = doc.get_iter_at_offset(start)
iend = doc.get_iter_at_offset(end)
doc.apply_tag(self._spell_error_tag, istart, iend)