Skip to content
Extraits de code Groupes Projets
Valider e8596cb0 rédigé par Danial Ahmad's avatar Danial Ahmad
Parcourir les fichiers

Refactor whitespace and improve code consistency in Message component,...

Refactor whitespace and improve code consistency in Message component, enhancing readability and maintainability of selection offset and feedback handling logic.
parent b1d4a70a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!53Enhance feedback sidebar functionality by implementing automatic state...
...@@ -83,14 +83,14 @@ ...@@ -83,14 +83,14 @@
if (!selection || selection.rangeCount === 0) return { start: 0, end: 0 }; if (!selection || selection.rangeCount === 0) return { start: 0, end: 0 };
const range = selection.getRangeAt(0); const range = selection.getRangeAt(0);
// Get the original message content for position calculation // Get the original message content for position calculation
const originalContent = message.content; const originalContent = message.content;
try { try {
// Get all text content from the contentDiv to reconstruct the original text // Get all text content from the contentDiv to reconstruct the original text
const allTextContent = contentDiv.textContent || ''; const allTextContent = contentDiv.textContent || '';
// If the text content doesn't match the original, something is wrong // If the text content doesn't match the original, something is wrong
if (allTextContent !== originalContent) { if (allTextContent !== originalContent) {
console.warn('Text content mismatch:', { allTextContent, originalContent }); console.warn('Text content mismatch:', { allTextContent, originalContent });
...@@ -106,12 +106,12 @@ ...@@ -106,12 +106,12 @@
// Create a temporary range to calculate positions // Create a temporary range to calculate positions
const tempRange = document.createRange(); const tempRange = document.createRange();
tempRange.selectNodeContents(contentDiv); tempRange.selectNodeContents(contentDiv);
// Calculate start position // Calculate start position
const beforeRange = tempRange.cloneRange(); const beforeRange = tempRange.cloneRange();
beforeRange.setEnd(range.startContainer, range.startOffset); beforeRange.setEnd(range.startContainer, range.startOffset);
const start = beforeRange.toString().length; const start = beforeRange.toString().length;
// Calculate end position // Calculate end position
beforeRange.setEnd(range.endContainer, range.endOffset); beforeRange.setEnd(range.endContainer, range.endOffset);
const end = beforeRange.toString().length; const end = beforeRange.toString().length;
...@@ -131,7 +131,6 @@ ...@@ -131,7 +131,6 @@
}); });
return { start: finalStart, end: finalEnd }; return { start: finalStart, end: finalEnd };
} catch (error) { } catch (error) {
console.error('Error calculating selection offset:', error); console.error('Error calculating selection offset:', error);
// Fallback: try to find the selected text in the original content // Fallback: try to find the selected text in the original content
...@@ -199,10 +198,10 @@ ...@@ -199,10 +198,10 @@
if (hightlight) hightlight.style.visibility = 'hidden'; if (hightlight) hightlight.style.visibility = 'hidden';
return; return;
} }
console.log('onSelect called with hasComment:', hasComment); console.log('onSelect called with hasComment:', hasComment);
console.log('Current selection:', selection.toString()); console.log('Current selection:', selection.toString());
const range = getSelectionCharacterOffsetWithin(); const range = getSelectionCharacterOffsetWithin();
console.log('Calculated range:', range); console.log('Calculated range:', range);
...@@ -237,8 +236,8 @@ ...@@ -237,8 +236,8 @@
// Create an array to track all feedback boundaries // Create an array to track all feedback boundaries
const boundaries: { position: number; type: 'start' | 'end'; feedback: Feedback }[] = []; const boundaries: { position: number; type: 'start' | 'end'; feedback: Feedback }[] = [];
feedbacks.forEach(feedback => { feedbacks.forEach((feedback) => {
boundaries.push({ position: feedback.start, type: 'start', feedback }); boundaries.push({ position: feedback.start, type: 'start', feedback });
boundaries.push({ position: feedback.end, type: 'end', feedback }); boundaries.push({ position: feedback.end, type: 'end', feedback });
}); });
...@@ -256,7 +255,7 @@ ...@@ -256,7 +255,7 @@
let currentPos = 0; let currentPos = 0;
const activeFeedbacks: Feedback[] = []; const activeFeedbacks: Feedback[] = [];
boundaries.forEach(boundary => { boundaries.forEach((boundary) => {
// Add text part before this boundary if there's content // Add text part before this boundary if there's content
if (boundary.position > currentPos) { if (boundary.position > currentPos) {
const text = content.slice(currentPos, boundary.position); const text = content.slice(currentPos, boundary.position);
...@@ -269,7 +268,7 @@ ...@@ -269,7 +268,7 @@
if (boundary.type === 'start') { if (boundary.type === 'start') {
activeFeedbacks.push(boundary.feedback); activeFeedbacks.push(boundary.feedback);
} else { } else {
const index = activeFeedbacks.findIndex(f => f.id === boundary.feedback.id); const index = activeFeedbacks.findIndex((f) => f.id === boundary.feedback.id);
if (index !== -1) { if (index !== -1) {
activeFeedbacks.splice(index, 1); activeFeedbacks.splice(index, 1);
} }
...@@ -283,8 +282,8 @@ ...@@ -283,8 +282,8 @@
parts.push({ text: content.slice(currentPos), feedback: null, allFeedbacks: [] }); parts.push({ text: content.slice(currentPos), feedback: null, allFeedbacks: [] });
} }
const result = parts.filter(part => part.text.length > 0); const result = parts.filter((part) => part.text.length > 0);
return result; return result;
} }
...@@ -378,8 +377,8 @@ ...@@ -378,8 +377,8 @@
{:else} {:else}
<span <span
class="underline relative decoration-wavy hover:cursor-help group/feedback" class="underline relative decoration-wavy hover:cursor-help group/feedback"
class:decoration-blue-500={part.allFeedbacks.some(f => f.content)} class:decoration-blue-500={part.allFeedbacks.some((f) => f.content)}
class:decoration-red-500={part.allFeedbacks.every(f => !f.content)} class:decoration-red-500={part.allFeedbacks.every((f) => !f.content)}
role="button" role="button"
tabindex="0" tabindex="0"
> >
...@@ -405,7 +404,9 @@ ...@@ -405,7 +404,9 @@
<!-- Multiple overlapping feedbacks --> <!-- Multiple overlapping feedbacks -->
<div class="flex flex-col gap-1 max-w-xs"> <div class="flex flex-col gap-1 max-w-xs">
{#each part.allFeedbacks as feedback, index} {#each part.allFeedbacks as feedback, index}
<div class="flex items-center text-xs border-b border-gray-600 pb-1 last:border-b-0"> <div
class="flex items-center text-xs border-b border-gray-600 pb-1 last:border-b-0"
>
<span class="flex-1 truncate"> <span class="flex-1 truncate">
{feedback.content || 'Marked text'} {feedback.content || 'Marked text'}
</span> </span>
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter