Fix spell with new config

This commit is contained in:
Michal Siedlaczek 2017-09-21 12:09:55 -04:00
parent 132b1f705e
commit 9e620ce6e9
4 changed files with 24 additions and 10 deletions

View File

@ -18,7 +18,7 @@ include tox.ini
include qutebrowser.py
include misc/cheatsheet.svg
include qutebrowser/config/configdata.yml
include misc/lang_list
include qutebrowser/browser/webengine/langs.tsv
prune www
prune scripts/dev

View File

@ -27,9 +27,9 @@ Module attributes:
constants.
"""
import os
import ctypes
import ctypes.util
import os
from PyQt5.QtGui import QFont
from PyQt5.QtWebEngineWidgets import (QWebEngineSettings, QWebEngineProfile,
@ -38,8 +38,7 @@ from PyQt5.QtWebEngineWidgets import (QWebEngineSettings, QWebEngineProfile,
from qutebrowser.browser import shared
from qutebrowser.browser.webengine.spell import get_installed_languages
from qutebrowser.config import config, websettings
from qutebrowser.utils import utils, standarddir, javascript, qtutils
from qutebrowser.utils import utils, standarddir, javascript, qtutils, message
# The default QWebEngineProfile
default_profile = None
@ -133,8 +132,7 @@ class DictionaryLanguageSetter(DefaultProfileSetter):
"""Sets paths to dictionary files based on language codes."""
def __init__(self):
super().__init__('setSpellCheckLanguages', default=[],
min_version='5.8')
super().__init__('setSpellCheckLanguages', default=[])
def _set(self, value, settings=None):
if settings is not None:
@ -326,7 +324,7 @@ MAPPINGS = {
Attribute(QWebEngineSettings.ScrollAnimatorEnabled),
'spell': DefaultProfileSetter('setSpellCheckEnabled'),
'spell-languages': DictionaryLanguageSetter()
'spell_languages': DictionaryLanguageSetter()
}
try:

View File

@ -975,6 +975,21 @@ scrolling.smooth:
Note smooth scrolling does not work with the `:scroll-px` command.
## spell
spell:
type: Bool
default: true
desc: Enable spell checking.
spell_languages:
type:
name: List
valtype: String
none_ok: true
default:
desc: Spell checking languages.
## statusbar
statusbar.hide:

View File

@ -47,8 +47,9 @@ def test_get_installed_languages_non_empty(tmpdir, mocker):
mocker.patch('qutebrowser.browser.webengine.spell.get_dictionary_dir',
lambda: str(tmpdir))
for lang in LANGUAGE_LIST:
open(join(tmpdir, lang.file), 'w').close()
for actual, expected in zip(spell.get_installed_languages(), LANGUAGE_LIST):
open(join(tmpdir, lang.file), 'w', encoding='UTF-8').close()
for actual, expected in zip(spell.get_installed_languages(),
LANGUAGE_LIST):
assert (actual.code, actual.name, actual.file) ==\
(expected.code, expected.name, expected.file)
@ -79,7 +80,7 @@ def test_install(tmpdir, mocker):
mocker.patch('qutebrowser.browser.webengine.spell.get_dictionary_dir',
lambda: str(tmpdir))
mocker.patch('qutebrowser.browser.webengine.spell.download_dictionary',
lambda url, dest: open(dest, 'w').close())
lambda url, dest: open(dest, 'w', encoding='UTF-8').close())
spell.install(LANGUAGE_LIST)
installed_files = [basename(str(file)) for file in tmpdir.listdir()]
expected_files = [lang.file for lang in LANGUAGE_LIST]