Standardize transpose logic. Add basic support for transposing multibyte characters.#45499
Conversation
|
Additionally fixes some strange behavior whereby transposing multibyte characters either deletes them or splits them, corrupting the document. This behavior still exists in some edge cases, not too sure why. |
|
👍 Thank you! |
|
While developing my transpose extension and comparing existing implementations, I noticed differences between the macOS and emacs implementation. Specifically, in: If you have the cursor immediately before B:
I don't know if you care about fixing corner cases, but this might be a useful thing to be aware of, at least. |
|
@Zarel when was this? In current macOS, the behaviour is as you described for emacs, except the cursor remains on the same line: becomes: This, to me, is the most logical because the typical (non-endline) behaviour of transpose is "swap char before with char after, then move cursor after the swapped pair". In this case char before is newline, char after is In fact, now that I look at it, emacs puts the cursor on the next line as well, so I think all is well. With this PR, vscode exactly mirrors TextEdit (except in weird multi-byte corner cases that I mostly but not entirely removed), which I believe also means it exactly mirrors emacs (except emacs doesn't seem to handle multi-byte at all). Nice extension BTW, "splitIntoLines" seems great. Might have to take it. |
|
Oh, huh, yeah, you're right. I was testing in Chrome's |
This fixes #8574 by standardizing "editor.action.transposeLetters" to match standard emacs/MacOS behavior.