@@ -89,8 +89,11 @@ struct CustomCommandView: View {
8989 . contextMenu {
9090 Button ( " Remove " ) {
9191 settings. customCommands. removeAll (
92- where: { $0. name == command. name }
92+ where: { $0. id == command. id }
9393 )
94+ if let editingCommand, editingCommand. command. id == command. id {
95+ self . editingCommand = nil
96+ }
9497 }
9598 }
9699 }
@@ -154,6 +157,7 @@ struct EditCustomCommandView: View {
154157 @State var prompt : String
155158 @State var systemPrompt : String
156159 @State var continuousMode : Bool
160+ @State var editingContentInFullScreen : Binding < String > ?
157161
158162 enum CommandType : Int , CaseIterable {
159163 case chatWithSelection
@@ -218,9 +222,9 @@ struct EditCustomCommandView: View {
218222 systemPromptTextField ( title: " Extra System Prompt " )
219223 promptTextField
220224 case . promptToCode:
225+ continuousModeToggle
221226 systemPromptTextField ( title: " Extra System Prompt " )
222227 promptTextField
223- continuousModeToggle
224228 case . customChat:
225229 systemPromptTextField ( )
226230 promptTextField
@@ -238,7 +242,7 @@ struct EditCustomCommandView: View {
238242
239243 HStack {
240244 Spacer ( )
241- Button ( " Cancel " ) {
245+ Button ( " Close " ) {
242246 editingCommand = nil
243247 }
244248
@@ -275,10 +279,13 @@ struct EditCustomCommandView: View {
275279 return
276280 }
277281 settings. customCommands. append ( newCommand)
278- editingCommand = nil
282+ editingCommand? . isNew = false
283+ editingCommand? . command = newCommand
284+
285+ toast ( Text ( " The command is created. " ) , . info)
279286 }
280287 } else {
281- Button ( " Update " ) {
288+ Button ( " Save " ) {
282289 guard !settings. illegalNames. contains ( newCommand. name)
283290 || newCommand. name == originalName
284291 else {
@@ -297,7 +304,8 @@ struct EditCustomCommandView: View {
297304 } else {
298305 settings. customCommands. append ( newCommand)
299306 }
300- editingCommand = nil
307+
308+ toast ( Text ( " The command is updated. " ) , . info)
301309 }
302310 }
303311 }
@@ -306,23 +314,42 @@ struct EditCustomCommandView: View {
306314 }
307315 . padding ( . bottom)
308316 . background ( . regularMaterial)
317+ . sheet ( isPresented: . init( get: { editingContentInFullScreen != nil } , set: {
318+ if $0 == false {
319+ editingContentInFullScreen = nil
320+ }
321+ } ) , content: {
322+ VStack {
323+ if let editingContentInFullScreen {
324+ TextEditor ( text: editingContentInFullScreen)
325+ . font ( Font . system ( . body, design: . monospaced) )
326+ . padding ( 4 )
327+ . frame ( minHeight: 120 )
328+ . multilineTextAlignment ( . leading)
329+ . overlay (
330+ RoundedRectangle ( cornerRadius: 4 )
331+ . stroke ( Color ( nsColor: . separatorColor) , lineWidth: 1 )
332+ )
333+ }
334+
335+ Button ( action: {
336+ editingContentInFullScreen = nil
337+ } ) {
338+ Text ( " Done " )
339+ }
340+ }
341+ . padding ( )
342+ . frame ( width: 600 , height: 500 )
343+ . background ( Color ( nsColor: . windowBackgroundColor) )
344+ } )
309345 }
310346 }
311347
312348 @ViewBuilder
313349 var promptTextField : some View {
314350 VStack ( alignment: . leading, spacing: 4 ) {
315351 Text ( " Prompt " )
316- TextEditor ( text: $prompt)
317- . font ( Font . system ( . body, design: . monospaced) )
318- . padding ( 2 )
319- . frame ( minHeight: 120 )
320- . multilineTextAlignment ( . leading)
321- . overlay (
322- RoundedRectangle ( cornerRadius: 1 )
323- . stroke ( . black, lineWidth: 1 / 3 )
324- . opacity ( 0.3 )
325- )
352+ editableText ( $prompt)
326353 }
327354 . padding ( . vertical, 4 )
328355 }
@@ -331,23 +358,46 @@ struct EditCustomCommandView: View {
331358 func systemPromptTextField( title: String ? = nil ) -> some View {
332359 VStack ( alignment: . leading, spacing: 4 ) {
333360 Text ( title ?? " System Prompt " )
334- TextEditor ( text: $systemPrompt)
335- . font ( Font . system ( . body, design: . monospaced) )
336- . padding ( 2 )
337- . frame ( minHeight: 120 )
338- . multilineTextAlignment ( . leading)
339- . overlay (
340- RoundedRectangle ( cornerRadius: 1 )
341- . stroke ( . black, lineWidth: 1 / 3 )
342- . opacity ( 0.3 )
343- )
361+ editableText ( $systemPrompt)
344362 }
345363 . padding ( . vertical, 4 )
346364 }
347365
348366 var continuousModeToggle : some View {
349367 Toggle ( " Continuous Mode " , isOn: $continuousMode)
350368 }
369+
370+ func editableText( _ binding: Binding < String > ) -> some View {
371+ Button ( action: {
372+ editingContentInFullScreen = binding
373+ } ) {
374+ HStack ( alignment: . top) {
375+ Text ( binding. wrappedValue)
376+ . font ( Font . system ( . body, design: . monospaced) )
377+ . padding ( 4 )
378+ . multilineTextAlignment ( . leading)
379+ . frame ( maxWidth: . infinity, alignment: . leading)
380+ . background {
381+ RoundedRectangle ( cornerRadius: 4 )
382+ . fill ( Color ( nsColor: . textBackgroundColor) )
383+ }
384+ . overlay {
385+ RoundedRectangle ( cornerRadius: 4 )
386+ . stroke ( Color ( nsColor: . separatorColor) , style: . init( lineWidth: 1 ) )
387+ }
388+ Image ( systemName: " square.and.pencil " )
389+ . resizable ( )
390+ . scaledToFit ( )
391+ . frame ( width: 14 )
392+ . padding ( 4 )
393+ . background (
394+ Color . primary. opacity ( 0.1 ) ,
395+ in: RoundedRectangle ( cornerRadius: 4 )
396+ )
397+ }
398+ }
399+ . buttonStyle ( . plain)
400+ }
351401}
352402
353403// MARK: - Previews
0 commit comments