improves plak

This commit is contained in:
2026-10-17 17:33:13 +02:00
parent 7b891819b0
commit a92d6f8871
633 changed files with 17623 additions and 7556 deletions
+10 -3
View File
@@ -66,6 +66,7 @@ public final class PageViewController: NSViewController, NSTextViewDelegate, NST
textView.delegate = self
textView.now = now
textView.onImages = { [weak self] images, range in self?.insertImages(images, replacing: range) }
textView.onEditorChange = { [weak self] in self?.store.changed() }
textView.textStorage?.delegate = self
banner.font = .systemFont(ofSize: 12)
@@ -103,10 +104,15 @@ public final class PageViewController: NSViewController, NSTextViewDelegate, NST
textView.undoManager?.removeAllActions()
}
/// The page file text of the page as it is now.
/// The page file text of the page as it is now, with the edit of an open editor in it.
func pageFileText() -> String {
guard let textStorage = textView.textStorage else { return "" }
return PageText.pageFile(textStorage).text()
return PageText.pageFile(textStorage, draft: textView.editorDraft()).text()
}
/// Closes an open code block or table editor and puts its edit in the page, as before Plak hides or quits.
public func closeEditor() {
textView.endEditing(nil)
}
// MARK: Launch
@@ -180,7 +186,7 @@ public final class PageViewController: NSViewController, NSTextViewDelegate, NST
store.changed()
textView.invalidateMargin()
if textView.topSpace > PageMetrics.topInset || textView.frame.height <= clip.bounds.height * 2 { layoutPage() }
keepCaretAboveFloor()
if !textView.isReplacingObject { keepCaretAboveFloor() }
}
/// Runs after the edit, not inside it: attribute changes during an edit move the caret to the end of the block.
@@ -220,6 +226,7 @@ public final class PageViewController: NSViewController, NSTextViewDelegate, NST
textView.setSpaces(side: side, top: top, bottom: bottom)
if textView.frame.width != visible.width { textView.setFrameSize(NSSize(width: visible.width, height: textView.frame.height)) }
textView.sizeToFit()
textView.positionEditor()
}
@objc private func clipFrameChanged(_ notification: Notification) {