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

Keep cursor position on save #553

Merged
merged 2 commits into from Nov 30, 2013
Merged

Keep cursor position on save #553

merged 2 commits into from Nov 30, 2013

Conversation

Gazer
Copy link
Contributor

@Gazer Gazer commented Nov 29, 2013

I've been using openscad a lot these days to start using my reprap 3D printer. Every time I hit "CTRL+S" for save my progress and see what changed, I was frustated by the fact that the cursos reset to the start of the file every time.

This patch aim to solve that problem. Before set the new file content via setPlainText I save the cursor position and the vertical scrollbar position and after the new text is set, I'm restoring that values to the original ones, so the cursor keeps in place and you can continue editing and the preview is updated at the same time.

When opening a new file, y set the content to an empty string, so the call on refreshDocument put the cursor at the start on the new file. Alto I'm doing boundary check to avoid putting the cursor past the last character.

I'm not used to user QT, so I hope the methos used to override the setPlainText is right, if not let me know.

When the file is saving, the cursor position was resetting to the top and you should keep
scrolling by hand every time you save the file.

This patch saves the scroll and cursor position and set it again after the file is refreshed so
we can continue edition from where we were.
Before open a new file now we cleanup the Editor, so the new file get the cursor
on the first character.
@GilesBathgate
Copy link
Contributor

This is a good workaround. But my question is, why does the existing code call setPlainText() when you are saving a file? you getPlainText(), write that to a file, job done.

@Gazer
Copy link
Contributor Author

Gazer commented Nov 29, 2013

The login in mainwindow.cc always relay on refreshDocument to load or reload the current opened file, and in the end is a QFile.readAll and then editor.setPlainText to set the code in the editor.

I thing that there is no reason to reload the file when the file is saving, but I guess that is done this way because is harded to detect if the file must be reload because an "internal save" or need to be reload because an external program change it.

kintel added a commit that referenced this pull request Nov 30, 2013
@kintel kintel merged commit 961c380 into openscad:master Nov 30, 2013
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

3 participants