chemodax / WordCount

Simple extension for Microsoft Visual Studio to show character, word and line count.
https://marketplace.visualstudio.com/items?itemName=Ivan.WordCount
0 stars 2 forks source link

Line count often is off by one #1

Open cfeied opened 1 year ago

cfeied commented 1 year ago

Incredibly helpful extension!!! Small bug.

If I click in the left margin to select an entire line, the line count shows 2 lines rather than one. This is because the cursor has been placed in column one of the next line, and the code does not recognize this edge case (it merely subtracts the line numbers and adds one).

This off-by-one scenario arises any time a selection includes the invisible EOL character that follows the last visible character on a line. For one humorous manifestation, put your cursor anywhere in a line of code and press the END key. You will see the normal status bar showing the total lines in the file. Now hold down the shift key and hit the right arrow. A single empty-appearing character space will be highlighted, and the status bar shows "Chars: 0 Words: 0 Lines: 2"

Hilarious, but possibly worth fixing.

chemodax commented 1 year ago

Thanks for problem report.

Well actually it's not a bug: technically selection end is on the second line, so it touches two lines.

For example Sublime Text has the same behavior: image

I agree it's a little bit confusing, but it matches behavior of other mainstream text editor.

What do you think?