@@ -2,7 +2,6 @@ import { Notice, TAbstractFile } from 'obsidian';
2
2
import LabeledAnnotations from '../../main' ;
3
3
import { parseAnnotationsFromFiles } from './parse-annotations-from-files' ;
4
4
import { pluralize } from '../../helpers/pluralize' ;
5
- import { clipboard } from 'electron' ;
6
5
import { annotationsToText } from './annotations-to-text' ;
7
6
8
7
export const copyAnnotationsToClipboard = async (
@@ -14,9 +13,17 @@ export const copyAnnotationsToClipboard = async (
14
13
: [ abstractFiles ] ;
15
14
const root = abstractFilesArray [ 0 ] . parent ?. path as string ;
16
15
17
- const content = await parseAnnotationsFromFiles ( abstractFilesArray , plugin ) ;
18
- const nOfFiles = Object . keys ( content ) . length ;
19
- const nOfAnnotations = content . map ( ( c ) => c . annotations ) . flat ( ) . length ;
16
+ const unsortedAnnotations = await parseAnnotationsFromFiles (
17
+ abstractFilesArray ,
18
+ plugin ,
19
+ ) ;
20
+ const sortedAnnotations = unsortedAnnotations . sort ( ( a , b ) =>
21
+ a . folder . localeCompare ( b . folder ) ,
22
+ ) ;
23
+ const nOfFiles = Object . keys ( sortedAnnotations ) . length ;
24
+ const nOfAnnotations = sortedAnnotations
25
+ . map ( ( c ) => c . annotations )
26
+ . flat ( ) . length ;
20
27
if ( nOfAnnotations ) {
21
28
new Notice (
22
29
`Copied ${ pluralize (
@@ -26,7 +33,9 @@ export const copyAnnotationsToClipboard = async (
26
33
) } from ${ pluralize ( nOfFiles , 'file' , 'files' ) } to clipboard`,
27
34
) ;
28
35
const templates = plugin . settings . getValue ( ) . clipboard . templates ;
29
- clipboard . writeText ( annotationsToText ( content , templates , root ) ) ;
36
+ await navigator . clipboard . writeText (
37
+ annotationsToText ( sortedAnnotations , templates , root ) ,
38
+ ) ;
30
39
} else {
31
40
new Notice ( `No annotations found` ) ;
32
41
}
0 commit comments