|
@@ -35,7 +35,7 @@ class KMBOTAOutlineView: BaseXibView {
|
|
|
|
|
|
var isSearchMode = false
|
|
|
var searchKey = ""
|
|
|
- var wholeWords = false {
|
|
|
+ var wholeWords = true {
|
|
|
didSet {
|
|
|
if isValidSearchMode() == false {
|
|
|
return
|
|
@@ -313,12 +313,33 @@ extension KMBOTAOutlineView : NSOutlineViewDataSource,NSOutlineViewDelegate {
|
|
|
_searchKey = _searchKey.lowercased()
|
|
|
}
|
|
|
|
|
|
- let ranges = label.ranges(of: _searchKey)
|
|
|
- for range in ranges.nsRnage {
|
|
|
- attri.addAttributes([.font : NSFont.SFProTextBoldFont(13), .foregroundColor: KMNColorTools.colorPrimary_textLight()], range: range)
|
|
|
+ if wholeWords {
|
|
|
+ let escapedKey = NSRegularExpression.escapedPattern(for: _searchKey)
|
|
|
+
|
|
|
+ let pattern = "\\b\(escapedKey)\\b"
|
|
|
+
|
|
|
+ do {
|
|
|
+ let regex = try NSRegularExpression(pattern: pattern, options: caseSensitive ? [] : [.caseInsensitive])
|
|
|
+ let matches = regex.matches(in: label, range: NSRange(location: 0, length: label.utf16.count))
|
|
|
+
|
|
|
+ for match in matches {
|
|
|
+ attri.addAttributes([
|
|
|
+ .font : NSFont.SFProTextBoldFont(13),
|
|
|
+ .foregroundColor: KMNColorTools.colorPrimary_textLight()
|
|
|
+ ], range: match.range)
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let ranges = label.ranges(of: _searchKey)
|
|
|
+ for range in ranges.nsRnage {
|
|
|
+ attri.addAttributes([.font : NSFont.SFProTextBoldFont(13), .foregroundColor: KMNColorTools.colorPrimary_textLight()], range: range)
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- cell.titleLabel.attributedStringValue = attri
|
|
|
|
|
|
+ cell.titleLabel.attributedStringValue = attri
|
|
|
cell.iconButton.isHidden = model.searchChildren.isEmpty
|
|
|
} else {
|
|
|
cell.titleLabel.stringValue = model.outline.label ?? ""
|