Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions freewrite/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ struct ContentView: View {
@State private var isHoveringHistoryText = false
@State private var isHoveringHistoryPath = false
@State private var isHoveringHistoryArrow = false
@State private var isHoveringBackspaceToggle = false
@State private var isBackspaceDisabled = false
@State private var colorScheme: ColorScheme = .light // Add state for color scheme
@State private var isHoveringThemeToggle = false // Add state for theme toggle hover
@State private var didCopyPrompt: Bool = false // Add state for copy prompt feedback
Expand Down Expand Up @@ -382,6 +384,8 @@ struct ContentView: View {
return colorScheme == .light ? Color.primary : Color.white
}

@State private var viewHeight: CGFloat = 0

var body: some View {
let buttonBackground = colorScheme == .light ? Color.white : Color.black
let navHeight: CGFloat = 68
Expand All @@ -394,24 +398,32 @@ struct ContentView: View {
Color(colorScheme == .light ? .white : .black)
.ignoresSafeArea()

TextEditor(text: Binding(
get: { text },
set: { newValue in
// Ensure the text always starts with two newlines
if !newValue.hasPrefix("\n\n") {
text = "\n\n" + newValue.trimmingCharacters(in: .newlines)
} else {
text = newValue

TextEditor(text: Binding(
get: { text },
set: { newValue in
// Prevent backspace if disabled
if isBackspaceDisabled && newValue.count < text.count {
return
}

// Ensure the text always starts with two newlines
if !newValue.hasPrefix("\n\n") {
text = "\n\n" + newValue.trimmingCharacters(in: .newlines)
} else {
text = newValue
}
}
}
))
))
.background(Color(colorScheme == .light ? .white : .black))
.font(.custom(selectedFont, size: fontSize))
.foregroundColor(colorScheme == .light ? Color(red: 0.20, green: 0.20, blue: 0.20) : Color(red: 0.9, green: 0.9, blue: 0.9))
.scrollContentBackground(.hidden)
.scrollIndicators(.never)
.lineSpacing(lineHeight)
.frame(maxWidth: 650)


.id("\(selectedFont)-\(fontSize)-\(colorScheme)")
.padding(.bottom, bottomNavOpacity > 0 ? navHeight : 0)
.ignoresSafeArea()
Expand All @@ -426,13 +438,20 @@ struct ContentView: View {
Text(placeholderText)
.font(.custom(selectedFont, size: fontSize))
.foregroundColor(colorScheme == .light ? .gray.opacity(0.5) : .gray.opacity(0.6))
// .padding(.top, 8)
// .padding(.leading, 8)
// .padding(.top, 8)
// .padding(.leading, 8)
.allowsHitTesting(false)
.offset(x: 5, y: placeholderOffset)
}
}, alignment: .topLeading
)
.onGeometryChange(for: CGFloat.self) { proxy in
proxy.size.height
} action: { height in
viewHeight = height
}
.contentMargins(.bottom, viewHeight / 4)


VStack {
Spacer()
Expand Down Expand Up @@ -803,6 +822,28 @@ struct ContentView: View {
}
}

Text("•")
.foregroundColor(.gray)

// Backspace toggle button - disable the use of backspace
Button(action: {
isBackspaceDisabled.toggle()
}) {
Text(isBackspaceDisabled ? "←" : "⌫")
.font(.system(size: 13))
}
.buttonStyle(.plain)
.foregroundColor(isHoveringBackspaceToggle ? textHoverColor : textColor)
.onHover { hovering in
isHoveringBackspaceToggle = hovering
isHoveringBottomNav = hovering
if hovering {
NSCursor.pointingHand.push()
} else {
NSCursor.pop()
}
}

Text("•")
.foregroundColor(.gray)

Expand Down Expand Up @@ -1399,4 +1440,4 @@ extension NSView {

#Preview {
ContentView()
}
}