Undo WIP
This commit is contained in:
@@ -185,8 +185,10 @@ struct MarkdownEditor: NSViewRepresentable {
|
||||
textView.font = NSFont.monospacedSystemFont(ofSize: 14, weight: .regular)
|
||||
textView.textColor = NSColor.textColor
|
||||
textView.backgroundColor = NSColor.textBackgroundColor
|
||||
textView.allowsUndo = true
|
||||
textView.string = text
|
||||
|
||||
|
||||
// Properly set up the scroll view hierarchy first
|
||||
scrollView.borderType = .noBorder
|
||||
scrollView.hasVerticalScroller = true
|
||||
@@ -217,6 +219,7 @@ struct MarkdownEditor: NSViewRepresentable {
|
||||
|
||||
if textView.string != text {
|
||||
print("MarkdownEditor: Updating text from \(textView.string.count) to \(text.count) characters")
|
||||
|
||||
textView.string = text
|
||||
}
|
||||
}
|
||||
@@ -244,4 +247,4 @@ struct MarkdownEditor: NSViewRepresentable {
|
||||
|
||||
#Preview {
|
||||
ContentView()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,20 @@ struct MarkdownViewerApp: App {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CommandGroup(replacing: .undoRedo) {
|
||||
Button("Undo") {
|
||||
print("Menu: Undo clicked, sending action to: \(NSApp.keyWindow?.firstResponder?.className ?? "nil")")
|
||||
NSApp.sendAction(#selector(UndoManager.undo), to: nil, from: nil)
|
||||
}
|
||||
.keyboardShortcut("z", modifiers: .command)
|
||||
|
||||
Button("Redo") {
|
||||
print("Menu: Redo clicked, sending action to: \(NSApp.keyWindow?.firstResponder?.className ?? "nil")")
|
||||
NSApp.sendAction(#selector(UndoManager.redo), to: nil, from: nil)
|
||||
}
|
||||
.keyboardShortcut("z", modifiers: [.command, .shift])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user