50 lines
1.7 KiB
Swift
50 lines
1.7 KiB
Swift
import AppKit
|
|
import PlakCore
|
|
|
|
/// Where the caret goes when an editor closes with a key.
|
|
enum EditorExit {
|
|
/// Esc: right after the object.
|
|
case after
|
|
/// ↑ on the first line or row: the end of the line above.
|
|
case above
|
|
/// ↓ on the last line or row: the start of the line below.
|
|
case below
|
|
}
|
|
|
|
/// What an edit does to its object.
|
|
enum ObjectEdit: Equatable {
|
|
case unchanged
|
|
/// The new kind and body; the page builds the object only when the edit closes.
|
|
case replaced(FenceKind, String)
|
|
case removed
|
|
}
|
|
|
|
/// An editor open over a code block or table, placed by the page over the object.
|
|
@MainActor
|
|
protocol ObjectEditor: AnyObject {
|
|
/// The view the page puts over the object.
|
|
var view: NSView { get }
|
|
/// The view that takes the keys when the editor opens.
|
|
var focusView: NSView { get }
|
|
/// Asks the page to close the editor and put the caret back in the text.
|
|
var onEnd: ((EditorExit) -> Void)? { get set }
|
|
/// The editor needs another size.
|
|
var onResize: (() -> Void)? { get set }
|
|
/// The content changed.
|
|
var onChange: (() -> Void)? { get set }
|
|
|
|
/// The size of the editor when `width` is the room from the object to the end of the column.
|
|
func size(available width: CGFloat) -> NSSize
|
|
func setFont(_ font: NSFont)
|
|
/// The object as the edit has it now, a cell being edited included; it changes nothing, so a save can ask.
|
|
func edit() -> ObjectEdit
|
|
}
|
|
|
|
/// The cell of a code block or table, which takes the height of its editor while that is open.
|
|
@MainActor
|
|
protocol ObjectCell: AnyObject {
|
|
/// The height the open editor needs; nil while no editor is open.
|
|
var editingHeight: CGFloat? { get set }
|
|
func setFont(_ font: NSFont)
|
|
}
|