Skip to content

feat(xodt): count words and characters under the page - #183

Merged
anderix merged 2 commits into
mainfrom
177-word-count
Nov 24, 2026
Merged

anderix merged 2 commits into
mainfrom
177-word-count

Conversation

@anderix

@anderix anderix commented Nov 24, 2026

Copy link
Copy Markdown
Member

The bar under the page in xodt now shows the document's word and character counts. When there is a selection, it shows the selection's counts against the totals: "Words: 3 of 79 Characters: 20 of 465". The counts are taken again when the text or the selection changes, not on every frame.

As the issue asks, a word is a stretch between the Unicode word boundaries the caret moves by (the word_ranges from #178) that holds a letter or a digit. Paragraphs are counted one at a time, and the character count includes spaces.

These figures differ from LibreOffice's. LibreOffice counts whatever sits between spaces, so & is a word and "right-aligned" is one word. It also adds list labels such as "•" and "1." to both figures. On the corpus the two agree on tabs.odt and directions.odt, and the test compares those two. On text.odt LibreOffice reports 88 words and 472 characters, where the issue's rule gives 79 and 465; list_labels_are_not_counted and a_hyphenated_word_is_two_and_a_lone_symbol_is_none pin that difference. DESIGN.md §7 explains it. Matching LibreOffice instead would mean changing words::count and counting labels.

The labels read "Words: …" and "Characters: …", the same form as xods' "Sum: …" and "Count: …". t has no plural forms, so "{n} words" would read "1 words". The German is "Wörter: {words}", "Zeichen: {characters}" and "… von {total}".

Closes #177

@anderix

anderix commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Review: no Critical or Important findings. Renamed list_labels_are_not_counted to text_odt_counts_by_word_boundaries_not_by_libreoffice_rule, since labels never reach the paragraph text and the test pins the figures, not the labels. Declined for now: a possible one-frame lag of the count after an edit whose last event is a mouse release (traced from the code, not reproduced; keyboard edits are unaffected).

@anderix
anderix merged commit 98e49d4 into main Nov 24, 2026
@anderix
anderix deleted the 177-word-count branch November 24, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xodt: word and character count

1 participant