allow swapping dict at runtime
This commit is contained in:
parent
fdb630555d
commit
2d71c541c6
@ -1004,11 +1004,14 @@ class WordHinter:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
# will be initialized on first use.
|
# will be initialized on first use.
|
||||||
self.words = set()
|
self.words = set()
|
||||||
|
self.dictionary = None
|
||||||
|
|
||||||
def ensure_initialized(self):
|
def ensure_initialized(self):
|
||||||
"""Generate the used words if yet uninialized."""
|
"""Generate the used words if yet uninialized."""
|
||||||
if not self.words:
|
dictionary = config.get("hints", "dictionary")
|
||||||
dictionary = config.get("hints", "dictionary")
|
if not self.words or self.dictionary != dictionary:
|
||||||
|
self.words.clear()
|
||||||
|
self.dictionary = dictionary
|
||||||
try:
|
try:
|
||||||
with open(dictionary, encoding="UTF-8") as wordfile:
|
with open(dictionary, encoding="UTF-8") as wordfile:
|
||||||
alphabet = set(string.ascii_lowercase)
|
alphabet = set(string.ascii_lowercase)
|
||||||
@ -1104,3 +1107,4 @@ class WordHinter:
|
|||||||
used_hints.add(hint)
|
used_hints.add(hint)
|
||||||
hints.append(hint)
|
hints.append(hint)
|
||||||
return hints
|
return hints
|
||||||
|
|
||||||
|
@ -62,21 +62,21 @@ def test_hints(test_name, quteproc):
|
|||||||
def test_word_hints_issue1393(quteproc, tmpdir):
|
def test_word_hints_issue1393(quteproc, tmpdir):
|
||||||
dict_file = tmpdir / 'dict'
|
dict_file = tmpdir / 'dict'
|
||||||
dict_file.write(textwrap.dedent("""
|
dict_file.write(textwrap.dedent("""
|
||||||
alpha
|
alph
|
||||||
beta
|
beta
|
||||||
gamma
|
gamm
|
||||||
delta
|
delt
|
||||||
epsilon
|
epsi
|
||||||
"""))
|
"""))
|
||||||
targets = [
|
targets = [
|
||||||
('words', 'words.txt'),
|
('words', 'words.txt'),
|
||||||
('smart', 'smart.txt'),
|
('smart', 'smart.txt'),
|
||||||
('hinting', 'hinting.txt'),
|
('hinting', 'hinting.txt'),
|
||||||
('alpha', 'l33t.txt'),
|
('alph', 'l33t.txt'),
|
||||||
('beta', 'l33t.txt'),
|
('beta', 'l33t.txt'),
|
||||||
('gamma', 'l33t.txt'),
|
('gamm', 'l33t.txt'),
|
||||||
('delta', 'l33t.txt'),
|
('delt', 'l33t.txt'),
|
||||||
('epsilon', 'l33t.txt'),
|
('epsi', 'l33t.txt'),
|
||||||
]
|
]
|
||||||
|
|
||||||
quteproc.set_setting('hints', 'mode', 'word')
|
quteproc.set_setting('hints', 'mode', 'word')
|
||||||
|
Loading…
Reference in New Issue
Block a user