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

Highlight only visible text #35

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Highlight only visible text #35

wants to merge 5 commits into from

Conversation

Moosems
Copy link
Collaborator

@Moosems Moosems commented May 8, 2023

Here's the current plan:

  1. Create a new tag named "MLCDS" to remember where Docstrings (DS), Multi Line Comments (MLCs), and backstick code areas (markdown) start and end. This tag should not start with "Token" so that it is not deleted later.
  2. Make a method that takes the tokens and tags and areas to remove and returns the tags without those areas.
  3. When highlight() runs, check if anything has changed in the text widget. If not, return. (Things to look for include viewable area, text, and so on.)
  4. Update the code to add MLCDS tags to the text widget where necessary. If a line starts or ends with a Docstring or MLC, add an MLCDS tag to the entire line.
  5. When the visible area of the text widget changes, get the visible area, visible text, and line offset, as before.
  6. Work with the MLCDS tags to add the necessary starts and ends to the visible text and then lex it using Pygments.
  7. Splice the tags to remove parts that are not visible (columns to the left or right of the visible area) and remove tags from emojis.
  8. Add the remaining tags to the visible text and display it in the text widget.
  9. Not in method: update the docs when this is done.
  10. Also not in method: Make sure that when typing, the typing area is viewable (see()).

In summary, the changes will make the text widget display only the visible area, while adding the necessary context outside the viewport using MLCDS tags.

@Moosems Moosems requested a review from rdbende May 8, 2023 19:10
@Moosems
Copy link
Collaborator Author

Moosems commented May 8, 2023

Could you review the plan and give your thoughts/ideas/suggestions/changes?

chlorophyll/codeview.py Outdated Show resolved Hide resolved
chlorophyll/codeview.py Outdated Show resolved Hide resolved
@rdbende
Copy link
Owner

rdbende commented May 8, 2023

I like your plan. The only thing I have concerns about is the emoji-in-tag-range
checking thingy. I'm not sure how would it perform.

@Moosems
Copy link
Collaborator Author

Moosems commented May 8, 2023

Check for a set of characters in the text, if any ranges are found, remove it from any relevant tags (might make a method that takes the tokens and tags and areas to remove and returns the tags without those areas).

@rdbende
Copy link
Owner

rdbende commented May 8, 2023

Check for a set of characters in the text, if any ranges are found, remove it from any relevant tags (might make a method that takes the tokens and tags and areas to remove and returns the tags without those areas).

But that would run on every keypress?

@rdbende rdbende closed this May 8, 2023
@rdbende
Copy link
Owner

rdbende commented May 8, 2023

Oh no

@rdbende rdbende reopened this May 8, 2023
@Moosems
Copy link
Collaborator Author

Moosems commented May 8, 2023

Yes, this runs on every keypress. Maybe I should add a check at the beginning of the method to check if anything has changed and if something has, only then will it all run. Another check could be if the return key was pressed and only highlight the whole thing in that case because otherwise only the line with the cursor needs to be changed.

Repository owner deleted a comment from rdbende May 8, 2023
@Moosems
Copy link
Collaborator Author

Moosems commented May 8, 2023

A method to scroll to where someone types that works properly is also in order.

@Moosems
Copy link
Collaborator Author

Moosems commented May 8, 2023

@rdbende, this runsbefore the highlighting. The issue? The check for MLCDS tags relies on checking for "Token.Literal.String.Doc", "Token.Comment.Multiline", "Token.Literal.String.Backtick" Tokens. What would you recommend? My thought is lex the line with the cursor if it is an insert, removal, or replacement event and use that to determine in that case if the MLCDS tags need updating.

@Moosems
Copy link
Collaborator Author

Moosems commented Jul 20, 2023

I wonder if it's the lexing or tags that takes up the computation time. If it's just the tags then it wouldn't be that hard to simply add the tags that are in the visible area and lex the whole files such that MLCDS isn't an issue otherwise it's going to be the whole arduous process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
2 participants