Skip to content

Commit

Permalink
Fix line spacing bugs, and fix crash when panel size exceeds screen size
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed May 18, 2024
1 parent fa7aa52 commit c13ac8a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sources/SquirrelPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ final class SquirrelPanel: NSPanel {

let paragraphStyleCandidate = (i == 0 ? theme.firstParagraphStyle : theme.paragraphStyle).mutableCopy() as! NSMutableParagraphStyle
if linear {
paragraphStyleCandidate.paragraphSpacingBefore -= theme.linespace
paragraphStyleCandidate.lineSpacing = theme.linespace
}
if let labelEnd = labeledLine.string.firstMatch(of: /\[(candidate|comment)\]/)?.range.lowerBound {
if !linear, let labelEnd = labeledLine.string.firstMatch(of: /\[(candidate|comment)\]/)?.range.lowerBound {
let labelString = labeledLine.attributedSubstring(from: NSMakeRange(0, labelEnd.utf16Offset(in: labeledLine.string)))
let labelWidth = labelString.boundingRect(with: .zero, options: [.usesLineFragmentOrigin]).width
paragraphStyleCandidate.headIndent = labelWidth
Expand Down Expand Up @@ -350,7 +351,8 @@ private extension SquirrelPanel {
}

if vertical {
panelRect.size = NSMakeSize(contentRect.height + theme.edgeInset.height * 2, contentRect.width + theme.edgeInset.width * 2)
panelRect.size = NSMakeSize(min(0.95 * screenRect.width, contentRect.height + theme.edgeInset.height * 2),
min(0.95 * screenRect.height, contentRect.width + theme.edgeInset.width * 2))
// To avoid jumping up and down while typing, use the lower screen when
// typing on upper, and vice versa
if position.midY / screenRect.height >= 0.5 {
Expand All @@ -365,10 +367,10 @@ private extension SquirrelPanel {
panelRect.origin.x += preeditRect.height + theme.edgeInset.width
}
} else {
panelRect.size = NSMakeSize(contentRect.width + theme.edgeInset.width * 2, contentRect.height + theme.edgeInset.height * 2)
panelRect.size = NSMakeSize(min(0.95 * screenRect.width, contentRect.width + theme.edgeInset.width * 2),
min(0.95 * screenRect.height, contentRect.height + theme.edgeInset.height * 2))
panelRect.origin = NSMakePoint(position.minX, position.minY - SquirrelTheme.offsetHeight - panelRect.height)
}

if panelRect.maxX > screenRect.maxX {
panelRect.origin.x = screenRect.maxX - panelRect.width
}
Expand Down

0 comments on commit c13ac8a

Please sign in to comment.