@@ -12,18 +12,21 @@ const extractOptions: readonly ExtractOption[] = [
1212export async function extractImages ( arg : unknown , inputImageSrc : ImageSrc | undefined ) {
1313 if ( ! ( arg instanceof Uri && arg . scheme === 'file' ) ) return
1414
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+
1621 const markdown = ( await workspace . fs . readFile ( arg ) ) . toString ( )
1722 const extractor = new MarkdownImagesExtractor ( markdown , arg )
23+
1824 const images = extractor . findImages ( )
25+ if ( images . length <= 0 )
26+ void ( ! inputImageSrc != null ? window . showWarningMessage ( '没有找到可以提取的图片' ) : undefined )
27+
1928 const availableWebImagesCount = images . filter ( newImageSrcFilter ( ImageSrc . web ) ) . length
2029 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-
2730 const result =
2831 extractOptions . find ( x => inputImageSrc != null && x . imageSrc === inputImageSrc ) ??
2932 ( await window . showInformationMessage < ExtractOption > (
@@ -37,16 +40,10 @@ export async function extractImages(arg: unknown, inputImageSrc: ImageSrc | unde
3740 ...extractOptions
3841 ) )
3942
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
4244
43- if ( ! ( result && result . imageSrc && textDocument ) ) return
44-
45- if ( extractor . findImages ( ) . length <= 0 ) return warnNoImages ( )
4645 extractor . imageSrc = result . imageSrc
4746
48- await textDocument . save ( )
49-
5047 const failedImages = await window . withProgress (
5148 { title : '提取图片' , location : ProgressLocation . Notification } ,
5249 async progress => {
0 commit comments