From 4b9d589bcb234b3fdd2160a3abf02cf9b647f328 Mon Sep 17 00:00:00 2001 From: Lukas <134181853+bo2themax@users.noreply.github.com> Date: Mon, 10 Aug 2026 11:39:53 +0200 Subject: [PATCH] macOS: disable text selection on macOS 15 --- macos/Sources/Helpers/Backport.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/macos/Sources/Helpers/Backport.swift b/macos/Sources/Helpers/Backport.swift index 3dcbaa0c0..0b6c61ac1 100644 --- a/macos/Sources/Helpers/Backport.swift +++ b/macos/Sources/Helpers/Backport.swift @@ -132,8 +132,19 @@ enum BackportNSGlassStyle { #endif } -/// Backported `TextField` that supports text selection on macOS 15/iOS 18 and up. The `selection` -/// has no effect on versions below macOS 15/iOS 18. +/// Backported `TextField` that supports text selection on macOS 26/iOS 18 and up. The `selection` +/// has no effect on versions below macOS 26/iOS 18. +/// +/// Although the API is available from macOS 15, we force it to be 26. Because on macOS 15, +/// SwiftUI will crash when deleting texts, even for this simple example. +/// +/// struct ContentView: View { +/// @State private var text = "" +/// @State private var selection: TextSelection? +/// var body: some View { +/// TextField("Search", text: $text, selection: $selection) +/// } +/// } struct BackportSelectionTextField: View { private let titleKey: LocalizedStringKey @Binding private var text: String @@ -150,7 +161,7 @@ struct BackportSelectionTextField: View { } var body: some View { - if #available(iOS 18.0, macOS 15, *) { + if #available(iOS 18.0, macOS 26, *) { TextField( titleKey, text: _text,