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

Virtually prevent pushing code down when new lines are automatically added #94173

Closed
rafaelrenanpacheco opened this issue Apr 1, 2020 · 4 comments · Fixed by #94327
Closed
Assignees
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities suggest IntelliSense, Auto Complete verified Verification succeeded
Milestone

Comments

@rafaelrenanpacheco
Copy link

I would like an option to virtually prevent vscode from pushing down the current focused line when new lines are automatically added. For example, when I click to automatically add an import, vscode adds the import line and the current focused line is scrolled down. This causes a distraction because the line I'm working on is moved away even tho I didn't want to scroll.

Here is a gif showing how IntelliJ behavior when new lines are automatically added above the current selected line. Note that after the import statement is added the current line is virtually kept the same (the line number do change, of course, but the scroll is set to a new position in order to respect the old position):

intellij

The next gif show how vscode pushes down the code and loses the previous virtual position:

vscode

Would be possible to add an option to vscode behavior like IntelliJ in this situation?

@alexdima
Copy link
Member

alexdima commented Apr 1, 2020

Technically, the editor does not scroll. The scrollTop is maintained. It just happens that everything is pushed down by the auto-import which inserts a line at the top of the file.

@jrieken This can be done from the outside if you know there are edits unrelated to the current cursor position in the suggestion e.g.:

const scrollState = StableEditorScrollState.capture(this._editor);
// apply edits unrelated to current cursor position ...
scrollState.restore(this._editor);

@alexdima alexdima assigned jrieken and unassigned alexdima Apr 1, 2020
@jrieken jrieken added feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities suggest IntelliSense, Auto Complete labels Apr 2, 2020
@jrieken jrieken added this to the Backlog milestone Apr 2, 2020
@alpalla
Copy link
Contributor

alpalla commented Apr 2, 2020

I'd like to help out with this! Any additional pointers would be appreciated.

@jrieken
Copy link
Member

jrieken commented Apr 2, 2020

This is where the first potential edit happens:

if (Array.isArray(suggestion.additionalTextEdits)) {
and this is where it is done: . So, those two places should be used to capture and restore the scroll state

@jrieken
Copy link
Member

jrieken commented May 29, 2020

to verify:

  1. scroll down a bit
  2. select a typescript suggestion that adds an import
  3. make sure that the scroll position stays stable (lines aren't pushed down)

@lramos15 lramos15 added verified Verification succeeded and removed verification-needed Verification of issue is requested labels Jun 2, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jun 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities suggest IntelliSense, Auto Complete verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants