diff --git a/server/readerMarks.js b/server/readerMarks.js index 172c0e6..3080f96 100644 --- a/server/readerMarks.js +++ b/server/readerMarks.js @@ -36,6 +36,9 @@ export function cleanMarks(body) { }; // The highlighted words, kept so lists of highlights can show them without loading the chapter if (typeof h.text === 'string' && h.text.length > 0) entry.text = h.text.slice(0, 500); + // Which translation the words were selected in, and whether it is a whole-verse highlight + if (typeof h.translation === 'string' && /^[A-Za-z0-9]{2,8}$/.test(h.translation)) entry.translation = h.translation; + if (h.whole === true) entry.whole = true; highlights.push(entry); } } diff --git a/server/readerMarks.test.js b/server/readerMarks.test.js index 65612ca..af366c2 100644 --- a/server/readerMarks.test.js +++ b/server/readerMarks.test.js @@ -58,3 +58,15 @@ test('the database keeps one row per user and updatedAt only moves forward', asy expect(saved.highlights).toHaveLength(1); expect(db.getReaderMarks('u2').updatedAt).toBe(0); // other users are untouched }); + +test('a highlight keeps the translation it was made in and whether it covers the whole verse', async () => { + const { cleanMarks } = await import('./readerMarks.js'); + const base = { id: 'a', book: 'JHN', chapter: 3, verse: 16, startOffset: 0, endOffset: 40, color: '#fef08a', text: 'For God so loved' }; + const out = cleanMarks({ highlights: [ + { ...base, translation: 'BSB', whole: true }, + { ...base, id: 'b', translation: 'not a code!!', whole: 'yes' }, + ] }).highlights; + expect(out[0]).toMatchObject({ translation: 'BSB', whole: true }); + expect(out[1].translation).toBeUndefined(); + expect(out[1].whole).toBeUndefined(); +}); diff --git a/src/components/reader/VerseSheet.jsx b/src/components/reader/VerseSheet.jsx index 6b7f7ab..e16102e 100644 --- a/src/components/reader/VerseSheet.jsx +++ b/src/components/reader/VerseSheet.jsx @@ -9,6 +9,7 @@ import { READER_TRANSLATIONS, fetchChapter } from '../../utils/bibleText.js'; import { diffVerses, differenceLabel } from '../../utils/textDiff.js'; import { DiffText } from './DiffText.jsx'; import { HIGHLIGHT_COLORS, colorTitle } from '../../utils/highlightColors.js'; +import { isWholeVerse } from '../../utils/highlightSpans.js'; import { useIqAvailable } from '../../hooks/useIq.js'; import VerseShareImage from '../VerseShareImage.jsx'; import IqLexicon from '../iq/IqLexicon.jsx'; @@ -223,7 +224,7 @@ export default function VerseSheet({
Highlight {HIGHLIGHT_COLORS.map((color) => { - const on = verseHighlights.some((h) => h.color === color && h.startOffset === 0 && h.endOffset >= verse.text.length); + const on = verseHighlights.some((h) => h.color === color && isWholeVerse(h, verse.text)); return (