diff --git a/Museion/PostEditorView.swift b/Museion/PostEditorView.swift index 34c3159..b6fcf21 100644 --- a/Museion/PostEditorView.swift +++ b/Museion/PostEditorView.swift @@ -278,8 +278,10 @@ struct ProseTextView: NSViewRepresentable { tv.isVerticallyResizable = true tv.isHorizontallyResizable = false tv.autoresizingMask = [.width] - tv.textContainer?.containerSize = NSSize(width: 640, height: CGFloat.greatestFiniteMagnitude) - tv.textContainer?.widthTracksTextView = false + // Wrap to the editor column (#71 fix): the container tracks the view + // width — the fixed 640pt measure clipped in narrower columns. + tv.textContainer?.containerSize = NSSize(width: 0, height: CGFloat.greatestFiniteMagnitude) + tv.textContainer?.widthTracksTextView = true tv.textContainer?.lineFragmentPadding = 12 tv.textContainerInset = NSSize(width: 0, height: 20) let scroll = NSScrollView() @@ -301,7 +303,12 @@ struct ProseTextView: NSViewRepresentable { // per keystroke: the text view owns the live text. if context.coordinator.loadedGeneration != session.loadGeneration { context.coordinator.loadedGeneration = session.loadGeneration - tv.textStorage?.setAttributedString(ProsePresenter.attribute(session.loadText)) + // Seed from session.text (LIVE), not session.loadText (the + // open-time snapshot): the representable is recreated on the + // reading⇄editing swap, and seeding from the snapshot showed + // pre-edit text — then session.edit on the stale view would + // have flushed it over the user's real content (#71 fix). + tv.textStorage?.setAttributedString(ProsePresenter.attribute(session.text)) // #66: restore cursor (clamped) + scroll. let length = (tv.string as NSString).length var cursor = session.restoreCursor ?? PostStore.CursorState() diff --git a/Museion/ReadingPresenter.swift b/Museion/ReadingPresenter.swift index 01031c5..a9a2638 100644 --- a/Museion/ReadingPresenter.swift +++ b/Museion/ReadingPresenter.swift @@ -117,7 +117,19 @@ enum ReadingPresenter { private static func flowContent(_ lines: [String], first: String) -> NSAttributedString { if let level = headingLevel(first) { let body = first.drop { $0 == "#" }.trimmingCharacters(in: .whitespaces) - return headingContent(body, level: level) + let heading = headingContent(body, level: level) + // Bug fix: a heading chunk may carry body lines under the heading + // (single newline is legal markdown) — they are part of the block. + let rest = lines.dropFirst() + .map { $0.trimmingCharacters(in: .whitespaces) } + .filter { !$0.isEmpty } + if rest.isEmpty { + return heading + } + let out = NSMutableAttributedString(attributedString: heading) + out.append(NSAttributedString(string: "\n", attributes: ProseTypography.bodyAttributes)) + out.append(inlineParse(rest.joined(separator: " "))) + return out } if first.hasPrefix("```") { let inner = lines.dropFirst().dropLast(hasClosingFence(lines) ? 1 : 0) @@ -209,7 +221,7 @@ enum ReadingPresenter { item.append(inlineParse(marker.payload.trimmingCharacters(in: .whitespaces))) item.addAttribute( .paragraphStyle, value: ps, - range: NSRange(location: 0, length: item.length) + range: NSRange(location: 0, length: item.length), ) out.append(item) if index < lines.count - 1 { @@ -277,7 +289,7 @@ enum ReadingPresenter { let text = column < cells.count ? cells[column] : "" let cell = NSTextTableBlock( table: table, startingRow: row, rowSpan: 1, - startingColumn: column, columnSpan: 1 + startingColumn: column, columnSpan: 1, ) cell.setWidth(1, type: .absolute, for: .border) let ps = NSMutableParagraphStyle() @@ -290,7 +302,7 @@ enum ReadingPresenter { ] out.append(NSAttributedString( string: text + (column == header.count - 1 ? "\n" : ""), - attributes: attrs + attributes: attrs, )) } row += 1 diff --git a/Museion/ReadingSurface.swift b/Museion/ReadingSurface.swift index f25cca4..ecdffc4 100644 --- a/Museion/ReadingSurface.swift +++ b/Museion/ReadingSurface.swift @@ -64,8 +64,14 @@ struct ReadingSurface: NSViewRepresentable { tv.isVerticallyResizable = true tv.isHorizontallyResizable = false tv.autoresizingMask = [.width] - tv.textContainer?.containerSize = NSSize(width: 640, height: CGFloat.greatestFiniteMagnitude) - tv.textContainer?.widthTracksTextView = false + // Tables (#69) lay out correctly under TextKit1 only — TK2 stacks + // NSTextTable rows vertically (probed). The canvas is read-only, so + // nothing editing-grade is lost by forcing the TK1 bridge. + tv.textContainer?.replaceLayoutManager(NSLayoutManager()) + // Wrap to the editor column (#68/71 fix): the container tracks the + // view width — a fixed 640pt measure clipped in narrower columns. + tv.textContainer?.containerSize = NSSize(width: 0, height: CGFloat.greatestFiniteMagnitude) + tv.textContainer?.widthTracksTextView = true tv.textContainer?.lineFragmentPadding = 12 tv.textContainerInset = NSSize(width: 0, height: 20) let scroll = NSScrollView() diff --git a/default.profraw b/default.profraw new file mode 100644 index 0000000..e69de29