Skip to content

Commit 1d5bb78

Browse files
HilbergKcursoragent
andcommitted
fix: cap new highlights at 512 bytes so stock CrossInk can still read them
New captures are truncated to a UTF-8-safe 512-byte prefix at addClipping only. The read cap stays 1024 so existing long records still load, and the plain-text export still gets the full passage. Existing long records are not rewritten. Co-authored-by: Cursor <[email protected]>
1 parent 4508048 commit 1d5bb78

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ changelogs live here — ours first, then CrossInk's exactly as upstream writes
2222
### Added
2323
- Filter highlights on device and Notes Connect by **Any tag**, **No tag**, **With a note**, or **No tag or note**, alongside existing tag filters.
2424

25+
### Changed
26+
- New highlights are capped at 512 characters, matching CrossInk, so clippings files stay readable if you switch back. The full text is still written to the exported clippings file.
27+
2528
### Fixed
2629
- Opening **Notes and Bookmarks** could crash on devices with many heavily annotated books.
27-
- A book's note count could read higher than the notes it actually shows.
2830

2931
---
3032

‎src/ClippingStore.h‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,18 @@
66
#include <vector>
77

88
inline constexpr size_t CLIPPING_CHAPTER_TITLE_MAX = 48;
9-
// CrossInk Notes: 1024 (upstream 512) ≈ 150-180 words per highlight, so long
10-
// passages are not truncated. Since v1.5.0 clipping text lives outside the
11-
// record (textOffset/textLength) and is read on demand, so a larger cap no
12-
// longer costs resident RAM per clipping.
9+
// CrossInk Notes: 1024 (upstream 512) ≈ 150-180 words per highlight. Since
10+
// v1.5.0 clipping text lives outside the record (textOffset/textLength) and is
11+
// read on demand, so a larger *read* cap no longer costs resident RAM.
1312
//
14-
// Known, accepted one-way incompatibility. readFromFile() below rejects the
15-
// WHOLE file if any record's textLength exceeds this cap, so a highlight over
16-
// 512 characters written here cannot be read by stock CrossInk/CrossPoint:
17-
// that book reads as having no clippings, and the next highlight made there
18-
// rewrites the file with only that one — destroying the rest. Back in
19-
// CrossNotes, pruneMissing() then drops the now-orphaned notes too.
20-
//
21-
// Judged not worth fixing: it needs a >512-character highlight AND a switch
22-
// back to stock firmware AND a new highlight made there, and the damage is
23-
// confined to that one book. The fix, if it is ever wanted, is to write 512
24-
// here (enough to locate the passage) and keep the full text in the notes
25-
// file we own — see NoteStore, which already has the binding and the
26-
// delete/move/prune hooks for it.
27-
inline constexpr size_t CLIPPING_TEXT_MAX = 1024;
13+
// Upstream rejects the WHOLE file if any record's textLength exceeds 512, so
14+
// a long highlight written here made stock CrossInk read that book as empty;
15+
// a new highlight there then rewrote the file with only that one. New captures
16+
// are truncated to CLIPPING_TEXT_PORTABLE_MAX at the addClipping call site
17+
// (owned). This read cap stays 1024 so books we already wrote still load.
18+
// Existing long records are not rewritten.
19+
inline constexpr size_t CLIPPING_TEXT_MAX = 1024; // read: accept what we already wrote
20+
inline constexpr size_t CLIPPING_TEXT_PORTABLE_MAX = 512; // write: upstream's cap
2821
inline constexpr uint16_t CLIPPING_MAX_PER_BOOK = 256;
2922
inline constexpr uint16_t CLIPPING_MAX_PAGE_MATCHES = 16;
3023

‎src/activities/reader/EpubReaderActivity.cpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3908,10 +3908,15 @@ void EpubReaderActivity::startClipSelection() {
39083908
const auto& clip = std::get<ClippingResult>(result.data);
39093909
if (!clip.text.empty()) {
39103910
const size_t clippingIndex = CLIPPINGS.clippingCount();
3911+
std::string storeText = clip.text;
3912+
if (storeText.size() > CLIPPING_TEXT_PORTABLE_MAX) {
3913+
storeText.resize(static_cast<size_t>(
3914+
utf8SafeTruncateBuffer(storeText.c_str(), static_cast<int>(CLIPPING_TEXT_PORTABLE_MAX))));
3915+
}
39113916
const auto addResult =
39123917
CLIPPINGS.addClipping(static_cast<uint16_t>(currentSpineIndex), clip.sectionPage, clip.endSectionPage,
39133918
clip.sectionPageCount, clip.startPageWordIndex, clip.endPageWordIndex, clip.wordCount,
3914-
chapterTitle.c_str(), clip.paragraphIndex, clip.text, clippingLayoutSignature);
3919+
chapterTitle.c_str(), clip.paragraphIndex, storeText, clippingLayoutSignature);
39153920
bool exported = false;
39163921
if (addResult == ClippingStore::AddResult::Added) {
39173922
exported = ClippingsManager::saveClipping(bookTitle, author, chapterTitle,

0 commit comments

Comments
 (0)