Skip to content

Commit

Permalink
Merge pull request #32 from Condo97/main
Browse files Browse the repository at this point in the history
Added allowsUndo
  • Loading branch information
helje5 authored Jun 30, 2024
2 parents 3a92458 + b7db3f6 commit f5c076b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 9 additions & 3 deletions Sources/CodeEditor/CodeEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public struct CodeEditor: View {
indentStyle : IndentStyle = .system,
autoPairs : [ String : String ]? = nil,
inset : CGSize? = nil,
allowsUndo : Bool = true,
autoscroll : Bool = true)
{
self.source = source
Expand All @@ -251,7 +252,8 @@ public struct CodeEditor: View {
self.autoPairs = autoPairs
?? language.flatMap({ CodeEditor.defaultAutoPairs[$0] })
?? [:]
self.autoscroll = autoscroll
self.allowsUndo = allowsUndo
self.autoscroll = autoscroll
}

/**
Expand Down Expand Up @@ -286,7 +288,8 @@ public struct CodeEditor: View {
flags : Flags = .defaultViewerFlags,
indentStyle : IndentStyle = .system,
autoPairs : [ String : String ]? = nil,
inset : CGSize? = nil)
inset : CGSize? = nil,
allowsUndo : Bool = true)
{
assert(!flags.contains(.editable), "Editing requires a Binding")
self.init(source : .constant(source),
Expand All @@ -296,7 +299,8 @@ public struct CodeEditor: View {
flags : flags.subtracting(.editable),
indentStyle : indentStyle,
autoPairs : autoPairs,
inset : inset)
inset : inset,
allowsUndo : allowsUndo)
}

private var source : Binding<String>
Expand All @@ -308,6 +312,7 @@ public struct CodeEditor: View {
private let indentStyle : IndentStyle
private let autoPairs : [ String : String ]
private let inset : CGSize
private let allowsUndo : Bool
private let autoscroll : Bool

public var body: some View {
Expand All @@ -320,6 +325,7 @@ public struct CodeEditor: View {
indentStyle : indentStyle,
autoPairs : autoPairs,
inset : inset,
allowsUndo : allowsUndo,
autoscroll : autoscroll)
}
}
Expand Down
8 changes: 7 additions & 1 deletion Sources/CodeEditor/UXCodeTextViewRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
indentStyle : CodeEditor.IndentStyle,
autoPairs : [ String : String ],
inset : CGSize,
allowsUndo : Bool,
autoscroll : Bool)
{
self.source = source
Expand All @@ -64,6 +65,7 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
self.indentStyle = indentStyle
self.autoPairs = autoPairs
self.inset = inset
self.allowsUndo = allowsUndo
self.autoscroll = autoscroll
}

Expand All @@ -75,6 +77,7 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
private let flags : CodeEditor.Flags
private let indentStyle : CodeEditor.IndentStyle
private let inset : CGSize
private let allowsUndo : Bool
private let autoPairs : [ String : String ]
private let autoscroll : Bool

Expand Down Expand Up @@ -235,7 +238,7 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
let textView = UXCodeTextView()
textView.autoresizingMask = [ .width, .height ]
textView.delegate = context.coordinator
textView.allowsUndo = true
textView.allowsUndo = allowsUndo
textView.textContainerInset = inset

let scrollView = NSScrollView()
Expand Down Expand Up @@ -319,6 +322,7 @@ struct UXCodeTextViewRepresentable_Previews: PreviewProvider {
indentStyle : .system,
autoPairs : [:],
inset : .init(width: 8, height: 8),
allowsUndo : true,
autoscroll : false)
.frame(width: 200, height: 100)

Expand All @@ -331,6 +335,7 @@ struct UXCodeTextViewRepresentable_Previews: PreviewProvider {
indentStyle : .system,
autoPairs : [:],
inset : .init(width: 8, height: 8),
allowsUndo : true,
autoscroll : false)
.frame(width: 200, height: 100)

Expand All @@ -349,6 +354,7 @@ struct UXCodeTextViewRepresentable_Previews: PreviewProvider {
indentStyle : .system,
autoPairs : [:],
inset : .init(width: 8, height: 8),
allowsUndo : true,
autoscroll : false
)
.frame(width: 540, height: 200)
Expand Down

0 comments on commit f5c076b

Please sign in to comment.