Skip to content

Commit c3abe0f

Browse files
committed
Update rating widget to use symbol count as denominator
- Modified previewRating() to show updated denominator during hover - Modified updateRating() to save the symbol count as the new denominator - When clicking on ●●●●●●●◐ (7.5/23), it now updates to (7.5/8) instead of keeping 23 - Enhanced logging to track old vs new denominators
1 parent 4b4cef4 commit c3abe0f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/editor-extension.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,12 @@ class RatingWidget extends WidgetType {
169169
if (this.ratingText) {
170170
const textContainer = container.querySelector('.interactive-rating-text');
171171
if (textContainer) {
172+
// Use the current pattern length as the denominator for preview
172173
const previewText = formatRatingText(
173174
this.ratingText.format,
174175
newRating,
175176
this.pattern.length,
176-
this.ratingText.denominator,
177+
this.pattern.length, // Use symbol count as denominator
177178
!!this.symbolSet.half
178179
);
179180
textContainer.textContent = previewText;
@@ -184,7 +185,8 @@ class RatingWidget extends WidgetType {
184185
console.debug('[InteractiveRatings] Preview rating with half-symbol support', {
185186
newRating,
186187
hasHalf: !!this.symbolSet.half,
187-
symbolSet: this.symbolSet
188+
symbolSet: this.symbolSet,
189+
denominator: this.pattern.length
188190
});
189191
}
190192
}
@@ -248,11 +250,12 @@ class RatingWidget extends WidgetType {
248250
// Generate new rating text if it exists
249251
let newText = newSymbols;
250252
if (this.ratingText) {
253+
// Use the current pattern length as the denominator for final update
251254
const newRatingText = formatRatingText(
252255
this.ratingText.format,
253256
newRating,
254257
this.pattern.length,
255-
this.ratingText.denominator,
258+
this.pattern.length, // Use symbol count as denominator
256259
!!this.symbolSet.half
257260
);
258261
newText = newSymbols + newRatingText;
@@ -275,6 +278,8 @@ class RatingWidget extends WidgetType {
275278
newText,
276279
hasRatingText: !!this.ratingText,
277280
hasHalf: !!this.symbolSet.half,
281+
oldDenominator: this.ratingText?.denominator,
282+
newDenominator: this.pattern.length,
278283
position: { from: this.startPos, to: this.endPos }
279284
});
280285
}
@@ -416,4 +421,4 @@ const ratingViewPlugin = ViewPlugin.fromClass(
416421
);
417422

418423
// Export the extension array
419-
export const ratingEditorExtension = [ratingViewPlugin];
424+
export const ratingEditorExtension = [ratingViewPlugin];

0 commit comments

Comments
 (0)