@@ -12,18 +12,21 @@ const extractOptions: readonly ExtractOption[] = [
12
12
export async function extractImages ( arg : unknown , inputImageSrc : ImageSrc | undefined ) {
13
13
if ( ! ( arg instanceof Uri && arg . scheme === 'file' ) ) return
14
14
15
- const shouldIgnoreWarnings = inputImageSrc != null
15
+ const editor = window . visibleTextEditors . find ( x => x . document . fileName === arg . fsPath )
16
+ const textDocument = editor ?. document ?? workspace . textDocuments . find ( x => x . fileName === arg . fsPath )
17
+
18
+ if ( ! textDocument ) return
19
+ await textDocument . save ( )
20
+
16
21
const markdown = ( await workspace . fs . readFile ( arg ) ) . toString ( )
17
22
const extractor = new MarkdownImagesExtractor ( markdown , arg )
23
+
18
24
const images = extractor . findImages ( )
25
+ if ( images . length <= 0 )
26
+ void ( ! inputImageSrc != null ? window . showWarningMessage ( '没有找到可以提取的图片' ) : undefined )
27
+
19
28
const availableWebImagesCount = images . filter ( newImageSrcFilter ( ImageSrc . web ) ) . length
20
29
const availableLocalImagesCount = images . filter ( newImageSrcFilter ( ImageSrc . local ) ) . length
21
-
22
- const warnNoImages = ( ) =>
23
- void ( ! shouldIgnoreWarnings ? window . showWarningMessage ( '没有找到可以提取的图片' ) : undefined )
24
-
25
- if ( images . length <= 0 ) return warnNoImages ( )
26
-
27
30
const result =
28
31
extractOptions . find ( x => inputImageSrc != null && x . imageSrc === inputImageSrc ) ??
29
32
( await window . showInformationMessage < ExtractOption > (
@@ -37,16 +40,10 @@ export async function extractImages(arg: unknown, inputImageSrc: ImageSrc | unde
37
40
...extractOptions
38
41
) )
39
42
40
- const editor = window . visibleTextEditors . find ( x => x . document . fileName === arg . fsPath )
41
- const textDocument = editor ?. document ?? workspace . textDocuments . find ( x => x . fileName === arg . fsPath )
43
+ if ( ! ( result && result . imageSrc !== undefined ) ) return
42
44
43
- if ( ! ( result && result . imageSrc && textDocument ) ) return
44
-
45
- if ( extractor . findImages ( ) . length <= 0 ) return warnNoImages ( )
46
45
extractor . imageSrc = result . imageSrc
47
46
48
- await textDocument . save ( )
49
-
50
47
const failedImages = await window . withProgress (
51
48
{ title : '提取图片' , location : ProgressLocation . Notification } ,
52
49
async progress => {
0 commit comments