From ef262597d354147e48f4a695982c82e6b64219d9 Mon Sep 17 00:00:00 2001 From: Lightech Date: Tue, 25 Oct 2022 02:44:13 -0400 Subject: [PATCH] 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 --- .gitignore | 2 +- Sample.xcodeproj/project.pbxproj | 6 ++++-- Sample/ContentView.swift | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c00af33..caacec5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,5 @@ xcuserdata/ llvm-project/ libffi/ tools/ -LLVM.xcframework/ +LLVM**.xcframework/ diff --git a/Sample.xcodeproj/project.pbxproj b/Sample.xcodeproj/project.pbxproj index 8477fd9..5250c9e 100644 --- a/Sample.xcodeproj/project.pbxproj +++ b/Sample.xcodeproj/project.pbxproj @@ -317,7 +317,8 @@ ENABLE_PREVIEWS = YES; HEADER_SEARCH_PATHS = ""; INFOPLIST_FILE = Sample/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 14.1; + IPHONEOS_DEPLOYMENT_TARGET = 15.5; + "IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 15.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -347,7 +348,8 @@ ENABLE_PREVIEWS = YES; HEADER_SEARCH_PATHS = ""; INFOPLIST_FILE = Sample/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 14.1; + IPHONEOS_DEPLOYMENT_TARGET = 15.5; + "IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 15.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/Sample/ContentView.swift b/Sample/ContentView.swift index 8f07b21..3b40b09 100644 --- a/Sample/ContentView.swift +++ b/Sample/ContentView.swift @@ -40,6 +40,8 @@ int main() { VStack { Button("Interpret Sample Program", action: interpretSampleProgram) TextEditor(text: $program) + .disableAutocorrection(true) + .font(.body.monospaced()) }.tabItem { Image(systemName: "doc.plaintext") Text("Source code") @@ -60,6 +62,8 @@ int main() { .padding() HStack { TextEditor(text: $program) + .disableAutocorrection(true) + .font(.body.monospaced()) Divider() VStack { Text(compilationOutput) @@ -87,6 +91,19 @@ int main() { } } +// Disable smart quote (replacing ' and " with Unicode characters) as this prevents compilation +// https://stackoverflow.com/questions/66432017/disable-auto-replacement-of-punctuation-in-swiftui-texteditor +// 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). +// https://developer.apple.com/forums/thread/124410 +// Note that simply uncheck "Use smart quotes and dashes" does not work either. +extension UITextView { + open override var frame: CGRect { + didSet { + self.smartQuotesType = UITextSmartQuotesType.no + } + } +} + struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView()