Skip to content

Commit

Permalink
fix candidate attributes
Browse files Browse the repository at this point in the history
Update SquirrelPanel.swift
  • Loading branch information
LEOYoon-Tsaw committed May 16, 2024
1 parent d21ddb7 commit 9020996
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sources/SquirrelPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ final class SquirrelPanel: NSPanel {
let comment = comments[i].precomposedStringWithCanonicalMapping

let line = NSMutableAttributedString(string: theme.candidateFormat, attributes: labelAttrs)
line.addAttributes(attrs, range: (line.string as NSString).range(of: "[candidate]"))
line.addAttributes(commentAttrs, range: (line.string as NSString).range(of: "[comment]"))
for range in line.string.ranges(of: /\[candidate\]/) {
line.addAttributes(attrs, range: convert(range: range, in: line.string))
}
for range in line.string.ranges(of: /\[comment\]/) {
line.addAttributes(commentAttrs, range: convert(range: range, in: line.string))
}
line.mutableString.replaceOccurrences(of: "[label]", with: label, range: NSMakeRange(0, line.length))
let labeledLine = line.copy() as! NSAttributedString
line.mutableString.replaceOccurrences(of: "[candidate]", with: candidate, range: NSMakeRange(0, line.length))
Expand Down Expand Up @@ -428,4 +432,10 @@ private extension SquirrelPanel {
self.hide()
}
}

func convert(range: Range<String.Index>, in string: String) -> NSRange {
let startPos = range.lowerBound.utf16Offset(in: string)
let endPos = range.upperBound.utf16Offset(in: string)
return NSRange(location: startPos, length: endPos - startPos)
}
}

0 comments on commit 9020996

Please sign in to comment.