XVim2: Relativenumber not work.

XVim2 work for me, but when I set up my .xvimrc as below,

set relativenumber

the relative number not appear in my Xcode9. Did I miss something?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 20 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Do we have any movement on this issue? Would love to have relative numbers support on 9.2. Thanks to all the contributors for their hard work, XVIM is a really amazing tool.

+1 for relative numbers

Hi, just want to say I really enjoy XVim2 and Vim mode is an absolute must for me when using an editor. Also as mentioned earlier in this thread, I’ve also grown custom to the relative line numbers and it’s quite shitty when they’re not there.

That being said I have tried over the last couple of days to find a way to get it working in this project, but I think I need some help from somebody with a bit more experience in both Obj-C (haven’t touched it in five years I think) and the type of project XVim2 is. My experience is solely with iOS apps, so I feel I’m lacking the fundamental stuff here.

Okay, so I have managed to scrap together a somewhat really buggy thingy, that in my opinion is better than not having any form of relative line numbering at all. It has the following bugs/features:

  • Shows relative line numbering when moving around, but might have to do a key stroke to make it visible (again) if it’s a first launch or some other command has been executed. I haven’t figured out where to put the code so that it always will replace the normal numbering.
  • It only works when Line Wrapping is turned off. Line wrapping screws up the math for calculating which line it is, based on the Y coordinate.
  • It respects the relativenumber setting in .xvimrc
  • It may break with other settings than mine given that I use the Y coordinate of the layer to calculate which line number I’m dealing with. I haven’t tested this fully.

Okay so please test if you wish, and pretty please help me solve this by submitting code or pointers. Anything is appreciated. I really wish to see relative numbers fully functioning in the XVim2 project.

Fork/branch: https://github.com/kentrh/XVim2/tree/relative-line-numbers Code: https://github.com/kentrh/XVim2/blob/relative-line-numbers/XVim2/XVim/XVimWindow.m#L519 Screenshot: rn

Unfortunately, I haven’t had the time to look into this again. Sorry 😞

I think so, relative numbers not being displayed is no longer an issue.

@kentrh This is amazing! Thank you very much for you work! Please feel free to claim the bounty at https://www.bountysource.com/issues/50244706-relativenumber-not-work

Should this issue be closed now that @kentrh’s excellent work has been merged?

@kentrh YOU. ARE. A. LEGEND!

Thank you so much for this. I’d love to get you a drink, have you got a PayPal or somewhere similar where to send it?

I checked out your branch, run make and took it for a quick spin. I noticed a few things:

Not working on first launch. You mentioned this in your comment but I wanted to report that the only way I found to enable it was to run :set relativenumber from normal mode

Not respecting font size. This is a minor detail, but, as you can see below, the font size of the number is not the same as they were originally. I suppose there must be a way to read the font size and apply it to the new views your code adds.

XVim-Demo-1

Line number goes to 1 when on one-before-the-last line

image

I’ll be using it more today and report here with other findings.

This is super promising. As far as I’m concerned, unless someone spots a bug, it should make it into develop ASAP.

It’s an optional feature, so even if it’s not super polished it’s okay. Also, I think it’s fair to say that most of the users of XVim are tinkerer and can understand the complexity of getting this kind of stuff working.

Again, thank you so much! ❤️ You are awesome!

I’m trying to look into this, but I have no idea of what I’m doing?

What’s a good place to start?

@kr15hna suggested:

line numbers are handled by “SourceEditor.SourceEditorGutterMarginContentView” it has an array of “SourceEditor.SourceEditorFontSmoothingTextLayer” for each line and looks like this contentView is reusing these layers.It seems tough to use these layers for relative number, Is it fine to add a new view? overlaying SourceEditorGutterMarginContentView and handle numbering on our own.

How can we get a reference to that class? So far in my reverse engineering I’ve been able to see the subviews of XVimIDEPegasusSourceEditorView.

screen shot 2018-11-21 at 8 49 08 am

Among them I can see a ChangeGutterMarginView, which I think matches this:

https://github.com/XVimProject/XVim2/blob/76852cf78332f53252eadb4f281f6530fbd2cb5f/XVim2/Xcode10/IDESourceEditor/_TtC15IDESourceEditorP33_7E074BCA936D0EABA73257D5271D839D22ChangeGutterMarginView.h#L9-L21

I might be wrong though. I tried to call isFlipped on it and it didn’t work, but I don’t know why:

screen shot 2018-11-21 at 8 50 04 am

Any ideas if I’m on the right track?

Ideally I’d like to:

  1. Somehow get a references to the gutter view
  2. Find out how to modify its content
  3. Write logic to derive the array of relative line numbers from the current one
  4. Understand where the hook for any line movement in the source window is
  5. Modify the content of the gutter after a movement