Skip to content

Commit 0224c8e

Browse files
authored
Merge pull request #8 from gin66/main
disable autocapitalization
2 parents 1789640 + c6fc42d commit 0224c8e

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

Sources/CodeEditor/UXCodeTextView.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,21 @@ final class UXCodeTextView: UXTextView {
142142
if coordinator.allowCopy { super.copy(sender) }
143143
}
144144

145-
145+
private var isAutoPairEnabled : Bool { return !autoPairCompletion.isEmpty }
146+
147+
#if os(iOS)
148+
override func insertText(_ text: String) {
149+
super.insertText(text)
150+
guard isAutoPairEnabled else { return }
151+
guard let end = autoPairCompletion[text] else { return }
152+
let prev = self.selectedRange
153+
super.insertText(end)
154+
self.selectedRange = prev
155+
}
156+
#endif
146157
#if os(macOS)
147158
// MARK: - Smarts as shown in https://github.com/naoty/NTYSmartTextView
148159

149-
private var isAutoPairEnabled : Bool { return !autoPairCompletion.isEmpty }
150-
151160
override func insertNewline(_ sender: Any?) {
152161
guard isSmartIndentEnabled else { return super.insertNewline(sender) }
153162

Sources/CodeEditor/UXCodeTextViewRepresentable.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
195195
textView.indentStyle = indentStyle
196196
textView.isSmartIndentEnabled = flags.contains(.smartIndent)
197197
textView.autoPairCompletion = autoPairs
198-
198+
199199
if source.wrappedValue != textView.string {
200200
if let textStorage = textView.codeTextStorage {
201201
textStorage.replaceCharacters(in : NSMakeRange(0, textStorage.length),
@@ -269,6 +269,10 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
269269
textView.autoresizingMask = [ .flexibleWidth, .flexibleHeight ]
270270
textView.delegate = context.coordinator
271271
textView.textContainerInset = edgeInsets
272+
#if os(iOS)
273+
textView.autocapitalizationType = .none
274+
textView.smartDashesType = .no
275+
#endif
272276
updateTextView(textView)
273277
return textView
274278
}

0 commit comments

Comments
 (0)