Commit Graph

4366 Commits

Author SHA1 Message Date
Ryan Roden-Corrent
66cc5f5ea4
Add support for more values in QtColor config type.
Recent changes in the completion highlighter mandate that
config.val.colors.completion.match be changed from a QssColor to a
QtColor. However, the latter accepts fewer formats. To avoid breaking
configs, this allows QtColors to be specified using all the same formats
as QssColors, excluding gradients.

I separated the QssColor and QtColor tests as the previous approach of
generating the tests made adding tests for QtColor more complicated.

While working on this I discovered that Qt's css parser is potentially
broken around parsing hsv percentages and filed
https://bugreports.qt.io/browse/QTBUG-70897.

For consistency, I made our parser similarly broken.

You can show the bug in qutebrowser right now by noting that the
following have different effects:

```
set colors.completion.odd.bg 'hsv(100%, 100%, 100%)'
set colors.completion.odd.bg 'hsv(358, 255, 255)'
```
2018-10-02 17:30:43 -04:00
Ryan Roden-Corrent
0fed563a02
Use QSyntaxHighlighter for completion.
This is a more "Qt" way of highlighting syntax, and works around the
problems of #4199 without resorting to complicated html escaping.

The tests are more straightforward with less mocking, but do involve
testing a private class.
2018-09-22 12:13:28 -04:00
Ryan Roden-Corrent
2eacf4bd94
Clean up completiondelegate tests.
Respond to code review comments to reduce mocking and clean up comments.
2018-09-18 20:40:06 -04:00
Ryan Roden-Corrent
4f733333c3
Remove unused imports in test_completiondelegate. 2018-09-15 14:45:18 -04:00
Ryan Roden-Corrent
102c6b99dd
Don't highlight html escapes in completion.
Resolves #4199.

To avoid accidentally highlighting characters that were introduced by
html escaping the text before feeding it to setHtml, we can't just
escape the whole string before adding the highlighting. Instead, we need
to break the string up on the pattern, format and escape the individual
parts, then join them back together.

re.escape includes empty strings if there is a match at the start/end,
which ensures that matches always land on odd indices:

https://docs.python.org/3/library/re.html#re.split

> If there are capturing groups in the separator and it matches at the
> start of the string, the result will start with an empty string. The
> same holds for the end of the string
2018-09-15 14:06:28 -04:00
Ryan Roden-Corrent
4f99af5876
Don't escape quotes in completion text.
Resolves the example case in #4199, but not the larger problem. We don't
need to escape quotes as we don't put the string in an attribute value.
From the docs at
https://docs.python.org/3/library/html.html#html.escape:

> If the optional flag quote is true, the characters (") and (') are also
> translated; this helps for inclusion in an HTML attribute value
> delimited by quotes, as in <a href="...">.

Escaping quotes means we end up with a literal &#x27; in the completion
view wherever there is a quote in the source text.

However, problem in #4199, where unexpected parts of the text are
highlighted, can also happen with '<', '>', and '&', which still must be
escaped.
2018-09-15 13:39:49 -04:00
Ryan Roden-Corrent
28c8e5682a
Unit test CompletionItemDelegate.paint.
There were no unit tests for this whole module. It is difficult to test
due to all the private logic and Qt dependencies, but with a lot of
mocking we can at least validate some of the text handling.

This is a setup to start testing the solution to #4199.

I picked '{' and '}' as placeholders in the test data because they draw
the eye to the 'highlighted' part, and vim even highlights them with
python syntax highlighting. It could be confusing though, as they look
like format strings but are not used that way.
2018-09-15 13:34:07 -04:00
Florian Bruhin
f9327731b8 Handle UTF-8 byte order marks in Greasemonkey scripts
See e.g. https://github.com/jerone/UserScripts/issues/135
2018-09-12 23:54:32 +02:00
Florian Bruhin
91b8002dd5 Clean up workaround for sqlite opening errors
Now that we know the real cause, we can be a bit stricter with our workaround.
2018-09-12 16:06:57 +02:00
Florian Bruhin
c2a072f9fe Fix handling of sqlite out of memory errors
The "error_code == -1" check never passed, as error_code (confusingly) is a
string of a number.
2018-09-12 01:36:50 +02:00
Florian Bruhin
d80d9eb26c Allow downloading from PDF.js
When we click the download button in PDF.js, it downloads a blob://qute:...
URL. We can detect that and force a download rather than opening it in PDF.js
again.

Note that what actually happens depends on the Qt version and backend:

QtWebKit (any Qt version):
Downloads always work properly (regardless of Qt version).

QtWebEngine, Qt 5.7.1:
Downloads work.

QtWebEngine, Qt 5.9 - 5.11:
Downloads won't work as we need to tell PDF.js to not use blob: URLs:
https://bugreports.qt.io/browse/QTBUG-70420 - in theory, PDF.js could fall back
to downloading the existing qute:// URL, but it has a whitelist of schemes
which does not include qute://... Since it's not in that whitelist, it just
ends up doing nothing at all.

QtWebEngine, Qt 5.12:
Downloads should hopefully work properly again, as we can register the qute://
scheme with Chromium, which allows us to use blob:// URLs.
2018-09-10 13:15:39 +02:00
Florian Bruhin
02641b86fc Don't tell PDF.js to disable createObjectURL on Qt 5.7.1
Looks like things actually work fine there...
2018-09-10 13:01:01 +02:00
Florian Bruhin
bb96f8d297 Fix PDF.js test when no PDF.js is installed 2018-09-10 09:36:29 +02:00
Florian Bruhin
9b04c4b8e0 Add missing tests for qute://pdfjs 2018-09-09 19:22:39 +02:00
Florian Bruhin
b4077a8543 Fix lint 2018-09-09 18:39:22 +02:00
Florian Bruhin
b96898db37 Simplify and lock down PDF.js filename handling 2018-09-09 18:35:09 +02:00
Florian Bruhin
8cfa46f539 100% test coverage for browser.pdfjs 2018-09-09 18:35:09 +02:00
Florian Bruhin
3e25262437 Remove old backend patching 2018-09-09 18:35:09 +02:00
Florian Bruhin
490fe5e1a3 Add utils.guess_mimetype 2018-09-09 18:35:09 +02:00
Florian Bruhin
24148c649e Fix lint and tests 2018-09-09 18:35:09 +02:00
Florian Bruhin
3ad7ae2a2c Remove fix_urls which isn't needed anymore
With qute://pdfjs/web/viewer.html we can use relative URLs
2018-09-09 18:35:09 +02:00
Florian Bruhin
bbcb87e434 Get PDF.js to work
We need to use the /web/viewer.html path so relative references are correct.
2018-09-09 18:35:09 +02:00
Florian Bruhin
7206dde19c Revert "Simplify getting pdfjs main page"
This reverts commit 9c731bde85627308fdde4730b0181a014096cb47.

We need to set some PDF.js options, so we can't just use the default viewer
with ?file=...
2018-09-09 18:35:09 +02:00
Florian Bruhin
8f19820a7a Remove pdfjs.fix_urls
Now that we use qute://pdfjs to show the viewer, we don't need to rewrite any
URLs.
2018-09-09 18:35:09 +02:00
Florian Bruhin
24fb3b0d1b Simplify getting pdfjs main page 2018-09-09 18:35:09 +02:00
Florian Bruhin
dc82ac3eb2 Move qute_pdfjs to qutescheme.py 2018-09-09 18:35:09 +02:00
Florian Bruhin
4ca8fc0cb7 Use a shared web_history fixture 2018-09-06 20:08:32 +02:00
Florian Bruhin
ab6c8dde9a Decrease minimum QProgressDialog duration
We already have a threshold before we use a QProgressDialog at all, so let's
show it quite quickly and not after 4 seconds.
2018-09-06 17:26:28 +02:00
Florian Bruhin
935d93d10e Add tests for HistoryProgress 2018-09-06 17:26:28 +02:00
Florian Bruhin
d4f16f88b6 Remove support for importing pre-v1.0.0 history 2018-09-06 17:26:28 +02:00
Florian Bruhin
ec774379bd Add tests for history progress 2018-09-06 17:13:46 +02:00
Florian Bruhin
e4b7786bcc Factor out GUI stuff to a HistoryProgress object 2018-09-06 17:04:26 +02:00
Florian Bruhin
c8be2d4f7e Fix pylint issues with config cache 2018-09-06 16:43:10 +02:00
Florian Bruhin
108cc65bc6 Merge remote-tracking branch 'origin/pr/4185' 2018-09-06 16:15:16 +02:00
Jay Kamat
8e82adc306
Refactor configcache to cache
Also fix and improve configcache tests
2018-09-05 22:26:12 -07:00
Florian Bruhin
6293bc5178 Fix lint and test 2018-09-04 23:46:34 +02:00
Florian Bruhin
58793d95d7 Further clean up error handling 2018-09-04 23:05:59 +02:00
Florian Bruhin
92fcc523c5 WIP: Properly signal scheme errors 2018-09-04 23:03:10 +02:00
Florian Bruhin
2fcdc5a0c9 Merge branch 'blacklist-history' 2018-09-04 22:19:52 +02:00
Jay Kamat
d4cf5045ab
Fix tests for configcache 2018-09-02 18:03:36 -07:00
Jay Kamat
067d76616b
Implement config cache system 2018-09-02 14:23:00 -07:00
Florian Bruhin
5b0c10d430 Fix docstrings 2018-09-02 15:46:57 +02:00
Florian Bruhin
8a42256cff Merge remote-tracking branch 'origin/pr/4178' 2018-09-02 15:45:48 +02:00
Florian Bruhin
b0185e3c8a Use config_stub.val instead of config_stub.set_obj in tests 2018-09-02 14:42:47 +02:00
Florian Bruhin
dbdeb6a9c7 Rename history.exclude to completion.web_history.exclude
If the blacklist is only valid for the completion, the setting should also be
under completion.

This also un-renames history.gap_interval and renames
completion.web_history_max_items.
2018-09-02 14:42:47 +02:00
Florian Bruhin
4f56355fbe Don't affect qute://history with history.exclude 2018-09-02 14:42:47 +02:00
Florian Bruhin
67b4b7d490 Handle :// as URL pattern 2018-09-02 11:58:34 +02:00
Florian Bruhin
37396d68f3 Define names for sqlite error codes 2018-09-01 22:25:22 +02:00
Florian Bruhin
f5c92ded41 Merge Sql{Environment,Bug}Error with Sqlite{Environment,Bug}Error 2018-09-01 22:25:22 +02:00
Florian Bruhin
50ae2bf2f9 Redesign SQL error handling
Instead of having an environmental attribute on exceptions, we now have two
different exception classes.

Fixes #3341
See #3073
2018-09-01 22:25:22 +02:00