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
This commit is contained in:
Filip Noetzel 2025-06-09 09:22:46 +02:00
parent 4b4cef482c
commit c3abe0f9ee

View file

@ -169,11 +169,12 @@ class RatingWidget extends WidgetType {
if (this.ratingText) {
const textContainer = container.querySelector('.interactive-rating-text');
if (textContainer) {
// Use the current pattern length as the denominator for preview
const previewText = formatRatingText(
this.ratingText.format,
newRating,
this.pattern.length,
this.ratingText.denominator,
this.pattern.length, // Use symbol count as denominator
!!this.symbolSet.half
);
textContainer.textContent = previewText;
@ -184,7 +185,8 @@ class RatingWidget extends WidgetType {
console.debug('[InteractiveRatings] Preview rating with half-symbol support', {
newRating,
hasHalf: !!this.symbolSet.half,
symbolSet: this.symbolSet
symbolSet: this.symbolSet,
denominator: this.pattern.length
});
}
}
@ -248,11 +250,12 @@ class RatingWidget extends WidgetType {
// Generate new rating text if it exists
let newText = newSymbols;
if (this.ratingText) {
// Use the current pattern length as the denominator for final update
const newRatingText = formatRatingText(
this.ratingText.format,
newRating,
this.pattern.length,
this.ratingText.denominator,
this.pattern.length, // Use symbol count as denominator
!!this.symbolSet.half
);
newText = newSymbols + newRatingText;
@ -275,6 +278,8 @@ class RatingWidget extends WidgetType {
newText,
hasRatingText: !!this.ratingText,
hasHalf: !!this.symbolSet.half,
oldDenominator: this.ratingText?.denominator,
newDenominator: this.pattern.length,
position: { from: this.startPos, to: this.endPos }
});
}
@ -416,4 +421,4 @@ const ratingViewPlugin = ViewPlugin.fromClass(
);
// Export the extension array
export const ratingEditorExtension = [ratingViewPlugin];
export const ratingEditorExtension = [ratingViewPlugin];