Skip to content

Commit

Permalink
Use monospace font in code editor and fix smart quote i.e. automatic …
Browse files Browse the repository at this point in the history
…replacement of ASCII single/double quote with Unicode quote characters which leads to issue when compiling string literal
  • Loading branch information
light-tech committed Oct 25, 2022
1 parent 2d8cfac commit ef26259
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ xcuserdata/
llvm-project/
libffi/
tools/
LLVM.xcframework/
LLVM**.xcframework/

6 changes: 4 additions & 2 deletions Sample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions Sample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -60,6 +62,8 @@ int main() {
.padding()
HStack {
TextEditor(text: $program)
.disableAutocorrection(true)
.font(.body.monospaced())
Divider()
VStack {
Text(compilationOutput)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ef26259

Please sign in to comment.