Repository: vscode
Issue: Formatter messes up indentation (even its own)
Labels: bug,typescript,javascript,editor-autoindent

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes/No
yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.95.3
Commit: f1a4fb101478ce6ec82fe9627c43efbf9e98c813
Date: 2024-11-13T14:50:04.152Z
Electron: 32.2.1
ElectronBuildId: 10427718
Chromium: 128.0.6613.186
Node.js: 20.18.0
V8: 12.8.374.38-electron.0
OS: Darwin arm64 24.1.0

Steps to Reproduce:

1. Open the attached TypeScript file in VS Code. Or not, since this site inexplicably won't let me attach the source file. So put the code below in a .ts file and open it in VS Code.
2. Set the default formatter to the built-in JavaScript/TypeScript one.
3. In the formatting settings, have "format on paste" off.
4. Select a full `if` statement and right-click, then say "format selection." Note that the resulting _indentation_ is correct.
5. Put the insertion point in front of the brace on the first line of the `if` statement and press Return. Note incorrect indentation.
6. Undo that and highlight a whole `if` statement, and then cut it.
7. Paste. Note incorrect indentation of the braces and body. If you turn "format on paste" **_on_**, this erroneous pasting behavior stops. But it shouldn't happen with "format on paste" **_off_** either, because you're cutting and pasting entire lines, all the way from the left margin. No reformatting is necessary.
Screen grab attached.https://github.com/user-attachments/assets/b52f28cd-4163-4921-97c0-40e8a88ab7a3

I'm not using any third-party formatter. Also, the JavaScript/TypeScript formatting options are being ignored. Screen shot of those options attached too.![Image](https://github.com/user-attachments/assets/2a14ae86-6c18-4d98-9b62-400650ebdd2f)

This page won't let me attach the source file (fix that), so I'll paste its contents here:

```
class CommManager
{
	public sendOTP(OTP: string, EMail: string, phoneNbr: string): void
	{
        	if (!OTP || (!EMail && !phoneNbr))
        	{
			console.error("Missing OTP or E-mail & phone number for user verification.");
			return;
        	}

        	// This doesn't preclude sending to both, if we want to someday.
    
        	if(EMail)
       		{
			console.log(`Sending OTP to ${EMail}.`);
		}

		if(phoneNbr)
		{
			console.log(`Sending OTP to ${phoneNbr}.`);
		}
	}
}

export const commMgr = new CommManager();

```