@@ -88,6 +88,22 @@ struct CodeActionsTopBar: View {
8888 ToolbarItem ( placement: . status) {
8989 if viewModel. remoteURL != nil {
9090 Button ( action: viewModel. openRemoteURL) {
91+ Image ( systemName: " curlybraces.square " )
92+ }
93+ . help ( NSLocalizedString ( " Open_Post " , comment: " " ) )
94+ . onHover { inside in
95+ if inside {
96+ NSCursor . pointingHand. push ( )
97+ } else {
98+ NSCursor . pop ( )
99+ }
100+ }
101+ }
102+ }
103+
104+ ToolbarItem ( placement: . status) {
105+ if viewModel. snipCode. count > 0 {
106+ Button ( action: viewModel. shareCode) {
91107 Image ( systemName: " square.and.arrow.up " )
92108 }
93109 . help ( NSLocalizedString ( " Open_Post " , comment: " " ) )
@@ -202,6 +218,8 @@ final class CodeActionsViewModel: ObservableObject {
202218 @Published var remoteURL : String ?
203219 @Published var isPreviewAvailable : Bool = false
204220
221+ var snipMode : String = " text "
222+
205223 var onRename : ( String ) -> Void
206224 var onToggleFavorite : ( ) -> Void
207225 var onDelete : ( ) -> Void
@@ -235,6 +253,7 @@ final class CodeActionsViewModel: ObservableObject {
235253 this. snipLastUpdate = snipItem. lastUpdateDate
236254 this. syncState = snipItem. syncState ?? . local
237255 this. remoteURL = snipItem. remoteURL
256+ this. snipMode = snipItem. mode. name
238257 this. isPreviewAvailable = snipItem. mode == CodeMode . html. mode ( ) || snipItem. mode == CodeMode . markdown. mode ( )
239258 }
240259 }
@@ -249,6 +268,16 @@ final class CodeActionsViewModel: ObservableObject {
249268 NSWorkspace . shared. open ( url)
250269 }
251270
271+ func shareCode( ) {
272+ let baseURL = " https://carbon.now.sh/?bg=rgba%28171%2C+184%2C+195%2C+1%29&t=blackboard&wt=none&l= \( snipMode) &ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=56px&ph=56px&ln=false&fl=1&fm=Hack&fs=14px&lh=133%25&si=false&es=2x&wm=false&code= "
273+
274+ if let escapedCode = snipCode. addingPercentEncoding ( withAllowedCharacters: NSCharacterSet . urlQueryAllowed) ,
275+ let doubleEscapedCode = escapedCode. addingPercentEncoding ( withAllowedCharacters: NSCharacterSet . urlQueryAllowed) ,
276+ let carbonURL = URL ( string: " \( baseURL) \( doubleEscapedCode) " ) {
277+ NSWorkspace . shared. open ( carbonURL)
278+ }
279+ }
280+
252281 func toggleSidebar( ) {
253282 NSApp . keyWindow? . firstResponder? . tryToPerform ( #selector( NSSplitViewController . toggleSidebar ( _: ) ) , with: nil )
254283 }
0 commit comments