p42ai / js-assistant

120+ refactorings and code-assists for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=p42ai.refactor
MIT License
125 stars 8 forks source link

Refactor Idea: Move Up / Down Braces to Extend Scope #41

Open hediet opened 2 years ago

hediet commented 2 years ago

Move Brace:

if (!modifiedBaseRange || modifiedBaseRange.isConflicting) {
⟦}⟧

for (const diff of m.rights) {
    const range = diff.outputRange.toInclusiveRange();
    if (range) {
        result.push({
            range,
            options: {
                className: `merge-editor-diff result`,
                description: 'Merge Editor',
                isWholeLine: true,
            }
        });
    }

    if (diff.rangeMappings) {
        for (const d of diff.rangeMappings) {
            result.push({
                range: d.outputRange,
                options: {
                    className: `merge-editor-diff-word result`,
                    description: 'Merge Editor'
                }
            });
        }
    }
}

⟦}⟧ being selected.

--- Move down --->

if (!modifiedBaseRange || modifiedBaseRange.isConflicting) {

    for (const diff of m.rights) {
        const range = diff.outputRange.toInclusiveRange();
        if (range) {
            result.push({
                range,
                options: {
                    className: `merge-editor-diff result`,
                    description: 'Merge Editor',
                    isWholeLine: true,
                }
            });
        }

        if (diff.rangeMappings) {
            for (const d of diff.rangeMappings) {
                result.push({
                    range: d.outputRange,
                    options: {
                        className: `merge-editor-diff-word result`,
                        description: 'Merge Editor'
                    }
                });
            }
        }
    }
⟦}⟧

This should not be confused with move statement up/down:

if (!modifiedBaseRange || modifiedBaseRange.isConflicting) {
⟦⟧}

for (const diff of m.rights) {
    const range = diff.outputRange.toInclusiveRange();
    if (range) {
        result.push({
            range,
            options: {
                className: `merge-editor-diff result`,
                description: 'Merge Editor',
                isWholeLine: true,
            }
        });
    }

    if (diff.rangeMappings) {
        for (const d of diff.rangeMappings) {
            result.push({
                range: d.outputRange,
                options: {
                    className: `merge-editor-diff-word result`,
                    description: 'Merge Editor'
                }
            });
        }
    }
}

--- Move Down --->

for (const diff of m.rights) {
    const range = diff.outputRange.toInclusiveRange();
    if (range) {
        result.push({
            range,
            options: {
                className: `merge-editor-diff result`,
                description: 'Merge Editor',
                isWholeLine: true,
            }
        });
    }

    if (diff.rangeMappings) {
        for (const d of diff.rangeMappings) {
            result.push({
                range: d.outputRange,
                options: {
                    className: `merge-editor-diff-word result`,
                    description: 'Merge Editor'
                }
            });
        }
    }
}

if (!modifiedBaseRange || modifiedBaseRange.isConflicting) {
⟦⟧}