mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-05-30 04:07:44 +08:00
username highlighting (#1502)
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -20,4 +20,6 @@ protocol AutocompleteType {
|
||||
|
||||
func accept(index: Int) -> String?
|
||||
|
||||
var highlightAttributes: [NSAttributedStringKey: Any]? { get }
|
||||
|
||||
}
|
||||
|
||||
@@ -57,4 +57,6 @@ final class EmojiAutocomplete: AutocompleteType {
|
||||
return results[index].emoji
|
||||
}
|
||||
|
||||
var highlightAttributes: [NSAttributedStringKey : Any]? { return nil }
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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),
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user