@@ -929,11 +929,16 @@ struct ContentView: View {
929929
930930 // MARK: - Inspector (unter dem Canvas)
931931
932+ private var selectedElement : VisuStructElement ? {
933+ guard let path = selectedPath else { return nil }
934+ return try? VisuStructDocumentEditing . element ( at : path , in : document )
935+ }
936+
932937 private var inspectorFallauswahlToolbar : InspectorFallauswahlToolbarContext ? {
933- guard let faPath = multiwayAncestorPath ( for : selectedPath ) else { return nil }
938+ guard let faPath = VisuStructDocumentEditing . multiwayAncestorPath ( for : selectedPath , in : document ) else { return nil }
934939 let faCaseCount =
935940 ( try? VisuStructDocumentEditing . element ( at : faPath , in : document ) ) ? . cases ? . count ?? 0
936- let removeCaseIdx = selectedCaseIndex ( multiwayPath : faPath , selectedPath : selectedPath )
941+ let removeCaseIdx = VisuStructDocumentEditing . caseIndex ( of : selectedPath , inMultiwayAt : faPath )
937942 return InspectorFallauswahlToolbarContext (
938943 caseCount : faCaseCount ,
939944 removeCaseIndex : removeCaseIdx ,
@@ -981,8 +986,14 @@ struct ContentView: View {
981986 lineEditorVisibleTextBinding : lineEditorVisibleTextBinding ,
982987 editorFocusToken : editorFocusToken ,
983988 lineEditorFixedPrefixLabel : lineEditorFixedPrefixLabel ,
984- inspectorConditionEditorHintLine : inspectorConditionEditorHintLine ( ) ,
985- inspectorLineEditorPlaceholder : inspectorLineEditorPlaceholder ( ) ,
989+ inspectorConditionEditorHintLine : selectedElement . flatMap { InspectorElementHints . conditionHintLine ( for : $0 . type ) } ,
990+ inspectorLineEditorPlaceholder : selectedElement . flatMap {
991+ InspectorElementHints . lineEditorPlaceholder (
992+ for : $0 . type ,
993+ ioMode : VisuStructLineEditorText . ioMode ( of : tabsModel . currentTab . lineEditorText ) ,
994+ lang : lang
995+ )
996+ } ,
986997 fallauswahl : inspectorFallauswahlToolbar ,
987998 onApplyLineEditor : applyLineEditor ,
988999 onApplyRespectingFocus : applyLineEditorRespectingTextFocus ,
@@ -1008,63 +1019,6 @@ struct ContentView: View {
10081019 )
10091020 }
10101021
1011- private func statementIOModeIfApplicable ( ) -> StatementIOMode ? {
1012- guard let path = selectedPath ,
1013- let el = try? VisuStructDocumentEditing . element ( at : path , in : document ) ,
1014- el . type == . anweisung else { return nil }
1015-
1016- return VisuStructLineEditorText . ioMode ( of : tabsModel . currentTab . lineEditorText )
1017- }
1018-
1019- /// Placeholder for the line editor, shown only when empty (grau im Feld). Code-Beispiele als Hilfe: `inspectorConditionEditorHintLine()` darüber.
1020- private func inspectorLineEditorPlaceholder ( ) -> String ? {
1021- guard let path = selectedPath ,
1022- let el = try? VisuStructDocumentEditing . element ( at : path , in : document ) else { return nil }
1023-
1024- switch el . type {
1025- case . anweisung :
1026- switch VisuStructLineEditorText . ioMode ( of : tabsModel . currentTab . lineEditorText ) {
1027- case . statement :
1028- return lang . tr ( " inspector_placeholder_statement " )
1029- case . input :
1030- return " int age \" Enter age \" "
1031- case . output :
1032- return " \" Your age: \" + age "
1033- }
1034- case . forSchleife :
1035- return nil
1036- case . verzweigung , . whileSchleife , . doUntilSchleife , . endlosschleife :
1037- return lang . tr ( " inspector_placeholder_condition " )
1038- case . fallauswahl :
1039- return lang . tr ( " inspector_placeholder_selector " )
1040- case . aufruf :
1041- return lang . tr ( " inspector_placeholder_call " )
1042- case . aussprung :
1043- return lang . tr ( " inspector_placeholder_break " )
1044- case . leerElement :
1045- return nil
1046- }
1047- }
1048-
1049- /// Sichtbare Hilfszeile über dem Bedingungs-Editor (wie Statement-Hinweis unter dem Modus-Picker) — Englisch, code-like.
1050- private func inspectorConditionEditorHintLine ( ) -> String ? {
1051- guard let path = selectedPath ,
1052- let el = try? VisuStructDocumentEditing . element ( at : path , in : document ) else { return nil }
1053- switch el . type {
1054- case . verzweigung :
1055- return " age >= 18 "
1056- case . whileSchleife :
1057- return " i < 10 "
1058- case . doUntilSchleife :
1059- return " again == 1 "
1060- case . fallauswahl :
1061- // Ausdruck in Klammern: switch (day) { … } — gleicher Stil wie die anderen Hinweise (englisch, code-nah).
1062- return " day "
1063- default :
1064- return nil
1065- }
1066- }
1067-
10681022 // MARK: - Inspector (iPhone: ein-/ausblendbar)
10691023
10701024 private var inspectorPanelPhoneAware : some View {
@@ -1106,20 +1060,6 @@ struct ContentView: View {
11061060
11071061 // MARK: - Fallauswahl (Multiway)
11081062
1109- /// Innerste **Fallauswahl** (`multiway`), die die aktuelle Auswahl enthält (für „Fall hinzufügen“).
1110- private func multiwayAncestorPath ( for path : [ Int ] ? ) -> [ Int ] ? {
1111- guard let path , ! path . isEmpty else { return nil }
1112- let doc = document
1113- for len in stride ( from : path . count , through : 1 , by : - 1 ) {
1114- let prefix = Array ( path . prefix ( len ) )
1115- if let el = try? VisuStructDocumentEditing . element ( at : prefix , in : doc ) ,
1116- el . type == . fallauswahl {
1117- return prefix
1118- }
1119- }
1120- return nil
1121- }
1122-
11231063 private func addCaseToFallauswahl ( at fallPath : [ Int ] ) {
11241064 do {
11251065 let ( updated , newPath ) = try VisuStructDocumentEditing . appendCaseToFallauswahl ( document , fallauswahlPath : fallPath )
@@ -1131,12 +1071,6 @@ struct ContentView: View {
11311071 }
11321072 }
11331073
1134- /// Spaltenindex der Fallauswahl, wenn die Auswahl **in** einer Spalte liegt (`[…, fall, spalte, …]`).
1135- private func selectedCaseIndex ( multiwayPath : [ Int ] , selectedPath : [ Int ] ? ) -> Int ? {
1136- guard let sp = selectedPath , sp . count > multiwayPath . count else { return nil }
1137- return sp [ multiwayPath . count ]
1138- }
1139-
11401074 private func removeCaseFromFallauswahl ( at fallPath : [ Int ] , caseIndex : Int ) {
11411075 do {
11421076 let ( updated , newPath ) = try VisuStructDocumentEditing . removeCaseFromFallauswahl (
@@ -1152,7 +1086,7 @@ struct ContentView: View {
11521086
11531087 /// Bindung für den **Fallnamen**, wenn die Auswahl in einer Spalte einer Fallauswahl liegt (nicht beim bloßen Kopf `[n]` ohne Folgeindex).
11541088 private func multiwayCaseLabelBinding ( ) -> Binding < String > ? {
1155- guard let fa = multiwayAncestorPath ( for : selectedPath ) ,
1089+ guard let fa = VisuStructDocumentEditing . multiwayAncestorPath ( for : selectedPath , in : document ) ,
11561090 let sp = selectedPath ,
11571091 sp . count > fa . count else { return nil }
11581092 let caseIdx = sp [ fa . count ]
0 commit comments