From 6cdcac1396e60286284fd8cbfe5c859050c696af Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 5 Feb 2017 03:01:23 +0100 Subject: [PATCH] Fix #598 - arrow keys to navigate media; fix #481 - non-exact matches no longer overshadow requirement for remote-lookup --- .../components/components/lightbox.jsx | 2 +- .../ui/containers/modal_container.jsx | 23 +++++++++++++++++++ app/services/search_service.rb | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/components/components/lightbox.jsx b/app/assets/javascripts/components/components/lightbox.jsx index 6464845395..65ff708b47 100644 --- a/app/assets/javascripts/components/components/lightbox.jsx +++ b/app/assets/javascripts/components/components/lightbox.jsx @@ -44,7 +44,7 @@ const Lightbox = React.createClass({ componentDidMount () { this._listener = e => { - if (e.key === 'Escape') { + if (this.props.isVisible && e.key === 'Escape') { this.props.onCloseClicked(); } }; diff --git a/app/assets/javascripts/components/features/ui/containers/modal_container.jsx b/app/assets/javascripts/components/features/ui/containers/modal_container.jsx index 0ffbfe8b30..1e69fc59c8 100644 --- a/app/assets/javascripts/components/features/ui/containers/modal_container.jsx +++ b/app/assets/javascripts/components/features/ui/containers/modal_container.jsx @@ -104,6 +104,29 @@ const Modal = React.createClass({ this.props.onPrevClicked(); }, + componentDidMount () { + this._listener = e => { + if (!this.props.isVisible) { + return; + } + + switch(e.key) { + case 'ArrowLeft': + this.props.onPrevClicked(); + break; + case 'ArrowRight': + this.props.onNextClicked(); + break; + } + }; + + window.addEventListener('keyup', this._listener); + }, + + componentDidUnmount () { + window.removeEventListener('keyup', this._listener); + }, + render () { const { media, index, ...other } = this.props; diff --git a/app/services/search_service.rb b/app/services/search_service.rb index e9a27f136d..04de8a1347 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -17,7 +17,7 @@ class SearchService < BaseService results = results.limit(limit).to_a results = [exact_match] + results.reject { |a| a.id == exact_match.id } if exact_match - if resolve && results.empty? && !domain.nil? + if resolve && !exact_match && !domain.nil? results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")] end