Commit Graph

278 Commits

Author SHA1 Message Date
Florian Bruhin
d8c02f495e Add highlighting test 2019-01-13 10:36:14 +01:00
Florian Bruhin
569bb0fa09 Add cmdutils.Value instead of using count=True/win_id=True 2018-11-30 12:45:01 +01:00
Florian Bruhin
b7de287e7b Move CommandError to api.cmdutils 2018-11-29 14:18:11 +01:00
Florian Bruhin
19628d0ae9 Move cmdutils.cmd_dict to objects.commands 2018-11-29 14:18:11 +01:00
Florian Bruhin
2453134011 Remove unnecessary pass statements 2018-11-28 12:51:53 +01:00
Ryan Roden-Corrent
2e562a926b
Don't complete url and title from same search word.
Resolves #4411:

> When opening a webpage, the suggested results will include those whose
> URL ends with the beginning of the string you've typed and whose title
> begins with the rest of the string.

By joining the url and title with a space, we ensure that the last word
of the url and the first word of the title are treated as separate
words.
2018-11-06 08:05:17 -05:00
Florian Bruhin
ee60159c16 Add missing tests for configmodel 2018-10-11 14:07:13 +02:00
Florian Bruhin
c689760872 Sort keys in configtypes.Dict.to_str
Otherwise, we get inconsistent output between runs on Python 3.5
2018-10-06 19:18:43 +02:00
Florian Bruhin
587b11f60d Make completion highlighting case-insensitive again
Fixes #4297
2018-10-06 09:57:01 +02:00
Florian Bruhin
0858c7146c Get rid of data_display_may_return_none
This got removed in pytest-qt
2018-10-05 18:57:23 +02:00
Florian Bruhin
4b13609553 Fix lint 2018-10-05 18:50:14 +02:00
Florian Bruhin
42ef645cf1 Merge remote-tracking branch 'origin/pr/4004' 2018-10-05 17:46:49 +02: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
4ca8fc0cb7 Use a shared web_history fixture 2018-09-06 20:08:32 +02:00
Philip Scheel
8d04f8cdc8 Fixed pylint complaints 2018-09-04 00:59:49 +02:00
Philip Scheel
35c2f95a58 Merged upstream, made requested modifications to the search engine code and added tests 2018-09-03 23:28:43 +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
Jimmy
b192164f2e Don't alphabetically sort tab completion.
`ListCategory` sorts its completion by default, we are already building
the categories in the right order so don't need that.

The test tests the case of where you have 11 tabs and if the model was
sorted the tabs with index 10 and 11 would be sorted before the one with
index 2.

The `random.sample` bit for the tab url and title is to also make sure
the model isn't being sorted on those columns, whithout haveng to write
and all ten lines.
2018-08-19 16:42:36 +12:00
Florian Bruhin
dcb1191f93 Remove the deprecated :tab-detach 2018-06-09 21:25:09 +02:00
Florian Bruhin
89a1c43b4c Merge remote-tracking branch 'origin/pr/3790' 2018-05-08 11:43:30 +02:00
Jay Kamat
ed76d689b0
Add test for completing other buffer excluding id0 2018-04-10 02:45:12 -04:00
Ryan Roden-Corrent
bca07eebba
Unit-test configmodel arg filtering.
Test that values the user has already input are omitted from the
suggestions. This brings configmodel coverage back to 100%.
2018-03-31 18:55:54 -04:00
Ryan Roden-Corrent
707fc1176d
Regen completion if args change.
Allow completion functions to react dynamically to args as the user
inputs them. This allows config-cycle to filter out values that were
already provided.

Args provided after the maxsplit do not cause the completion to regen.
For example, successive words typed after `:open` just set the filter
pattern and do not spuriously regenerate the completion model.
2018-03-31 11:45:50 -04:00
Ryan Roden-Corrent
f237a87ad0 Completion for varargs.
When a command has positional varargs, keep offering the configured
completion for each successive argument.

Right now this only influences `config-cycle`.

Previously, `config-cycle <option> ` would offer a value completion for
only the first argument after the option. Now it will keep offering
value completion for each successive argument.

This will be useful for passing multiple tags to the new bookmark
commands that will be added for #882.
2018-03-25 21:59:30 -04:00
Florian Bruhin
c590648077 Merge remote-tracking branch 'origin/pr/3613' 2018-03-13 08:39:36 +01:00
Florian Bruhin
34815f5cf8 Make bindings.default only settable in autoconfig.yml
Fixes #3131
2018-03-07 18:30:44 +01:00
Florian Bruhin
0e2a39da2a Fix tests for keyboard parsing change 2018-03-06 07:39:41 +01:00
Florian Bruhin
8deb38e22d Add test for :bind completion with invalid binding 2018-03-05 22:21:57 +01:00
Florian Bruhin
155a1901c0 Merge branch 'keys' 2018-03-04 22:50:41 +01:00
Florian Bruhin
067be7aaa2 Simplify mock checks 2018-03-02 06:33:56 +01:00
Florian Bruhin
fb7fa0cb49 Merge remote-tracking branch 'origin/pr/3652' 2018-03-02 06:31:00 +01:00
Ryan Roden-Corrent
d5e30fd728 Don't crash first completion update with min_chars.
When min_chars is nonzero, if the first command that opens the
completion has < min_chars on the word under the cursor, it triggers a
check for a condition where last_cursor_pos is None.

By setting last_cursor_pos=-1 we ensure that the completer always
updates the first time it is opened, and that there is never a check
against None.

This adds a test for the min_chars feature.

Resolves #3635.
2018-03-01 22:07:53 -05:00
Ryan Roden-Corrent
2965f954ba Resolve empty completion.timestamp_format crash.
Resolves #3628.
2018-03-01 07:54:20 -05:00
Florian Bruhin
5eb340d481 Add missing tests for completions 2018-02-27 15:55:00 +01:00
Florian Bruhin
fa29a0b686 Expect capitalized bindings in test_models 2018-02-27 06:58:39 +01:00
Florian Bruhin
8416e97c6c Fix type which is stubbed in test_models 2018-02-27 06:50:57 +01:00
Florian Bruhin
75181e16fa Fix test_models.py
The Config object got initialized via the config_stub fixture early, so we need
to force it to re-init its values after patching configdata.DATA.
2018-02-19 22:09:46 +01:00
bttner
e169e2165d Refactor TabbedBrowser from inheritance to composition 2018-02-19 14:29:05 +01:00
Florian Bruhin
6f028e9ad0 Update copyright years 2018-02-05 12:19:50 +01:00
Ryan Roden-Corrent
c290b3f80f Don't attempt completion if input starts with flag.
Always interpret the first word in the command string as the command to
offer completions for, even if that word looks like a flag.

Fixes #3460, where the command string `:-w open` would attempt to offer
completions for `open` but crash because the parsing was thrown off.
By moving the flag-stripping logic to _after_ we determine the command,
`:-w open` interprets `:-w` as the command. Since that is not a valid
command, we won't offer any completions.
2018-01-04 12:34:06 -05:00
Florian Bruhin
e65c0dd8a7 pylint: Re-enable bad-continuation
And lots and lots of whitespace changes.
2017-12-15 19:16:55 +01:00
Ryan Roden-Corrent
6420037dd9 Fix histcategory query reuse logic.
I mistakenly checked the length of wheres instead of words. This fixes
that check, renames 'wheres' to 'where_clause' to be clear
that it is a string and not an array, and adds a test.
2017-12-13 08:39:34 -05:00
Ryan Roden-Corrent
8909e03f1c Match url completion terms in any order.
Perviously, 'foo bar' would match 'foo/bar' but not 'bar/foo'. Now it
will match both, using a query with a WHERE clause like:

WHERE ((url || title) like '%foo%' AND (url || title) like '%bar%')

This does not seem to change the performance benchmark. However, it does
create a new query for every character added rather than re-running the
same query with different parameters. We could re-use queries if we
maintained a list like self._queries=[1_arg_query, 2_arg_query, ...].
However, it isn't clear that such a complexity would be necessary.

Resolves #1651.
2017-12-11 07:46:50 -05:00
Ryan Roden-Corrent
636f9edff6 History completion by both URL and title.
Resolves #1649.
2017-12-05 07:32:58 -05:00
Florian Bruhin
a137a29cce Style improvements
This adds a blank line and makes Completer arguments keyword-only to make their
meaning more clear.
2017-12-03 22:32:17 +01:00