Skip to content

Commit

Permalink
feat(PlantUML+OpenAI.swift): add clear k LILOQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Apr 1, 2023
1 parent 2911f42 commit 2b30ddc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions PlantUML/PlantUML+OpenAI.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SwiftUIView.swift
// PlantUML+OpenAI.swift
//
//
// Created by Bartolomeo Sorrentino on 29/03/23.
Expand Down Expand Up @@ -45,6 +45,10 @@ class LILOQueue<T> {
return elements.removeLast()
}

func clear() {
elements.removeAll()
}

}

class OpenAIService : ObservableObject {
Expand Down Expand Up @@ -118,16 +122,12 @@ struct OpenAIView : View {

@ObservedObject var service:OpenAIService
@Binding var result: String
@State var input:String = """
@startuml
@enduml
"""
@State var input:String
@State var instruction:String = ""
@State private var tabs: Tab = .Input

var onUndo:(() -> Void)

var isEditing:Bool {
if case .Editing = service.status {
return true
Expand Down Expand Up @@ -165,6 +165,7 @@ struct OpenAIView : View {
.padding( EdgeInsets(top: 0, leading: 5, bottom: 5, trailing: 0))

}

}

// MARK: Input Extension
Expand Down Expand Up @@ -200,7 +201,7 @@ extension OpenAIView {
Task {
if let res = await service.generateEdit( input: input, instruction: instruction ) {
service.status = .Ready
service.clipboard.push( result )
service.clipboard.push( result.isEmpty ? input : result )
service.prompt.push( instruction )

result = res
Expand Down Expand Up @@ -267,6 +268,7 @@ struct OpenAIView_Previews: PreviewProvider {
static var previews: some View {
OpenAIView( service: OpenAIService(),
result: Binding.constant(""),
input: "",
onUndo: { } )
.frame(height: 200)
}
Expand Down

0 comments on commit 2b30ddc

Please sign in to comment.