Skip to content

Commit f5c076b

Browse files
authored
Merge pull request #32 from Condo97/main
Added allowsUndo
2 parents 3a92458 + b7db3f6 commit f5c076b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Sources/CodeEditor/CodeEditor.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public struct CodeEditor: View {
238238
indentStyle : IndentStyle = .system,
239239
autoPairs : [ String : String ]? = nil,
240240
inset : CGSize? = nil,
241+
allowsUndo : Bool = true,
241242
autoscroll : Bool = true)
242243
{
243244
self.source = source
@@ -251,7 +252,8 @@ public struct CodeEditor: View {
251252
self.autoPairs = autoPairs
252253
?? language.flatMap({ CodeEditor.defaultAutoPairs[$0] })
253254
?? [:]
254-
self.autoscroll = autoscroll
255+
self.allowsUndo = allowsUndo
256+
self.autoscroll = autoscroll
255257
}
256258

257259
/**
@@ -286,7 +288,8 @@ public struct CodeEditor: View {
286288
flags : Flags = .defaultViewerFlags,
287289
indentStyle : IndentStyle = .system,
288290
autoPairs : [ String : String ]? = nil,
289-
inset : CGSize? = nil)
291+
inset : CGSize? = nil,
292+
allowsUndo : Bool = true)
290293
{
291294
assert(!flags.contains(.editable), "Editing requires a Binding")
292295
self.init(source : .constant(source),
@@ -296,7 +299,8 @@ public struct CodeEditor: View {
296299
flags : flags.subtracting(.editable),
297300
indentStyle : indentStyle,
298301
autoPairs : autoPairs,
299-
inset : inset)
302+
inset : inset,
303+
allowsUndo : allowsUndo)
300304
}
301305

302306
private var source : Binding<String>
@@ -308,6 +312,7 @@ public struct CodeEditor: View {
308312
private let indentStyle : IndentStyle
309313
private let autoPairs : [ String : String ]
310314
private let inset : CGSize
315+
private let allowsUndo : Bool
311316
private let autoscroll : Bool
312317

313318
public var body: some View {
@@ -320,6 +325,7 @@ public struct CodeEditor: View {
320325
indentStyle : indentStyle,
321326
autoPairs : autoPairs,
322327
inset : inset,
328+
allowsUndo : allowsUndo,
323329
autoscroll : autoscroll)
324330
}
325331
}

Sources/CodeEditor/UXCodeTextViewRepresentable.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
5353
indentStyle : CodeEditor.IndentStyle,
5454
autoPairs : [ String : String ],
5555
inset : CGSize,
56+
allowsUndo : Bool,
5657
autoscroll : Bool)
5758
{
5859
self.source = source
@@ -64,6 +65,7 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
6465
self.indentStyle = indentStyle
6566
self.autoPairs = autoPairs
6667
self.inset = inset
68+
self.allowsUndo = allowsUndo
6769
self.autoscroll = autoscroll
6870
}
6971

@@ -75,6 +77,7 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
7577
private let flags : CodeEditor.Flags
7678
private let indentStyle : CodeEditor.IndentStyle
7779
private let inset : CGSize
80+
private let allowsUndo : Bool
7881
private let autoPairs : [ String : String ]
7982
private let autoscroll : Bool
8083

@@ -235,7 +238,7 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
235238
let textView = UXCodeTextView()
236239
textView.autoresizingMask = [ .width, .height ]
237240
textView.delegate = context.coordinator
238-
textView.allowsUndo = true
241+
textView.allowsUndo = allowsUndo
239242
textView.textContainerInset = inset
240243

241244
let scrollView = NSScrollView()
@@ -319,6 +322,7 @@ struct UXCodeTextViewRepresentable_Previews: PreviewProvider {
319322
indentStyle : .system,
320323
autoPairs : [:],
321324
inset : .init(width: 8, height: 8),
325+
allowsUndo : true,
322326
autoscroll : false)
323327
.frame(width: 200, height: 100)
324328

@@ -331,6 +335,7 @@ struct UXCodeTextViewRepresentable_Previews: PreviewProvider {
331335
indentStyle : .system,
332336
autoPairs : [:],
333337
inset : .init(width: 8, height: 8),
338+
allowsUndo : true,
334339
autoscroll : false)
335340
.frame(width: 200, height: 100)
336341

@@ -349,6 +354,7 @@ struct UXCodeTextViewRepresentable_Previews: PreviewProvider {
349354
indentStyle : .system,
350355
autoPairs : [:],
351356
inset : .init(width: 8, height: 8),
357+
allowsUndo : true,
352358
autoscroll : false
353359
)
354360
.frame(width: 540, height: 200)

0 commit comments

Comments
 (0)