Allow configuring the search URL

This commit is contained in:
Kovid Goyal 2020-07-27 19:58:04 +05:30
parent 83d5865d4c
commit cbdaad0003
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 9 additions and 1 deletions

View File

@ -40,8 +40,15 @@ def create_selection_panel(container, apply_func, cancel_func):
ans.checked = True ans.checked = True
return E.div(style='margin-top:1ex', E.label(ans, '\xa0' + text)) return E.div(style='margin-top:1ex', E.label(ans, '\xa0' + text))
def url(name, text, title):
ans = E.input(type='url', name=name, value=sd.get(name), size='50', title=title or '')
return E.div(style='margin-top:1ex', E.label(text, E.br(), ans))
container.appendChild(cb( container.appendChild(cb(
'show_selection_bar', _('Show a popup bar with common actions next to selected text'))) 'show_selection_bar', _('Show a popup bar with common actions next to selected text')))
container.appendChild(url(
'net_search_url', _('URL to query when searching the internet'),
_('The {q} in the URL is replaced by the selected text')))
container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func)) container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func))

View File

@ -89,7 +89,7 @@ class SelectionBar:
text = self.view.currently_showing.selection.text text = self.view.currently_showing.selection.text
if text: if text:
q = encodeURIComponent(text) q = encodeURIComponent(text)
url = f'https://google.com/search?q={q}' url = get_session_data().get('net_search_url').format(q=q)
ui_operations.open_url(url) ui_operations.open_url(url)
def clear_selection(self): def clear_selection(self):

View File

@ -65,6 +65,7 @@ defaults = {
'highlight_style': None, 'highlight_style': None,
'custom_highlight_colors': v'[]', 'custom_highlight_colors': v'[]',
'show_selection_bar': True, 'show_selection_bar': True,
'net_search_url': 'https://google.com/search?q={q}',
} }
is_local_setting = { is_local_setting = {