Skip to content

Commit

Permalink
Fix printing in macOS Sequoia (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanzhong authored Nov 28, 2024
1 parent 659e59d commit 6fa40cf
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions MarkEditMac/Sources/Editor/Models/EditorDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,26 @@ extension EditorDocument {
return
}

// Ideally we should be able to print WKWebView,
// but it doesn't work well because of the lazily rendering strategy used in CodeMirror.
//
// For now let's just print plain text,
// we don't expect printing to be used a lot.

Task {
// Ideally we should be able to print WKWebView,
// but it doesn't work well because of the lazily rendering strategy used in CodeMirror.
//
// For now let's just print plain text,
// we don't expect printing to be used a lot.
let textView = NSTextView(frame: CGRect(origin: .zero, size: printInfo.paperSize))
// Alignment
printInfo.isHorizontallyCentered = true
printInfo.isVerticallyCentered = false

// Sizing
let width = printInfo.paperSize.width - printInfo.leftMargin - printInfo.rightMargin
let height = printInfo.paperSize.height - printInfo.topMargin - printInfo.bottomMargin
let frame = CGRect(x: 0, y: 0, width: width, height: height)

// Rendering
let textView = NSTextView(frame: frame)
textView.string = await hostViewController?.editorText ?? stringValue
textView.sizeToFit()

let operation = NSPrintOperation(view: textView)
operation.runModal(for: window, delegate: nil, didRun: nil, contextInfo: nil)
Expand Down

0 comments on commit 6fa40cf

Please sign in to comment.