Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support zero-indexed line numbers in TextArea #4471

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

royatt
Copy link
Contributor

@royatt royatt commented May 2, 2024

Possible alternatives:

  • Add this as a keyword argument - IMO this use-case will not be common enough to deserve it's own typed keyword argument being there until the end of time
  • Make the show_line_numbers kw accept an int (with -1 signifying False) - won't add another kw but will terribly hurt readability
  • Split up the source code in such a way it won't require overriding the entire render_line method to do this in one's own project - not worth it, will probably end up being very invasive, while this approach is fairly elegant

Something I still consider adding:

typing this class variable as : Literal[0, 1] to increase clarity of what it's use case really is

@royatt royatt force-pushed the text-area-lines-from-zero branch from cebfe20 to 4b13b49 Compare May 2, 2024 22:20
@darrenburns
Copy link
Member

I don't really understand the benefit of this - why would you want to have the line numbers be zero indexed?

@davep
Copy link
Collaborator

davep commented May 3, 2024

Chiming in with a perspective: I can't personally see any benefit in zero-based line numbers, as a specific feature, but I can see benefits to being able to set the origin number of the line numbers. For example, I might want to create a breakout editor where I'm working on a specific few lines of code, and I want to maintain the line numbers; another reason might be I want to do some sort of narrowing effect.

So perhaps if such a feature were added in some way, it would make sense that it's a way of setting the number of the "first visible line"?

@darrenburns
Copy link
Member

@davep Yeah, I can see that being useful. Rich Syntax offers something similar IIRC.

@royatt
Copy link
Contributor Author

royatt commented May 4, 2024

I don't really understand the benefit of this - why would you want to have the line numbers be zero indexed?

The use case I was going for is I have a sort of a query language embedded into a TextArea that you can submit and then it shows you results (kinda like that cool SQL TUI project named harlequin).

I also have this cool feature where when the language grammar is parsed; if you have a syntax error you get a toast with the error the parser created.

The problem is, the parser shows line number based errors which are zero-index based :(

I did some googling (for this problem in text editors/ programming in general) and found some more use cases, so I'm not totally alone on this it seems (albeit, yes - This might not be a very intuitive thing to add)

@royatt
Copy link
Contributor Author

royatt commented May 4, 2024

Chiming in with a perspective: I can't personally see any benefit in zero-based line numbers, as a specific feature, but I can see benefits to being able to set the origin number of the line numbers. For example, I might want to create a breakout editor where I'm working on a specific few lines of code, and I want to maintain the line numbers; another reason might be I want to do some sort of narrowing effect.

So perhaps if such a feature were added in some way, it would make sense that it's a way of setting the number of the "first visible line"?

Hmm, this can be fairly easily transformed into an instance attribute with no further cost if you think it's better

@willmcgugan
Copy link
Collaborator

I think this is probably best done as a reactive on the widget itself. Possibly also exposed in the constructor.

Suggest we call it line_number_start

@merriam
Copy link

merriam commented May 27, 2024

The use case I could possibly imagine:

My program is popping up a text area to modify one little section of a large annoyingly formatted data file. For example, "change some parameters for the machine Gandalf, but don't let anything else change". The relevant section would be loaded into the buffer, the buffer would be edited in a TextArea, and, after some validation, the annoying file is updated. In that case, setting the starting number of a text area would be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants