microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
161.85k stars 28.45k forks source link

Copy paste indent #221574

Open Ianuarius opened 1 month ago

Ianuarius commented 1 month ago

Type: Feature Request

Copy pasting code breaks the indentation. Every time I have to copy and paste a block, I'm spending precious flow-breaking moments reformatting the pasted code, because VSCode cannot retain the correct indentation. Take a look at how Sublime does it. I can focus on work, not hitting tab and backspace a bunch of times just because the editor cannot do it.

VS Code version: Code 1.91.1 (f1e16e1e6214d7c44d078b1f0607b2388f29d729, 2024-07-09T22:06:49.809Z) OS version: Windows_NT x64 10.0.19045 Modes:

RedCMD commented 1 month ago

what language? have a look at the editor.autoIndent setting

Ianuarius commented 1 month ago

Thanks for the reply, RedCMD. Language HTML/PHP. I tried all the editor.autoIndent settings. Nothing was better.

RedCMD commented 1 month ago

can you share a code snippet of a before and after please and you settings file

Ianuarius commented 1 month ago

Here are a couple of examples: And I copy lines by dragging up with mouse, which means, it is taking newline from the previous line. 1. Code initially...

            <button type="button" onclick="document.getElementById('levelup-ikkuna').style.display='none';">Peruuta</button>
            <input type="submit" value="Hyväksy" disabled>
        </div>

Copy this... <input type="submit" id="hyvaksy_nappi" value="Hyväksy" disabled>

Replace the input line, resulting...

            <button type="button" onclick="document.getElementById('levelup-ikkuna').style.display='none';">Peruuta</button>
            <input type="submit" id="hyvaksy_nappi" value="Hyväksy" disabled>
            </div>

So the closing div is now wrong.

2. Code initially...

            </form>
        </div>
<?php
get_footer();
?>

Copy this...

    </main><!-- #main -->
</div><!-- #ensisijainen -->

Paste it in the middle, resulting...

            </form>
        </div>
        </main><!-- #main -->
</div><!-- #ensisijainen -->
<?php
get_footer();
?>

So, this time the closing main is in the wrong location. Or if you're expecting one indentation based on previous lines, then the closing div is in the wrong location.

Settings file: settings.json