Skip to content

Commit ef26259

Browse files
committed
Use monospace font in code editor and fix smart quote i.e. automatic replacement of ASCII single/double quote with Unicode quote characters which leads to issue when compiling string literal
1 parent 2d8cfac commit ef26259

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ xcuserdata/
1919
llvm-project/
2020
libffi/
2121
tools/
22-
LLVM.xcframework/
22+
LLVM**.xcframework/
2323

Sample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@
317317
ENABLE_PREVIEWS = YES;
318318
HEADER_SEARCH_PATHS = "";
319319
INFOPLIST_FILE = Sample/Info.plist;
320-
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
320+
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
321+
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 15.0;
321322
LD_RUNPATH_SEARCH_PATHS = (
322323
"$(inherited)",
323324
"@executable_path/Frameworks",
@@ -347,7 +348,8 @@
347348
ENABLE_PREVIEWS = YES;
348349
HEADER_SEARCH_PATHS = "";
349350
INFOPLIST_FILE = Sample/Info.plist;
350-
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
351+
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
352+
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 15.0;
351353
LD_RUNPATH_SEARCH_PATHS = (
352354
"$(inherited)",
353355
"@executable_path/Frameworks",

Sample/ContentView.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ int main() {
4040
VStack {
4141
Button("Interpret Sample Program", action: interpretSampleProgram)
4242
TextEditor(text: $program)
43+
.disableAutocorrection(true)
44+
.font(.body.monospaced())
4345
}.tabItem {
4446
Image(systemName: "doc.plaintext")
4547
Text("Source code")
@@ -60,6 +62,8 @@ int main() {
6062
.padding()
6163
HStack {
6264
TextEditor(text: $program)
65+
.disableAutocorrection(true)
66+
.font(.body.monospaced())
6367
Divider()
6468
VStack {
6569
Text(compilationOutput)
@@ -87,6 +91,19 @@ int main() {
8791
}
8892
}
8993

94+
// Disable smart quote (replacing ' and " with Unicode characters) as this prevents compilation
95+
// https://stackoverflow.com/questions/66432017/disable-auto-replacement-of-punctuation-in-swiftui-texteditor
96+
// This does not work on Mac Catalyst: change in System preferences > Keyboard > Text > for Double/Single Quotes, choose the last quote style (amongst the 8 possible types).
97+
// https://developer.apple.com/forums/thread/124410
98+
// Note that simply uncheck "Use smart quotes and dashes" does not work either.
99+
extension UITextView {
100+
open override var frame: CGRect {
101+
didSet {
102+
self.smartQuotesType = UITextSmartQuotesType.no
103+
}
104+
}
105+
}
106+
90107
struct ContentView_Previews: PreviewProvider {
91108
static var previews: some View {
92109
ContentView()

0 commit comments

Comments
 (0)