Skip to content

Added new config to keep the same line when switching between diffEditors #155395

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Balastrong
Copy link
Contributor

This PR fixes #155036.

Added a new boolean config diffEditor.keepLine.

If enabled, switching between diffEditors with a command (workbench.action.compareEditor.focusPrimarySide, workbench.action.compareEditor.focusSecondarySide, workbench.action.compareEditor.focusOtherSide) will keep the cursor on the same line.

@hediet hediet added this to the July 2022 milestone Jul 18, 2022
@hediet
Copy link
Member

hediet commented Jul 18, 2022

Also, I don't think we need a config for this. I don't see a reason why you would not want the cursors to be synchronized.

@Balastrong
Copy link
Contributor Author

The current implementation jumps to the last focused line, I see it potentially useful for merge conflicts.

Maybe we can keep the config but instead of a boolean we can explicit the "strategy" that would be either corresponding line or last focused and if we see this new feature as way metter, set it as default.

@Balastrong Balastrong force-pushed the feature/155036-sync-curson-on-compare-editor-focus branch from a062f57 to 0e054c6 Compare July 18, 2022 12:23
@Balastrong Balastrong requested a review from hediet July 18, 2022 12:44
@alexdima alexdima modified the milestones: July 2022, August 2022 Jul 29, 2022
@rzhao271 rzhao271 modified the milestones: August 2022, September 2022 Aug 26, 2022
@hediet hediet modified the milestones: September 2022, Backlog Sep 29, 2022
Comment on lines 414 to 431

const configurationService = accessor.get(IConfigurationService);
const keepLine = configurationService.getValue<boolean>('diffEditor.keepLine');

if (keepLine && source) {
const position = source.getPosition();

if (position) {
const equivalentLineNumber = mode === FocusTextDiffEditorMode.Original ?
control.getDiffLineInformationForModified(position.lineNumber)?.equivalentLineNumber :
control.getDiffLineInformationForOriginal(position.lineNumber)?.equivalentLineNumber;

if (equivalentLineNumber !== undefined) {
destination.setPosition(new Position(equivalentLineNumber, position.column));
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this code nicer? It is very deeply nested. Maybe a function with early returns makes sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, you're absolutely right, that nesting is terrible!

I updated the branch now, thanks for pointing it out!

@hediet hediet modified the milestones: Backlog, October 2022 Sep 29, 2022
@hediet hediet modified the milestones: October 2022, November 2022 Oct 25, 2022
@aeschli aeschli modified the milestones: November 2022, December 2022 Nov 29, 2022
@hediet hediet modified the milestones: January 2023, On Deck Jan 26, 2023
@bl-nero
Copy link
Contributor

bl-nero commented Dec 17, 2024

@hediet @Balastrong Hello! I stumbled upon this PR when trying to figure out if it's possible to sync the cursor between diff panels today. Is this PR still expected to be merged? Is there any help needed? It would be shame to leave it like this, unless there's already a different way to do it.

@kupuma-ru21
Copy link

kupuma-ru21 commented Mar 22, 2025

I made an extension kinda same to this.
https://marketplace.visualstudio.com/items?itemName=kupuma-ru21.Cursorghost

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.

Feature Request: Option to sync cursor when using command workbench.action.compareEditor.focusOtherSide
7 participants