feat(web): implement complete workspace with themes, tabs, sidebar, and mobile
Transform CalcText from a single-document calculator into a full workspace application with multi-document support, theming, and responsive mobile experience. - Theme system: 5 presets (Light, Dark, Matrix, Midnight, Warm) + accent colors - Document model with localStorage persistence and auto-save - Tab bar with keyboard shortcuts (Ctrl+N/W/Tab/1-9), rename, close - Sidebar with search, recent, favorites, folders, templates, drag-and-drop - 5 templates: Budget, Invoice, Unit Converter, Trip Planner, Loan Calculator - Status bar with cursor position, engine status, dedication to Igor Cassel - Results panel: type-specific colors, click-to-copy, error hints - Format toolbar: H, B, I, //, color labels with live preview toggle - Syntax highlighting using theme CSS variables - Error hover tooltips - Mobile: bottom results tray, sidebar drawer, touch targets, safe areas - Docker multi-stage build (Rust WASM + Vite + Nginx) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,52 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
// MARK: - StripedTextView
|
||||
|
||||
/// NSTextView subclass that draws alternating row background stripes.
|
||||
/// Used by both the editor and answer column to provide zebra-striping
|
||||
/// that visually connects lines across panes.
|
||||
final class StripedTextView: NSTextView {
|
||||
/// Subtle stripe color for odd-numbered lines.
|
||||
static let stripeColor = NSColor.secondaryLabelColor.withAlphaComponent(0.04)
|
||||
|
||||
override func drawBackground(in rect: NSRect) {
|
||||
super.drawBackground(in: rect)
|
||||
|
||||
guard let layoutManager = layoutManager,
|
||||
let textContainer = textContainer else { return }
|
||||
|
||||
let stripeColor = Self.stripeColor
|
||||
|
||||
// We need the absolute line index (not just visible lines) so that
|
||||
// the stripe pattern stays consistent when scrolling and matches
|
||||
// the answer column. Walk all line fragments from the start of the
|
||||
// document, but only fill those that intersect the dirty rect.
|
||||
let fullGlyphRange = layoutManager.glyphRange(for: textContainer)
|
||||
var lineIndex = 0
|
||||
|
||||
layoutManager.enumerateLineFragments(forGlyphRange: fullGlyphRange) {
|
||||
fragmentRect, _, _, _, _ in
|
||||
|
||||
if lineIndex % 2 == 1 {
|
||||
var stripeRect = fragmentRect
|
||||
stripeRect.origin.x = 0
|
||||
stripeRect.size.width = self.bounds.width
|
||||
stripeRect.origin.y += self.textContainerInset.height
|
||||
|
||||
// Only draw if the stripe intersects the dirty rect
|
||||
if stripeRect.intersects(rect) {
|
||||
stripeColor.setFill()
|
||||
NSBezierPath.fill(stripeRect)
|
||||
}
|
||||
}
|
||||
lineIndex += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - EditorTextView
|
||||
|
||||
/// A SwiftUI wrapper around NSTextView for the editor pane.
|
||||
/// Uses NSViewRepresentable to bridge AppKit's NSTextView into SwiftUI,
|
||||
/// providing line-level control, scroll position access, and performance
|
||||
@@ -9,6 +55,7 @@ struct EditorTextView: NSViewRepresentable {
|
||||
@Binding var text: String
|
||||
@Binding var scrollOffset: CGFloat
|
||||
var font: NSFont
|
||||
var alignment: NSTextAlignment = .left
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
Coordinator(self)
|
||||
@@ -22,7 +69,7 @@ struct EditorTextView: NSViewRepresentable {
|
||||
scrollView.borderType = .noBorder
|
||||
scrollView.drawsBackground = false
|
||||
|
||||
let textView = NSTextView()
|
||||
let textView = StripedTextView()
|
||||
textView.isEditable = true
|
||||
textView.isSelectable = true
|
||||
textView.allowsUndo = true
|
||||
@@ -33,11 +80,11 @@ struct EditorTextView: NSViewRepresentable {
|
||||
textView.isAutomaticTextReplacementEnabled = false
|
||||
textView.isAutomaticSpellingCorrectionEnabled = false
|
||||
|
||||
// Disable line wrapping — horizontal scroll instead
|
||||
textView.isHorizontallyResizable = true
|
||||
textView.textContainer?.widthTracksTextView = false
|
||||
// Enable line wrapping — tracks text view width
|
||||
textView.isHorizontallyResizable = false
|
||||
textView.textContainer?.widthTracksTextView = true
|
||||
textView.textContainer?.containerSize = NSSize(
|
||||
width: CGFloat.greatestFiniteMagnitude,
|
||||
width: 0,
|
||||
height: CGFloat.greatestFiniteMagnitude
|
||||
)
|
||||
textView.maxSize = NSSize(
|
||||
@@ -49,9 +96,12 @@ struct EditorTextView: NSViewRepresentable {
|
||||
textView.font = font
|
||||
textView.textColor = .textColor
|
||||
textView.backgroundColor = .clear
|
||||
textView.drawsBackground = false
|
||||
textView.drawsBackground = true
|
||||
textView.insertionPointColor = .textColor
|
||||
|
||||
// Set alignment
|
||||
textView.alignment = alignment
|
||||
|
||||
// Set the text
|
||||
textView.string = text
|
||||
|
||||
@@ -84,11 +134,19 @@ struct EditorTextView: NSViewRepresentable {
|
||||
// Update font if changed
|
||||
if textView.font != font {
|
||||
textView.font = font
|
||||
// Reapply font to entire text storage
|
||||
let range = NSRange(location: 0, length: textView.textStorage?.length ?? 0)
|
||||
textView.textStorage?.addAttribute(.font, value: font, range: range)
|
||||
}
|
||||
|
||||
// Update alignment if changed
|
||||
if textView.alignment != alignment {
|
||||
textView.alignment = alignment
|
||||
let range = NSRange(location: 0, length: textView.textStorage?.length ?? 0)
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.alignment = alignment
|
||||
textView.textStorage?.addAttribute(.paragraphStyle, value: paragraphStyle, range: range)
|
||||
}
|
||||
|
||||
// Update text only if it actually changed (avoid feedback loops)
|
||||
if textView.string != text {
|
||||
let selectedRanges = textView.selectedRanges
|
||||
|
||||
Reference in New Issue
Block a user