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

Join Lines Redesigned #71678

Closed
wants to merge 4 commits into from
Closed

Conversation

irrationalRock
Copy link
Contributor

@irrationalRock irrationalRock commented Apr 3, 2019

This PR fixes #64655.

It redesigns multi-cursor Join Lines to allow for multiple lines to be merged in.

Before:
JoinLines-TheIssue

Examples:
JoinLines-3Cursor

JoinLines-1Cursor-3Select

JoinLines-2Cursor-2Cursor

JoinLines-Merge-Merge

As a note, it will merge in adjacent selections.

JoinLines-MergeCon

@rebornix rebornix self-assigned this Apr 3, 2019
@irrationalRock irrationalRock changed the title [WIP] Join Lines Redesigned Join Lines Redesigned Apr 8, 2019
@rebornix rebornix added editor-commands Editor text manipulation commands feature-request Request for new features or functionality labels Oct 8, 2020
}
const range = new Range(line, model.getLineMaxColumn(line) - whitespaceAtEnd[0].length, line + 1, model.getLineFirstNonWhitespaceColumn(line + 1));
if (model.getLineContent(line).length > 0) {
Copy link

Choose a reason for hiding this comment

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

Could this be mode.getLineLength(line)?

}
private _getLinesToJoin(editor: IActiveCodeEditor): IJoinLinesOperation[] {
// Construct Join operations
let operations: IJoinLinesOperation[] = editor.getSelections().map((s) => {
Copy link

Choose a reason for hiding this comment

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

nit pick: Could s be named better?

return new Selection(previousValue.startLineNumber, previousValue.startColumn, currentValue.endLineNumber, currentValue.endColumn);
}
let endLineNumber = s.endLineNumber;
if (s.startLineNumber < s.endLineNumber && s.endColumn === 1) {
Copy link

Choose a reason for hiding this comment

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

What is the significance of the magic number 1? Could this is improved by adding a name constant to reveal what 1 means?

}
private _getLinesToJoin(editor: IActiveCodeEditor): IJoinLinesOperation[] {
// Construct Join operations
let operations: IJoinLinesOperation[] = editor.getSelections().map((s) => {
Copy link

Choose a reason for hiding this comment

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

I think operations can be a const?

if (model === null) {
return;
// Merge Join operations which are adjacent or overlapping
let mergedOperations: IJoinLinesOperation[] = [];
Copy link

Choose a reason for hiding this comment

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

I think this can be a constant

}

lineOffset += deleteSelection.endLineNumber - deleteSelection.startLineNumber;
let start = model.getLineFirstNonWhitespaceColumn(startLineNumber);
Copy link

Choose a reason for hiding this comment

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

Can start be constant?

let selectionEndPositionOffset = model.getLineContent(selection.endLineNumber).length - selection.endColumn;
let removeLines = this._getLinesToJoin(editor);
let ops: IIdentifiedSingleEditOperation[] = [];
let conString: String[] = [];
Copy link

Choose a reason for hiding this comment

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

I think this can be a constant

let selectionEndPositionOffset = model.getLineContent(selection.endLineNumber).length - selection.endColumn;
let removeLines = this._getLinesToJoin(editor);
let ops: IIdentifiedSingleEditOperation[] = [];
let conString: String[] = [];
Copy link

Choose a reason for hiding this comment

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

When shortening names it makes it harder to understand what it is used for? What is con? Would naming the variable more clearly make it more readable?

editor.pushUndoStop();
editor.executeEdits(this.id, edits, endCursorState);
editor.executeEdits(this.id, ops, cursorState);
Copy link

Choose a reason for hiding this comment

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

This function is now rather large. Can be be broken down into smaller private functions?

@joaomoreno joaomoreno changed the base branch from master to main February 15, 2021 08:51
@rebornix
Copy link
Member

rebornix commented Oct 21, 2021

I would recommend to implement this experience in an extension. Thanks for your contribution though ❤️

@rebornix rebornix added the *extension-candidate Issue identified as good extension implementation label Oct 21, 2021
@rebornix rebornix closed this Oct 21, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-commands Editor text manipulation commands *extension-candidate Issue identified as good extension implementation feature-request Request for new features or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Joining with multiple cursors on contiguous lines doesn't work as expected
3 participants