Chromatism icon indicating copy to clipboard operation
Chromatism copied to clipboard

Line numbers are required

Open zyavrik opened this issue 12 years ago • 16 comments

Required support for line numbers.

zyavrik avatar Oct 02 '13 14:10 zyavrik

I second this, having line numbers would be hugely helpful.

davemackintosh avatar Nov 27 '13 16:11 davemackintosh

This might help somebody to add this: http://stackoverflow.com/questions/2836162/how-to-add-line-numbers-to-a-uitextview

ndrewh avatar Nov 27 '13 16:11 ndrewh

I've actually already started trying to implement that along side.

davemackintosh avatar Nov 27 '13 16:11 davemackintosh

I would love to see it when you get something working. I've been looking for this for a while.

ndrewh avatar Nov 27 '13 17:11 ndrewh

Like that post says, it's working around the line break, or we scroll horizontally. Will be a challenge.

davemackintosh avatar Nov 27 '13 17:11 davemackintosh

@davemackintosh Yeah I'm messing with it now too.

ndrewh avatar Nov 27 '13 17:11 ndrewh

@davemackintosh Overriding the drawRect method is significantly reducing performance.

ndrewh avatar Nov 27 '13 17:11 ndrewh

I haven't noticed anything massive yet but stopped playing a few hours ago to get on with some other work that pays me lol. Will have another look later on/tomorrow morning but if you find anything else do let me (us all) know!

davemackintosh avatar Nov 27 '13 17:11 davemackintosh

Okay so here is what I have so far using that stack overflow post as a guide. It doesn't work perfectly yet but It will eventually. (Note that the code in the image is not mine) Imgur

ndrewh avatar Nov 27 '13 18:11 ndrewh

An alternative to overriding -drawRect might be using NSLayoutManager.

Anviking avatar Nov 27 '13 18:11 Anviking

I think this might actually be easier than I thought, conceptually anyway. Will do an implementation tonight and see if I can come up with anything good.

davemackintosh avatar Nov 27 '13 19:11 davemackintosh

yes, it is easier than I thought with no measurable performance hit. I'm currently working on a UITableView that displays the line numbers according to the lines, this gives us line numbers that have the right amount of spacing between them without having to modify the UITextView or extend it. Will be finishing up on this today and you can review it.

davemackintosh avatar Nov 28 '13 09:11 davemackintosh

Just so people know, I am still working on this. Work is just a bit hectic at the moment and finding time to finish the implementation is hard! rest assured I will update my fork with line numbers and once it's okayed I'll submit a pull-request.

Some info on my implementation:

After seeing performance issues with using drawRect method, I've implemented programatically adding a UITableView to the left of the JLTextView which contains the line numbers in and the heights of each Cell is calculated from the font and string size so they're spaced properly.

The issue I'm having at the moment is updating the UITableView properly while editing and also setting the width of it as you get from single digits to double, to triple, so on and so forth but I'm still working on it! I'll try to get some screen shots when I get a little time to do so!

davemackintosh avatar Dec 01 '13 12:12 davemackintosh

Okay, now I have some free time I'm back on this :) just as an update. Is anyone else working on this?

davemackintosh avatar Jan 28 '14 22:01 davemackintosh

@davemackintosh check out https://github.com/illyabusigin/CYRTextView to see a possible implementation of the line numbers... Haven't really dug around, but may be of some use.

ruddfawcett avatar Jan 29 '14 02:01 ruddfawcett

Oh. Ha, nice. I'll hit that up instead, having a quick look over it and it's mostly the same as what I've been doing. I'll add this today and remove what I've done.

davemackintosh avatar Jan 29 '14 07:01 davemackintosh