@@ -4,15 +4,13 @@ interface AnchorDisplayTextSettings {
4
4
includeNoteName : string ;
5
5
whichHeadings : string ;
6
6
includeNotice : boolean ;
7
- noticeText : string ;
8
7
sep : string ;
9
8
}
10
9
11
10
const DEFAULT_SETTINGS : AnchorDisplayTextSettings = {
12
11
includeNoteName : 'headersOnly' ,
13
12
whichHeadings : 'allHeaders' ,
14
13
includeNotice : false ,
15
- noticeText : 'Link changed!' ,
16
14
sep : ' '
17
15
}
18
16
@@ -48,15 +46,16 @@ export default class AnchorDisplayText extends Plugin {
48
46
}
49
47
}
50
48
const startIndex = ( match . index ?? 0 ) + match [ 0 ] . length - 2 ;
51
- if ( this . settings . includeNoteName === 'headersOnly' ) {
52
- editor . replaceRange ( `|${ displayText } ` , { line : cursor . line , ch : startIndex } , undefined , 'headerDisplayText' ) ;
53
- } else if ( this . settings . includeNoteName === 'noteNameFirst' ) {
54
- editor . replaceRange ( `|${ headings [ 0 ] } ${ this . settings . sep } ${ displayText } ` , { line : cursor . line , ch : startIndex } , undefined , 'headerDisplayText' ) ;
49
+ // add note name to display text if wanted
50
+ if ( this . settings . includeNoteName === 'noteNameFirst' ) {
51
+ displayText = `${ headings [ 0 ] } ${ this . settings . sep } ${ displayText } ` ;
55
52
} else if ( this . settings . includeNoteName === 'noteNameLast' ) {
56
- editor . replaceRange ( `| ${ displayText } ${ this . settings . sep } ${ headings [ 0 ] } `, { line : cursor . line , ch : startIndex } , undefined , 'headerDisplayText' ) ;
53
+ displayText = ` ${ displayText } ${ this . settings . sep } ${ headings [ 0 ] } `;
57
54
}
55
+ // change the display text of the link
56
+ editor . replaceRange ( `|${ displayText } ` , { line : cursor . line , ch : startIndex } , undefined , 'headerDisplayText' ) ;
58
57
if ( this . settings . includeNotice ) {
59
- new Notice ( this . settings . noticeText )
58
+ new Notice ( `Updated anchor link display text.` ) ;
60
59
}
61
60
}
62
61
} )
0 commit comments