Skip to content

Keep cursor position when tidying code #1223

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

Closed
jpgualdarrama opened this issue Dec 3, 2019 · 9 comments · Fixed by #1788
Closed

Keep cursor position when tidying code #1223

jpgualdarrama opened this issue Dec 3, 2019 · 9 comments · Fixed by #1788
Labels
Priority:High Should be addressed soon but not critical

Comments

@jpgualdarrama
Copy link
Contributor

Nature of issue?

  • Existing feature enhancement

Feature enhancement details:

The tidying code feature resets the cursor back to the beginning of the file that was tidied. For long files, this can be irksome, because you then have to scroll back to your position. It would be helpful to keep the cursor position from before the tidying.

@welcome
Copy link

welcome bot commented Dec 3, 2019

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

@catarak
Copy link
Member

catarak commented Dec 5, 2019

thanks for the suggestion! i think this feature is a little hard to add because the number of characters/lines might change, and therefore putting the cursor in the "same" position might actually be a different position. i was trying to find example code for why implemented this with beautify-js in the first place, and i couldn't find anything, so maybe code tidy in general could use a revisit?

@catarak catarak added Priority:Medium Moderately important, should be completed in a fair timeframe Feature Request Proposal for adding a new functionality labels Dec 5, 2019
@ashu8912
Copy link
Contributor

@catarak I can Work On This Feature if its not already taken.

@ashu8912
Copy link
Contributor

#1240 raised a pr that fixes this

@catarak catarak added type:bug Priority:High Should be addressed soon but not critical and removed Feature Request Proposal for adding a new functionality Priority:Medium Moderately important, should be completed in a fair timeframe labels Feb 11, 2021
@catarak
Copy link
Member

catarak commented Feb 11, 2021

I notice that with #1240 the cursor jumps forward in the line when running tidy code. I believe the fix for this would be removing the part that adds INDENTATION_AMOUNT.

@satyasaibhushan
Copy link
Contributor

Hey @catarak,
You are true about INDENTATION_AMOUNT causing the cursor jump,
But, we are not able to sustain the cursor position as required.
For example, In the video provided, the firstly the horizontal position is not retained and next the vertical position is not.
I think this might require opening a new different issue, Please give your thoughts.

Screen.Recording.2021-02-22.at.11.00.05.PM.mov

@catarak
Copy link
Member

catarak commented Mar 3, 2021

Thanks for posting the video! The library that this project is currently using, beautify-js, does not support code formatting with a cursor position. We can add some code that would get the cursor position pretty close, by preserving its line/column, but this is imperfect when the code formatting changes the number of lines of code. I believe this project would have to switch to using Prettier to fix this, which I just added as a dependency anyway.

@satyasaibhushan
Copy link
Contributor

Hey @catarak ,
After hours of searching, I've figured out using prettier. There is still a bit of work to do.
Do you want me to open a new issue by closing this one or should we work on this one itself?

@satyasaibhushan
Copy link
Contributor

Never mind,
I've figured it out and am attaching a PR

catarak added a commit to satyasaibhushan/p5.js-web-editor that referenced this issue Mar 4, 2021
catarak added a commit to satyasaibhushan/p5.js-web-editor that referenced this issue Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:High Should be addressed soon but not critical
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants