Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion MarkdownViewer/ViewModels/DocumentState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Combine
import CoreGraphics
import Foundation
import Markdown
import SwiftUI

class DocumentState: ObservableObject {
@Published var htmlContent: String = ""
Expand Down Expand Up @@ -134,7 +135,9 @@ class DocumentState: ObservableObject {
guard let self = self else { return }
let newModDate = try? FileManager.default.attributesOfItem(atPath: url.path)[.modificationDate] as? Date
if newModDate != self.lastModificationDate {
self.fileChanged = true
self.lastModificationDate = newModDate
self.reload()
withAnimation(.easeInOut(duration: 0.2)) { self.fileChanged = true }
}
}

Expand Down
36 changes: 20 additions & 16 deletions MarkdownViewer/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ struct ContentView: View {
}
}
.onExitCommand {
if documentState.isShowingFindBar {
if documentState.fileChanged {
withAnimation(.easeInOut(duration: 0.2)) { documentState.fileChanged = false }
} else if documentState.isShowingFindBar {
documentState.hideFindBar()
}
}
Expand Down Expand Up @@ -110,22 +112,24 @@ struct ContentView: View {
if documentState.fileChanged || documentState.isShowingFindBar {
VStack(alignment: .trailing, spacing: 8) {
if documentState.fileChanged {
Button(action: {
documentState.reload()
}) {
HStack(spacing: 4) {
Image(systemName: "arrow.clockwise")
.font(.system(size: 11, weight: .medium))
Text("File changed")
.font(.system(size: 11, weight: .medium))
}
.padding(.horizontal, 10)
.padding(.vertical, 6)
.background(Color.orange.opacity(0.9))
.foregroundColor(.white)
.cornerRadius(6)
HStack(spacing: 6) {
Image(systemName: "arrow.triangle.2.circlepath")
.font(.system(size: 11, weight: .medium))
Text("File updated")
.font(.system(size: 11, weight: .medium))
Text("esc to dismiss")
.font(.system(size: 10))
.opacity(0.7)
}
.padding(.horizontal, 10)
.padding(.vertical, 6)
.background(Color.accentColor.opacity(0.85))
.foregroundColor(.white)
.cornerRadius(6)
.onTapGesture {
withAnimation(.easeInOut(duration: 0.2)) { documentState.fileChanged = false }
}
.buttonStyle(.plain)
.transition(.opacity.combined(with: .move(edge: .top)))
}

if documentState.isShowingFindBar {
Expand Down