fix search from url bar

This commit is contained in:
Izalia Mae 2023-01-29 12:33:29 -05:00
parent ded8e94e73
commit a092150ffa
2 changed files with 23 additions and 31 deletions

View file

@ -501,55 +501,47 @@ class WebTab(BuilderBase, Gtk.Box):
self['navbar-url'].select_region(0,0)
def handle_load_url(self, full_url):
keyword = None
def handle_load_url(self, raw_url):
with self.db.session as s:
if Path(full_url).exists():
full_url = f'local://{full_url}'
if Path(raw_url).exists():
return run_in_gui_thread(self.webview.load_uri, Url(f'local://{raw_url}'))
full_url = Url(full_url)
if not full_url.domain and full_url.path and not full_url.proto:
proto = 'https' if s.get_config('https_force') else 'http'
try:
url = Url(f'{proto}://{full_url}')
except ValueError:
return run_in_gui_thread(self.window.notification, f'Not a valid url: {full_url}')
else:
url = Url(full_url)
url = Url(raw_url)
# Can't register the ftp protocol, so use an alternative scheme name
if full_url.proto == 'ftp':
if url.proto == 'ftp':
logging.verbose('ftp url. Redirecting to filetp instead')
url = full_url.replace_property('proto', 'filetp')
url = url.replace_property('proto', 'filetp')
# Can't register the file protocol either
elif full_url.proto == 'file':
elif url.proto == 'file':
logging.verbose('file url. Redirecting to local instead')
url = full_url.replace_property('proto', 'local')
url = url.replace_property('proto', 'local')
elif not full_url.proto:
elif not url.proto:
## Check the first word is a search keyword
try:
keyword, data = full_url.split(' ', 1)
keyword, data = raw_url.split(' ', 1)
except ValueError:
keyword, data = None, full_url
keyword, data = None, raw_url
## Is the url.domain an actual domain?
if not keyword:
try:
Address(resolve_address(url.domain))
proto = 'https' if s.get_config('https_force') else 'http'
url = Url(f'{proto}://{url}')
logging.verbose('Url without protocol')
except (NXDOMAIN, NoAnswer):
search = s.get_search(keyword, default=True)
logging.verbose('Keyword search:', search.keyword)
url = search.compile(full_url)
except (NXDOMAIN, NoAnswer, TypeError):
keword = s.get_config('default_search')
if not (search := s.get_search(keyword, default=False)):
search = s.get_search()
data = raw_url
logging.verbose('Keyword search:', search.keyword)
url = search.compile(data)
## this is broken :/
# try:

View file

@ -320,7 +320,7 @@ class CustomSession(Session):
if row:
return row
if default:
elif default:
return self.get_search()