Skip to content

Commit

Permalink
Improve layout strategy for version picker (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanzhong authored Dec 12, 2024
1 parent e303521 commit a28ca6b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions MarkEditMac/Modules/Sources/FileVersion/FileVersionPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,21 @@ public final class FileVersionPicker: NSViewController {
textView?.drawsBackground = false
textView?.isEditable = false
textView?.isSelectable = true

textView?.textContainerInset = CGSize(width: Constants.layoutPadding, height: Constants.layoutPadding)
textView?.textContainer?.lineFragmentPadding = 0

// We avoid using width in textContainerInset as it disrupts the cursor style
textView?.textContainerInset = CGSize(
width: 0,
height: Constants.layoutPadding
)

// Instead, we use a tail indent and adjust the leading position to achieve the same effect
textView?.defaultParagraphStyle = {
let style = NSMutableParagraphStyle()
style.tailIndent = -Constants.layoutPadding
return style
}()

// Background color fills the full width to visualize empty lines
textView?.layoutManager?.showsControlCharacters = true

Expand Down Expand Up @@ -281,7 +292,7 @@ private extension FileVersionPicker {
counterView.trailingAnchor.constraint(lessThanOrEqualTo: cancelButton.leadingAnchor, constant: -Constants.layoutPadding),
counterView.centerYAnchor.constraint(equalTo: bottomGuide.centerYAnchor),

scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: Constants.layoutPadding),
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
scrollView.topAnchor.constraint(equalTo: topGuide.bottomAnchor),
scrollView.bottomAnchor.constraint(equalTo: bottomGuide.topAnchor),
Expand Down

0 comments on commit a28ca6b

Please sign in to comment.