Anviking / Chromatism

iOS Syntax Highlighting in Swift
MIT License
100 stars 15 forks source link

Line numbers are required #15

Open zyavrik opened 11 years ago

zyavrik commented 11 years ago

Required support for line numbers.

davemackintosh commented 10 years ago

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

ndrewh commented 10 years ago

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

davemackintosh commented 10 years ago

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

ndrewh commented 10 years ago

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

davemackintosh commented 10 years ago

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

ndrewh commented 10 years ago

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

ndrewh commented 10 years ago

@davemackintosh Overriding the drawRect method is significantly reducing performance.

davemackintosh commented 10 years ago

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!

ndrewh commented 10 years ago

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

Anviking commented 10 years ago

An alternative to overriding -drawRect might be using NSLayoutManager.

davemackintosh commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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

ruddfawcett commented 10 years ago

@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.

davemackintosh commented 10 years ago

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.