forked from organicmaps/organicmaps
[ios] fix search result selection index after filtering the suggestions
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
parent
52bbb9c28a
commit
55951a28be
8 changed files with 16 additions and 14 deletions
|
@ -160,9 +160,9 @@ using Observers = NSHashTable<Observer>;
|
|||
}
|
||||
|
||||
+ (SearchResult *)resultWithContainerIndex:(NSUInteger)index {
|
||||
SearchResult * result = [[SearchResult alloc]
|
||||
initWithResult:[MWMSearch manager]->m_everywhereResults[index]
|
||||
itemType:[MWMSearch resultTypeWithRow:index]];
|
||||
SearchResult * result = [[SearchResult alloc] initWithResult:[MWMSearch manager]->m_everywhereResults[index]
|
||||
itemType:[MWMSearch resultTypeWithRow:index]
|
||||
index:index];
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@interface SearchResult (Core)
|
||||
|
||||
- (instancetype)initWithResult:(const search::Result &)result itemType:(SearchItemType)itemType;
|
||||
- (instancetype)initWithResult:(const search::Result &)result itemType:(SearchItemType)itemType index:(NSUInteger)index;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@interface SearchResult : NSObject
|
||||
|
||||
@property (nonatomic, readonly) NSUInteger index;
|
||||
@property (nonatomic, readonly) NSString * titleText;
|
||||
@property (nonatomic, readonly) NSString * iconImageName;
|
||||
@property (nonatomic, readonly) NSString * addressText;
|
||||
|
|
|
@ -26,9 +26,10 @@
|
|||
|
||||
@implementation SearchResult(Core)
|
||||
|
||||
- (instancetype)initWithResult:(const search::Result &)result itemType:(SearchItemType)itemType {
|
||||
- (instancetype)initWithResult:(const search::Result &)result itemType:(SearchItemType)itemType index:(NSUInteger)index {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_index = index;
|
||||
_titleText = result.GetString().empty() ? @(result.GetLocalizedFeatureType().c_str()) : @(result.GetString().c_str());
|
||||
_addressText = @(result.GetAddress().c_str());
|
||||
_infoText = @(result.GetFeatureDescription().c_str());
|
||||
|
|
|
@ -130,7 +130,7 @@ final class SearchOnMapTests: XCTestCase {
|
|||
let results = SearchResult.stubResults()
|
||||
searchManager.results = results
|
||||
|
||||
interactor.handle(.didSelectResult(results[0], atIndex: 0, withSearchText: searchText))
|
||||
interactor.handle(.didSelectResult(results[0], withSearchText: searchText))
|
||||
XCTAssertEqual(currentState, .hidden)
|
||||
XCTAssertEqual(view.viewModel.presentationStep, .hidden)
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ final class SearchOnMapTests: XCTestCase {
|
|||
let results = SearchResult.stubResults()
|
||||
searchManager.results = results
|
||||
|
||||
interactor.handle(.didSelectResult(results[0], atIndex: 0, withSearchText: searchText))
|
||||
interactor.handle(.didSelectResult(results[0], withSearchText: searchText))
|
||||
XCTAssertEqual(currentState, .hidden)
|
||||
XCTAssertEqual(view.viewModel.presentationStep, .hidden)
|
||||
|
||||
|
@ -207,7 +207,7 @@ final class SearchOnMapTests: XCTestCase {
|
|||
interactor.handle(.didType(searchText))
|
||||
|
||||
let suggestion = SearchResult(titleText: "", type: .suggestion, suggestion: "suggestion")
|
||||
interactor.handle(.didSelectResult(suggestion, atIndex: 0, withSearchText: searchText))
|
||||
interactor.handle(.didSelectResult(suggestion, withSearchText: searchText))
|
||||
|
||||
XCTAssertEqual(view.viewModel.searchingText, "suggestion")
|
||||
XCTAssertEqual(view.viewModel.contentState, .searching)
|
||||
|
|
|
@ -45,8 +45,8 @@ final class SearchOnMapInteractor: NSObject {
|
|||
return processSelectedText(searchText, isCategory: isCategory)
|
||||
case .searchButtonDidTap(let searchText):
|
||||
return processSearchButtonDidTap(searchText)
|
||||
case .didSelectResult(let result, let index, let searchText):
|
||||
return processSelectedResult(result, index: index, searchText: searchText)
|
||||
case .didSelectResult(let result, let searchText):
|
||||
return processSelectedResult(result, searchText: searchText)
|
||||
case .didSelectPlaceOnMap:
|
||||
return isIPad ? .none : .setSearchScreenHidden(true)
|
||||
case .didDeselectPlaceOnMap:
|
||||
|
@ -93,14 +93,14 @@ final class SearchOnMapInteractor: NSObject {
|
|||
return .selectText(searchText.text)
|
||||
}
|
||||
|
||||
private func processSelectedResult(_ result: SearchResult, index: Int, searchText: SearchOnMap.SearchText) -> SearchOnMap.Response {
|
||||
private func processSelectedResult(_ result: SearchResult, searchText: SearchOnMap.SearchText) -> SearchOnMap.Response {
|
||||
switch result.itemType {
|
||||
case .regular:
|
||||
searchManager.saveQuery(searchText.text,
|
||||
forInputLocale:searchText.locale)
|
||||
switch routingTooltipSearch {
|
||||
case .none:
|
||||
searchManager.showResult(at: UInt(index))
|
||||
searchManager.showResult(at: result.index)
|
||||
case .start:
|
||||
let point = MWMRoutePoint(cgPoint: result.point,
|
||||
title: result.titleText,
|
||||
|
|
|
@ -49,7 +49,7 @@ enum SearchOnMap {
|
|||
case didStartTyping
|
||||
case didType(SearchText)
|
||||
case didSelectText(SearchText, isCategory: Bool)
|
||||
case didSelectResult(SearchResult, atIndex: Int, withSearchText: SearchText)
|
||||
case didSelectResult(SearchResult, withSearchText: SearchText)
|
||||
case searchButtonDidTap(SearchText)
|
||||
case clearButtonDidTap
|
||||
case didSelectPlaceOnMap
|
||||
|
|
|
@ -303,7 +303,7 @@ extension SearchOnMapViewController: UITableViewDataSource {
|
|||
extension SearchOnMapViewController: UITableViewDelegate {
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
let result = searchResults[indexPath.row]
|
||||
interactor.handle(.didSelectResult(result, atIndex: indexPath.row, withSearchText: headerView.searchText))
|
||||
interactor.handle(.didSelectResult(result, withSearchText: headerView.searchText))
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue