Skip to content
This repository was archived by the owner on Nov 7, 2026. It is now read-only.

Commit b7dbd8b

Browse files
Merge pull request #21 from code4teaching/keyboard-autofocus
Inspector: Tastatur nicht mehr automatisch öffnen
2 parents c1926fa + 38d3caf commit b7dbd8b

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎VisuStruct-iOS/VisuStructXcodeOpen/VisuStruct/ContentView.swift‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,9 @@ struct ContentView: View {
20072007
tabs[i].lineEditorText = el.textLines.joined(separator: "\n")
20082008
tabsModel.tabs = tabs
20092009

2010-
if !isPhone, focusedField == nil, el.type != .forSchleife {
2010+
if DiagramInspectorAutoFocus.shouldFocusOnSelection,
2011+
focusedField == nil,
2012+
el.type != .forSchleife {
20112013
focusedField = .textEditor
20122014
editorFocusToken = UUID()
20132015
}

‎VisuStruct-iOS/VisuStructXcodeOpen/VisuStruct/Editing/CodeLineEditor.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ private struct CodeLineEditorUIKit: UIViewRepresentable {
110110
tv.commitOnReturn = commitOnReturn
111111
tv.onCommit = onCommit
112112
tv.delegate = context.coordinator
113+
// Beim Erzeugen nicht fokussieren: Nur ein späterer Token-Wechsel holt die Tastatur.
114+
context.coordinator.lastFocusToken = focusToken
113115
return tv
114116
}
115117

‎VisuStruct-iOS/VisuStructXcodeOpen/VisuStruct/Supporting/DiagramEditorFocusTarget.swift‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import SwiftUI
2+
#if canImport(GameController)
3+
import GameController
4+
#endif
5+
#if canImport(UIKit)
6+
import UIKit
7+
#endif
28

39
/// Gemeinsame Fokus-Markierung für Diagrammtitel, Inspector-Felder und Zeileneditor.
410
enum DiagramEditorFocusTarget: Hashable {
@@ -8,3 +14,32 @@ enum DiagramEditorFocusTarget: Hashable {
814
/// Zählschleife: drei Kopf-Felder (Start / Bedingung / Schritt).
915
case forLoopPart(Int)
1016
}
17+
18+
/// Ob der Inspector nach einer Zeilenauswahl automatisch den Cursor bekommt.
19+
///
20+
/// Auf dem iPhone nie (zu wenig Platz). Auf dem Mac (Designed for iPad) immer.
21+
/// Auf dem iPad nur, wenn eine Hardware-Tastatur verbunden ist — sonst würde die
22+
/// Software-Tastatur das Diagramm verdecken.
23+
enum DiagramInspectorAutoFocus {
24+
static var shouldFocusOnSelection: Bool {
25+
if ProcessInfo.processInfo.isiOSAppOnMac {
26+
return true
27+
}
28+
#if canImport(UIKit)
29+
switch UIDevice.current.userInterfaceIdiom {
30+
case .phone:
31+
return false
32+
case .pad:
33+
#if canImport(GameController)
34+
return GCKeyboard.coalesced != nil
35+
#else
36+
return false
37+
#endif
38+
default:
39+
return false
40+
}
41+
#else
42+
return false
43+
#endif
44+
}
45+
}

0 commit comments

Comments
 (0)