Fix current line highlight with line height 1.0 (fix #594)

This commit is contained in:
1024jp 2016-09-16 22:46:28 +09:00
parent 48eae506b2
commit d6fde4f40a
3 changed files with 19 additions and 2 deletions

View File

@ -20,6 +20,7 @@ develop
- Fix an issue find string is not shared to other applications after quitting CotEditor.
- Address an issue with drawing area of zoomed character view in character inspector popover.
- [beta] Fix an issue where current line highlight was occasionally too wide when line height is 1.0.
- [beta] Fix an issue where inputting character with unicode hex didn't work.
- [beta] Fix some memory leaks.

View File

@ -1080,8 +1080,9 @@ final class EditorTextView: NSTextView, Themable {
// -> The actual line height will be calculated in LayoutManager and ATSTypesetter based on this line height multiple.
// Because the default Cocoa Text System calculate line height differently
// if the first character of the document is drawn with another font (typically by a composite font).
paragraphStyle.lineHeightMultiple = self.lineHeight
// -> Round line height for workaround to avoid expanding current line highlight when line height is 1.0. (2016-09 on macOS Sierra 10.12)
paragraphStyle.lineHeightMultiple = self.lineHeight.rounded(to: 5)
moof(self.lineHeight.rounded(to: 5))
// calculate tab interval
if let font = self.font, let displayFont = self.layoutManager?.substituteFont(for: font) {
paragraphStyle.tabStops = []

View File

@ -95,3 +95,18 @@ extension CGRect {
}
}
// MARK: CGFloat
extension CGFloat {
/// round to decimal places value
func rounded(to places: Int) -> CGFloat {
let divisor = pow(10.0, CGFloat(places))
return (self * divisor).rounded() / divisor
}
}