@@ -40,8 +40,7 @@ class StatusBarEditorPlugin implements PluginValue {
4040 // When selecting text with Shift+Home the userEventType is undefined.
4141 // This is probably a bug in codemirror, for the time being doing an explict check
4242 // for the type allows us to update the stats for the selection.
43- const userEventTypeUndefined =
44- tr . annotation ( Transaction . userEvent ) === undefined ;
43+ const userEventTypeUndefined = tr . annotation ( Transaction . userEvent ) === undefined ;
4544
4645 if (
4746 ( tr . isUserEvent ( "select" ) || userEventTypeUndefined ) &&
@@ -171,36 +170,6 @@ function getHeadingRanges(app: App, file: TFile, end: number) {
171170 return ranges ;
172171}
173172
174- class SectionWidget extends WidgetType {
175- plugin : BetterWordCount ;
176- range : HeadingRange ;
177- count : number ;
178- selfCount ?: number ;
179-
180- constructor ( plugin : BetterWordCount , range : HeadingRange , count : number , selfCount ?: number ) {
181- super ( ) ;
182- this . plugin = plugin ;
183- this . range = range ;
184- this . count = count ;
185- this . selfCount = selfCount ;
186- }
187-
188- eq ( widget : this) : boolean {
189- return this . range . from === widget . range . from && this . range . to === widget . range . to ;
190- }
191-
192- getDisplayText ( ) {
193- if ( this . selfCount ) {
194- return `${ this . selfCount } / ${ this . count } ` ;
195- }
196- return this . count . toString ( ) ;
197- }
198-
199- toDOM ( ) {
200- return createSpan ( { cls : "bwc-section-count" , text : this . getDisplayText ( ) } ) ;
201- }
202- }
203-
204173class SectionWordCountEditorPlugin implements PluginValue {
205174 decorations : DecorationSet ;
206175
@@ -244,7 +213,7 @@ class SectionWordCountEditorPlugin implements PluginValue {
244213 for ( let i = 0 ; i < headingRanges . length ; i ++ ) {
245214 const heading = headingRanges [ i ] ;
246215 const next = headingRanges [ i + 1 ] ;
247- const targetPos = heading . heading . position . end . offset ;
216+ const targetPos = heading . heading . position . start . offset ;
248217
249218 const totalCount = getWordCount ( view . state . doc . slice ( heading . from , heading . to ) . toString ( ) ) ;
250219 let selfCount : number ;
@@ -259,9 +228,11 @@ class SectionWordCountEditorPlugin implements PluginValue {
259228 b . add (
260229 targetPos ,
261230 targetPos ,
262- Decoration . widget ( {
263- side : 0 ,
264- widget : new SectionWidget ( plugin , heading , totalCount , selfCount ) ,
231+ Decoration . line ( {
232+ attributes : {
233+ class : "bwc-section-count" ,
234+ style : `--word-count: "${ selfCount ? `${ selfCount } / ${ totalCount } ` : totalCount . toString ( ) } "` ,
235+ } ,
265236 } )
266237 ) ;
267238 }
0 commit comments