Ionaru / easy-markdown-editor

EasyMDE: A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.
https://stackblitz.com/edit/easymde
MIT License
2.39k stars 316 forks source link

Line number in status bar has offset [Fixed] #381

Closed Zignature closed 2 years ago

Zignature commented 2 years ago

Describe the bug The cursor position in the status bar (line:column) is wrong. The line number has an offset of -1.

To Reproduce Position the cursor anywhere in the document and check the line number in the status bar.

Expected behavior I expect the line number to be correct.

Screenshots Current: cursor-position-wrong

Expected: cursor-position-right

Version information

Solution line 2675 in easymde.js should be changed from el.innerHTML = pos.line + ':' + pos.ch; to el.innerHTML = pos.line + 1 + ':' + pos.ch;

Ionaru commented 2 years ago

Good catch. Should we also increase pos.ch by one?

In Microsoft Word, the Line and Column count both start at 1.

image

image

Feel free to open a PR :)

Zignature commented 2 years ago

I'll catch pos.ch too and open a PR :)

Zignature commented 2 years ago

@Ionaru We overlooked one thing. The Line:Column counter starts at 0:0. It should be 1:1.

Right now if you put your cursor in an empty document the Line:Column counter doesn't update to 1:1. It updates to 1:2 after a character is added to the document.

Line ~2693: el.innerHTML = '0:0'; needs to be changed to el.innerHTML = '1:1';

Ionaru commented 2 years ago

You're right, I'll make a commit to fix that :)