Fix timing to update print page range

This commit is contained in:
1024jp 2022-12-04 10:16:04 +09:00
parent 1a0a0416d8
commit 2d446204ab
2 changed files with 16 additions and 11 deletions

View File

@ -5,6 +5,10 @@ Change Log
4.4.3 (unreleased)
--------------------------
### Fixes
- Fix an issue the total page did not update when changing the print scope option to Selection in CotEditor in the print dialog.
4.4.2 (544)

View File

@ -157,13 +157,17 @@ final class PrintTextView: NSTextView, Themable {
/// return the number of pages available for printing
override func knowsPageRange(_ range: NSRangePointer) -> Bool {
// adjust content size based on print setting
if let paperContentSize = NSPrintOperation.current?.printInfo.paperContentSize,
self.lastPaperContentSize != paperContentSize
{
self.lastPaperContentSize = paperContentSize
self.frame.size = paperContentSize
self.layoutManager?.doForegroundLayout()
if let printInfo = NSPrintOperation.current?.printInfo {
// set scope to print
(self.layoutManager as? PrintLayoutManager)?.showsSelectionOnly = printInfo.isSelectionOnly
// adjust content size based on print setting
let paperContentSize = printInfo.paperContentSize
if self.lastPaperContentSize != paperContentSize {
self.lastPaperContentSize = paperContentSize
self.frame.size = paperContentSize
self.layoutManager?.doForegroundLayout()
}
}
return super.knowsPageRange(range)
@ -265,13 +269,10 @@ final class PrintTextView: NSTextView, Themable {
private func applyPrintSettings() {
guard
let layoutManager = self.layoutManager as? PrintLayoutManager,
let layoutManager = self.layoutManager as? LayoutManager,
let printInfo = NSPrintOperation.current?.printInfo
else { return assertionFailure() }
// set scope to print
layoutManager.showsSelectionOnly = printInfo.isSelectionOnly
// set line numbers
self.printsLineNumber = printInfo[.printsLineNumbers] ?? false
// adjust paddings considering the line numbers