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

Show line numbers in file editor #916

Open
jelly opened this issue Jan 27, 2025 · 5 comments
Open

Show line numbers in file editor #916

jelly opened this issue Jan 27, 2025 · 5 comments
Labels
enhancement New feature or request

Comments

@jelly
Copy link
Member

jelly commented Jan 27, 2025

Currently our editor lacks line numbers, ideally we add them via CSS.

@jelly jelly added the enhancement New feature or request label Jan 27, 2025
@garrett
Copy link
Member

garrett commented Jan 27, 2025

Note: I have a proof of concept in #509, which I have a demo of (with updated CSS) at https://codepen.io/garrett/pen/qBGPzWZ ... where I just added some additional CSS I suggested in that discussion thread (white-space-collapse: break-spaces; hyphens: none;), to cover the edge cases brought up.

@Mash707
Copy link
Contributor

Mash707 commented Feb 6, 2025

Hi @garrett I would like to explore this. From what I understand is that the changes should be made in editor.scss and editor.tsx. Is there any other information you could provide which can make the implementation simple? I am familiar with CSS and tailwind CSS but haven't explored SCSS much.

@jelly
Copy link
Member Author

jelly commented Feb 7, 2025

@Mash707 you don't really need to know SCSS to work on this, you indeed need to edit the editor files you pointed out.

Look at the demo and try to understand what it does, most importantly test it out while resizing the browser. The resizing case will likely be the most difficult thing to handle.

@Mash707
Copy link
Contributor

Mash707 commented Feb 7, 2025

Thanks for the information @jelly . I'll begin with implementing the demo first and then moving forward we can test out the resizing part.

@jelly
Copy link
Member Author

jelly commented Feb 20, 2025

I looked at the proof of concept from @garrett again, this seems to require a few per-requirsites:

  • fixed line-height for editor
  • fixed column count (we can obtain this from JavaScript)

The text is then iterated over and it is assumed that the word length of a JavaScript string is equal to the width when rendered. Creating a line <-> wrapCount which is a quite elegant solution combined with css variables for the line number container. (Basically removes the need for "empty" elements which other examples do by inserting a non breaking space element for a wrapped line).

However this does not work well with internationalization I tried Japanese with a Japanese Lorem Ipsum and it looks wrong for example in Gedit this renders as:

Image

In your demo:

Image

The main take away here is that I quite like the approach with the line number height and line number container ie.

 .line-number {
    height: calc(var(--character-height) * var(--mod));
    padding: 0 var(--padding-width);
    min-width: 2ch;
  }

But this seems to not apply to Japanese and possibly other languages?

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

No branches or pull requests

3 participants