alldritt / TextKit_LineNumbers

iOS7 Text Kit - Text View with Line Numbers
105 stars 17 forks source link

Inserting new line does not add a new line number/change current line #2

Open mbcoder17 opened 9 years ago

mbcoder17 commented 9 years ago

If I press enter to go to a new line, a new line is not created until I begin typing on that line.

alldritt commented 9 years ago

Yes, I see the problem. This seems to be a consequence of how the NSLayoutManager's enumerateLineFragmentsForGlyphRange method works. Since there are no characters on the last line, there are no line fragments to draw. I'm not sure how to resolve this easily.

I suppose, one could add code after the enumerateLineFragmentsForGlyphRange call to draw a final line number when the last line is empty. The trick will be to calculate the rectangle in which to draw the final line number.

mbcoder17 commented 9 years ago

@alldritt How would one go about doing that? I am not very familiar with stuff like this, but I love the library.

alldritt commented 9 years ago

Hi,

On Jul 19, 2015, at 11:03 AM, mbcoder17 notifications@github.com wrote:

@alldritt How would one go about doing that? I am not very familiar with stuff like this, but I love the library.

This code in LineNumberLayoutManager.m should do the trick:

Cheers -Mark


Mark Alldritt Late Night Software Ltd. www.latenightsw.com 250-380-1725 (888-999-3210)

mbcoder17 commented 9 years ago

Hmmmm, this didn't work for me. When I press enter after a line the next line still doesn't have a line number. After some logging, I don't think the if statement is getting called to begin with.

alldritt commented 9 years ago

Hello,

On Jul 20, 2015, at 4:34 PM, mbcoder17 notifications@github.com wrote:

Hmmmm, this didn't work for me. When I press enter after a line the next line still doesn't have a line number.

I commited the changes to GitHub. You can check out a fresh copy. Its working for me.

Cheers -Mark


Mark Alldritt Late Night Software Ltd. www.latenightsw.com 250-380-1725 (888-999-3210)

mbcoder17 commented 9 years ago

@alldritt Try this to reproduce the issue I'm having. Remove everything in the textview, type something on the first line, then press enter. For me a second line number is not added...

alldritt commented 9 years ago

Hi,

On Jul 21, 2015, at 7:47 AM, mbcoder17 notifications@github.com wrote:

Try this to reproduce the issue I'm having. Remove everything in the textview, type something on the first line, then press enter. For me a second line number is not added…

Fascinating. It seems that drawBackgroundForGlyphRange is not called at all when there are no glyphs to display, and so my code never gets a chance to draw the line number. Some other solution is going to be needed to catch this particular problem-nothing obvious comes to mind.

Cheers -Mark


Mark Alldritt Late Night Software Ltd. www.latenightsw.com 250-380-1725 (888-999-3210)

mbcoder17 commented 9 years ago

Any luck in finding a solution for this??

alldritt commented 9 years ago

Hello,

On Sep 5, 2015, at 7:38 AM, Jacob notifications@github.com wrote:

Any luck in finding a solution for this??

Sorry, no. I’ve been working on other projects and have not devoted any time to this problem.

Cheers -Mark


Mark Alldritt Late Night Software Ltd. www.latenightsw.com 250-380-1725 (888-999-3210)

dirtyhenry commented 3 years ago

I just updated/ran the code and can't reproduce this issue: https://github.com/alldritt/TextKit_LineNumbers/pull/5