File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { MonacoEmptyMock } from "./monaco-mock-empty";
5
5
import { register } from "./monaco-utils" ;
6
6
import { __dangerous__lastFormattedValue__global } from "@code-editor/prettier-services" ;
7
7
import { debounce } from "utils/debounce" ;
8
+ import { downloadFile } from "utils/download" ;
8
9
9
10
type ICodeEditor = monaco . editor . IStandaloneCodeEditor ;
10
11
@@ -57,13 +58,7 @@ export function MonacoEditor(props: MonacoEditorProps) {
57
58
contextMenuGroupId : "navigation" ,
58
59
contextMenuOrder : 1.5 ,
59
60
run : function ( ed ) {
60
- var data = new Blob ( [ ed . getModel ( ) . getValue ( ) ] , { type : "text/txt" } ) ;
61
- var csvURL = window . URL . createObjectURL ( data ) ;
62
- const tempLink = document . createElement ( "a" ) ;
63
- tempLink . href = csvURL ;
64
- tempLink . setAttribute ( "download" , path ) ;
65
- tempLink . click ( ) ;
66
- tempLink . remove ( ) ;
61
+ downloadFile ( { data : ed . getModel ( ) . getValue ( ) , filename : path } ) ;
67
62
} ,
68
63
} ) ;
69
64
Original file line number Diff line number Diff line change
1
+ export function downloadFile ( {
2
+ data,
3
+ filename,
4
+ } : {
5
+ data : string ;
6
+ filename : string ;
7
+ } ) {
8
+ var blob = new Blob ( [ data ] , { type : "text/txt" } ) ;
9
+ var csvURL = window . URL . createObjectURL ( blob ) ;
10
+ const tempLink = document . createElement ( "a" ) ;
11
+ tempLink . href = csvURL ;
12
+ tempLink . setAttribute ( "download" , filename ) ;
13
+ tempLink . click ( ) ;
14
+ tempLink . remove ( ) ;
15
+ }
You can’t perform that action at this time.
0 commit comments