2026-02-12 19:36:14 -05:00
|
|
|
#pragma once
|
|
|
|
|
#include <Epub/Page.h>
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
feat: Integrate PR #857 dictionary intelligence and sub-activity refactor
Pull in the full feature update from PR #857 while preserving fork
advantages (HTML parsing, custom drawHints, PageForward/PageBack,
cache management, stardictCmp, /.dictionary/ paths).
- Add morphological stemming (getStemVariants), Levenshtein edit
distance, and fuzzy matching (findSimilar) to Dictionary
- Create DictionarySuggestionsActivity for "Did you mean?" flow
- Add onDone callback to DictionaryDefinitionActivity for direct
exit-to-reader via "Done" button
- Refactor DictionaryWordSelectActivity to ActivityWithSubactivity
with cascading lookup (exact → stems → suggestions → not found),
en-dash/em-dash splitting, and cross-page hyphenation
- Refactor LookedUpWordsActivity with reverse-chronological order,
inline cascading lookup, UITheme-aware rendering, and sub-activities
- Simplify EpubReaderActivity LOOKUP/LOOKED_UP_WORDS handlers
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 20:50:03 -05:00
|
|
|
#include "../ActivityWithSubactivity.h"
|
2026-02-12 19:36:14 -05:00
|
|
|
|
feat: Integrate PR #857 dictionary intelligence and sub-activity refactor
Pull in the full feature update from PR #857 while preserving fork
advantages (HTML parsing, custom drawHints, PageForward/PageBack,
cache management, stardictCmp, /.dictionary/ paths).
- Add morphological stemming (getStemVariants), Levenshtein edit
distance, and fuzzy matching (findSimilar) to Dictionary
- Create DictionarySuggestionsActivity for "Did you mean?" flow
- Add onDone callback to DictionaryDefinitionActivity for direct
exit-to-reader via "Done" button
- Refactor DictionaryWordSelectActivity to ActivityWithSubactivity
with cascading lookup (exact → stems → suggestions → not found),
en-dash/em-dash splitting, and cross-page hyphenation
- Refactor LookedUpWordsActivity with reverse-chronological order,
inline cascading lookup, UITheme-aware rendering, and sub-activities
- Simplify EpubReaderActivity LOOKUP/LOOKED_UP_WORDS handlers
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 20:50:03 -05:00
|
|
|
class DictionaryWordSelectActivity final : public ActivityWithSubactivity {
|
2026-02-12 19:36:14 -05:00
|
|
|
public:
|
|
|
|
|
explicit DictionaryWordSelectActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
|
|
|
|
std::unique_ptr<Page> page, int fontId, int marginLeft, int marginTop,
|
|
|
|
|
const std::string& cachePath, uint8_t orientation,
|
|
|
|
|
const std::function<void()>& onBack,
|
feat: Integrate PR #857 dictionary intelligence and sub-activity refactor
Pull in the full feature update from PR #857 while preserving fork
advantages (HTML parsing, custom drawHints, PageForward/PageBack,
cache management, stardictCmp, /.dictionary/ paths).
- Add morphological stemming (getStemVariants), Levenshtein edit
distance, and fuzzy matching (findSimilar) to Dictionary
- Create DictionarySuggestionsActivity for "Did you mean?" flow
- Add onDone callback to DictionaryDefinitionActivity for direct
exit-to-reader via "Done" button
- Refactor DictionaryWordSelectActivity to ActivityWithSubactivity
with cascading lookup (exact → stems → suggestions → not found),
en-dash/em-dash splitting, and cross-page hyphenation
- Refactor LookedUpWordsActivity with reverse-chronological order,
inline cascading lookup, UITheme-aware rendering, and sub-activities
- Simplify EpubReaderActivity LOOKUP/LOOKED_UP_WORDS handlers
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 20:50:03 -05:00
|
|
|
const std::string& nextPageFirstWord = "")
|
|
|
|
|
: ActivityWithSubactivity("DictionaryWordSelect", renderer, mappedInput),
|
2026-02-12 19:36:14 -05:00
|
|
|
page(std::move(page)),
|
|
|
|
|
fontId(fontId),
|
|
|
|
|
marginLeft(marginLeft),
|
|
|
|
|
marginTop(marginTop),
|
|
|
|
|
cachePath(cachePath),
|
|
|
|
|
orientation(orientation),
|
|
|
|
|
onBack(onBack),
|
feat: Integrate PR #857 dictionary intelligence and sub-activity refactor
Pull in the full feature update from PR #857 while preserving fork
advantages (HTML parsing, custom drawHints, PageForward/PageBack,
cache management, stardictCmp, /.dictionary/ paths).
- Add morphological stemming (getStemVariants), Levenshtein edit
distance, and fuzzy matching (findSimilar) to Dictionary
- Create DictionarySuggestionsActivity for "Did you mean?" flow
- Add onDone callback to DictionaryDefinitionActivity for direct
exit-to-reader via "Done" button
- Refactor DictionaryWordSelectActivity to ActivityWithSubactivity
with cascading lookup (exact → stems → suggestions → not found),
en-dash/em-dash splitting, and cross-page hyphenation
- Refactor LookedUpWordsActivity with reverse-chronological order,
inline cascading lookup, UITheme-aware rendering, and sub-activities
- Simplify EpubReaderActivity LOOKUP/LOOKED_UP_WORDS handlers
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 20:50:03 -05:00
|
|
|
nextPageFirstWord(nextPageFirstWord) {}
|
2026-02-12 19:36:14 -05:00
|
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
|
void onExit() override;
|
|
|
|
|
void loop() override;
|
2026-02-16 13:22:40 -05:00
|
|
|
void render(Activity::RenderLock&&) override;
|
2026-02-12 19:36:14 -05:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct WordInfo {
|
|
|
|
|
std::string text;
|
|
|
|
|
std::string lookupText;
|
|
|
|
|
int16_t screenX;
|
|
|
|
|
int16_t screenY;
|
|
|
|
|
int16_t width;
|
|
|
|
|
int16_t row;
|
|
|
|
|
int continuationIndex;
|
|
|
|
|
int continuationOf;
|
|
|
|
|
WordInfo(const std::string& t, int16_t x, int16_t y, int16_t w, int16_t r)
|
|
|
|
|
: text(t), lookupText(t), screenX(x), screenY(y), width(w), row(r), continuationIndex(-1), continuationOf(-1) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Row {
|
|
|
|
|
int16_t yPos;
|
|
|
|
|
std::vector<int> wordIndices;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Page> page;
|
|
|
|
|
int fontId;
|
|
|
|
|
int marginLeft;
|
|
|
|
|
int marginTop;
|
|
|
|
|
std::string cachePath;
|
|
|
|
|
uint8_t orientation;
|
|
|
|
|
const std::function<void()> onBack;
|
feat: Integrate PR #857 dictionary intelligence and sub-activity refactor
Pull in the full feature update from PR #857 while preserving fork
advantages (HTML parsing, custom drawHints, PageForward/PageBack,
cache management, stardictCmp, /.dictionary/ paths).
- Add morphological stemming (getStemVariants), Levenshtein edit
distance, and fuzzy matching (findSimilar) to Dictionary
- Create DictionarySuggestionsActivity for "Did you mean?" flow
- Add onDone callback to DictionaryDefinitionActivity for direct
exit-to-reader via "Done" button
- Refactor DictionaryWordSelectActivity to ActivityWithSubactivity
with cascading lookup (exact → stems → suggestions → not found),
en-dash/em-dash splitting, and cross-page hyphenation
- Refactor LookedUpWordsActivity with reverse-chronological order,
inline cascading lookup, UITheme-aware rendering, and sub-activities
- Simplify EpubReaderActivity LOOKUP/LOOKED_UP_WORDS handlers
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 20:50:03 -05:00
|
|
|
std::string nextPageFirstWord;
|
2026-02-12 19:36:14 -05:00
|
|
|
|
|
|
|
|
std::vector<WordInfo> words;
|
|
|
|
|
std::vector<Row> rows;
|
|
|
|
|
int currentRow = 0;
|
|
|
|
|
int currentWordInRow = 0;
|
feat: Integrate PR #857 dictionary intelligence and sub-activity refactor
Pull in the full feature update from PR #857 while preserving fork
advantages (HTML parsing, custom drawHints, PageForward/PageBack,
cache management, stardictCmp, /.dictionary/ paths).
- Add morphological stemming (getStemVariants), Levenshtein edit
distance, and fuzzy matching (findSimilar) to Dictionary
- Create DictionarySuggestionsActivity for "Did you mean?" flow
- Add onDone callback to DictionaryDefinitionActivity for direct
exit-to-reader via "Done" button
- Refactor DictionaryWordSelectActivity to ActivityWithSubactivity
with cascading lookup (exact → stems → suggestions → not found),
en-dash/em-dash splitting, and cross-page hyphenation
- Refactor LookedUpWordsActivity with reverse-chronological order,
inline cascading lookup, UITheme-aware rendering, and sub-activities
- Simplify EpubReaderActivity LOOKUP/LOOKED_UP_WORDS handlers
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 20:50:03 -05:00
|
|
|
bool pendingBackFromDef = false;
|
|
|
|
|
bool pendingExitToReader = false;
|
2026-02-12 19:36:14 -05:00
|
|
|
|
|
|
|
|
bool isLandscape() const;
|
|
|
|
|
bool isInverted() const;
|
|
|
|
|
void extractWords();
|
|
|
|
|
void mergeHyphenatedWords();
|
|
|
|
|
void drawHints();
|
|
|
|
|
};
|