Preserve format when copy/paste yaml file#4009
Conversation
|
@mmoulian @LappleApple |
|
Works for me @TheGostKasper -- thanks for jumping on this. |
|
I've tested this branch and verified that copying YAML with the Copy button copies valid YAML and preserves the indents and does not insert extra space between the lines. ✨ But the acceptance criteria mention copying excerpts (so, probably portions of highlighted text):
And this comment from @jpellizzari mentions copying highlighted text but also mention adding a Copy button as an alternative (what this PR does): When I highlight portions of YAML on the web page and copy it with Ctrl+C, this is what I see on paste:
Indentation and space between lines are not preserved. So, @LappleApple @jpellizzari could you please clarify if the acceptance criteria should be edited to only require copying the whole YAML with the Copy button or if the current PR should also include the "copy highlighted text and preserve indentation" functionality? If only the former, I can approve this PR. If the latter is required too, more changes are needed. In principle, this issue could be split into two issues, because the first part is much easier to implement than copying highlighted text with preserving formatting. |
|
I think a So if it makes sense to fix the text-highlighting within this PR, then that is fine. If it's too big of a change, we can merge this and follow up with a PR that fixes the text highlighting. |
|
@jpellizzari OK, fine with me! |
|
@jpellizzari @opudrovs Hi both, I didn't have time to discuss implementation details or add Acceptance Criteria before this got picked up via UI triage and over to Timberwolf. Great to see it moving forward. If you need me to create ACs let me know, but it looks like Jordan's got this? |
|
@opudrovs , the issue here is with On the other hand removing What options we have here ?
The easiest way for now was to show the Icon . |
|
@TheGostKasper hmm, interesting. Would it be possible to, maybe, display line numbers in some common margin (maybe with some before pseudo-elements) but position them absolutely relative to each line span and make them non-selectable? Or if it's overcomplicated (probably it is), the decision depends on the Product's priorities: what is more important, displaying line numbers or being able to select portions of the YAML. Either option is fine with me. The third option (using Regexes to clean up copied text) sounds interesting too and might the least troublesome if the copied text is consistent enough. In principle, I would prefer to switch to another YAML/markdown/rich text component (maybe a third-party solution, whatever works) which supports selecting and copying code without line numbers. It should be such a standard task. 😅 But I am not sure how much time searching for the right component will take, like if it's worth it at all. |
|
@opudrovs changing lineProps to use |
|
@TheGostKasper great, I'll re-test it now. Can you please update the failing snapshot test? |
|
Re-tested it manually, works fine for me in Chrome. Great job! ✨ The only minor issue left is that when selecting and copying a portion of YAML in Firefox, blank lines are inserted between YAML lines. This is what I see when copy-pasting several lines from Chrome (works as expected): and this is what I see when copy-pasting from Firefox: But I think it can be considered a Firefox issue. |



Closes Preserve my formatting when I copy/paste excerpts from WGE UI yaml files
What changed?
Add a copy button to
YamlViewcomponentI updated
CopyToClipboardcomponent to accept different option ( icon , icon + text ) and added it toYamlViewcomponentredirect3-2023-09-13_15.41.52.mp4
redirect3-2023-09-13_15.35.03.mp4