Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add text statistics next to the cursor position #268

Merged
merged 1 commit into from
May 16, 2017

Conversation

xgouchet
Copy link
Contributor

@xgouchet xgouchet commented Mar 4, 2017

This adds a word count, alpha numeric character count and all character
count in the bottom right corner, with the cursor line and column
position

Fixes #164

@mitya57
Copy link
Member

mitya57 commented Mar 4, 2017

Sorry for the delay with reviewing your requests.
The idea looks fine, but I would like to make this be:

  • separate from the cursor position panel (maybe you can make this have a different background color?);
  • translatable (wrapping this in a tr() and adding a translator comment would be nice).

Also, did you perform any performance checks? How slow is it on large (or huge) documents?

I can look at these issues myself, but in this case you will need to wait a bit more.

@xgouchet
Copy link
Contributor Author

xgouchet commented Mar 4, 2017

Hi, good idea about the translation, I'm going to add it.

I thought about the performance issue, and might add an option to enable / disable this feature.
I also thought of using some heuristic to guess the wordcount without having to actually parse the whole document (the QEditText already gives the character count, and we can divide this number by an average character per count value).

Copy link
Member

@mitya57 mitya57 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. How about using a common class from which LineNumberArea and StatsArea can inherit, to avoid duplicating code?

  2. The word count currently shows a number less by one from the actual word count. I.e. if my document is “foo bar”, not ending with a space, it shows 1 instead of 2.

ReText/editor.py Outdated
self.setPalette(palette)

def mousePressEvent(self, event):
pos = self.mapToParent(event.pos())
pos.setX(pos.x() - self.editor.lineNumberAreaWidth())
newEvent = QMouseEvent(event.type(), pos,
event.button(), event.buttons(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses tabs for indentation, but spaces for alignment. Please do not change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

ReText/editor.py Outdated
wordCount += 1
wasWordCharacter = isWordCharacter
end = time.clock()
value = int((end - start) * 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these start / end / value lines a leftover debug? Can you please share your time measurements?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they were left over, sorry.
On my laptop, for a 100k document (100'000 characters, 3500 lines), I get an average of 40ms to compute the stats

ReText/editor.py Outdated
def getText(self):
if not globalSettings.documentStatsEnabled:
return
template = '%d w : %d a : %d c'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this translatable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

This adds a word count, alpha numeric character count and all character
count in the bottom left corner

This option can be disabled from the Preferences dialog (by default it's
off). The statistic is only updated when the content changes (to avoid
recomputing when scrolling or resizing the window). On my lapop, the
computing only takes 40ms for a 100'000 characters markdown document
(roughly 15'000 words, 3'500 lines).

Fixes retext-project#164
@xgouchet
Copy link
Contributor Author

I updated the PR with your recommendation : a base class for additional information (LineInfo / Text Info), and updated the text analysis to correct the word count

@mitya57 mitya57 merged commit 3519397 into retext-project:master May 16, 2017
@mitya57
Copy link
Member

mitya57 commented May 16, 2017

Thank you!

@xgouchet xgouchet deleted the text_statistics branch September 14, 2017 06:27
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.

None yet

3 participants