Skip to content

Support smart escaping of text when pasting into string expressions (part1).#60036

Merged
CyrusNajmabadi merged 115 commits intodotnet:mainfrom
CyrusNajmabadi:stringCopyPaste
May 3, 2022
Merged

Support smart escaping of text when pasting into string expressions (part1).#60036
CyrusNajmabadi merged 115 commits intodotnet:mainfrom
CyrusNajmabadi:stringCopyPaste

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Mar 8, 2022

WIP for #31869

Initial support for a smart-string-copy-paste system. The general ideas here are:

  1. if you copy code from VS, we can smartly determine what the original context was, to determine how to interpret characters. For example, if the user copies "" from inside a verbatim string (like @" goo "" bar "" baz "), then we can know this represents a single quote character.
  2. when pasting code into a string literal we can use the above information to smartly determine to if we should escape the contents, and how to escape them. For example, if we see that we are pasting text whose value is a single quote character into a verbatim string, then we can double the quote to keep things legal. This allows copy/paste across different string types, while having the contents of the string stay the same, even if the escaping changes.
  3. if pasting come in from an external source, we can't know the context of the text to know what values it actually has. However, we can still ensure that things are properly escaped to keep code parsable.

For all of the above, we ensure that any special work we do happens as a second edit transaction. THat way if the user ever doesn't want the contextual-pasting result, they can undo and get back to exactly the code that pastes normally.

This PR effectively adds the italicized items in this table:

First position of copied region Pasting outside a literal Pasting inside a literal
Inside a text literal Unescape on paste Correct escape sequences that change meaning
Outside a text literal As-is Escape on paste
Raw text (e.g. browser) As-is Escape on paste

--

This is still a WIP as i work through all the combinations of source/destination text forms. In particular interpolated strings and raw strings are compelx in terms of how pasting has to work.

@ghost ghost added the Area-IDE label Mar 8, 2022
@allisonchou allisonchou changed the base branch from release/dev17.3 to main-vs-deps March 31, 2022 18:15
@allisonchou
Copy link
Copy Markdown
Contributor

Re-targeting from release/dev17.3 to main-vs-deps so we can delete the release/dev17.3 branch.

@JoeRobich
Copy link
Copy Markdown
Member

Retargeting to main so we can remove main-vs-deps branch

@JoeRobich JoeRobich changed the base branch from main-vs-deps to main April 6, 2022 19:34
@CyrusNajmabadi CyrusNajmabadi changed the title Support smart escaping of text when pasting into string expressions. Support smart escaping of text when pasting into string expressions (part1). May 3, 2022
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Goign to merge this in. Then, the work to support copy/paste from/to an existing string literal will be done in #61111

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge May 3, 2022 21:02
@CyrusNajmabadi CyrusNajmabadi merged commit 4de4270 into dotnet:main May 3, 2022
@ghost ghost added this to the Next milestone May 3, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the stringCopyPaste branch May 3, 2022 23:48
@Cosifne Cosifne modified the milestones: Next, 17.3 P2 May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants