username highlighting (#1502)

This commit is contained in:
Ryan Nystrom
2018-02-09 17:40:05 -05:00
committed by GitHub
parent 220a5a3373
commit 44e2da1d35
5 changed files with 21 additions and 1 deletions

View File

@@ -66,7 +66,7 @@ MessageAutocompleteControllerDelegate {
prefix: messageAutocompleteController.selection?.prefix,
indexPath: indexPath
) {
messageAutocompleteController.accept(autocomplete: accepted + " ", keepPrefix: false)
messageAutocompleteController.accept(autocomplete: accepted, keepPrefix: false)
}
}
@@ -79,6 +79,10 @@ MessageAutocompleteControllerDelegate {
func didChangeStore(autocomplete: IssueCommentAutocomplete) {
for prefix in autocomplete.prefixes {
messageAutocompleteController.register(prefix: prefix)
if let attributes = autocomplete.highlightAttributes(prefix: prefix) {
messageAutocompleteController.registerAutocomplete(prefix: prefix, attributes: attributes)
}
}
messageAutocompleteController.tableView.reloadData()
}

View File

@@ -20,4 +20,6 @@ protocol AutocompleteType {
func accept(index: Int) -> String?
var highlightAttributes: [NSAttributedStringKey: Any]? { get }
}

View File

@@ -57,4 +57,6 @@ final class EmojiAutocomplete: AutocompleteType {
return results[index].emoji
}
var highlightAttributes: [NSAttributedStringKey : Any]? { return nil }
}

View File

@@ -46,6 +46,10 @@ final class IssueCommentAutocomplete {
return map.map { $0.key }
}
func highlightAttributes(prefix: String) -> [NSAttributedStringKey: Any]? {
return map[prefix]?.highlightAttributes
}
func resultCount(prefix: String?) -> Int {
guard let prefix = prefix, let autocomplete = map[prefix] else { return 0 }
return autocomplete.resultsCount

View File

@@ -63,4 +63,12 @@ final class UserAutocomplete: AutocompleteType {
return prefix + results[index].login
}
var highlightAttributes: [NSAttributedStringKey : Any]? {
return [
.font: Styles.Text.body.preferredFont,
.foregroundColor: Styles.Colors.Blue.medium.color,
.backgroundColor: Styles.Colors.Blue.medium.color.withAlphaComponent(0.1),
]
}
}