When I follow all the instructions (including apple's video) to drag text to create a code snippet in xcode, I get a different system behavior: all I see is the selection ibeam... I can't drag. It just ends up selecting text again. Am i missing some obvious Apple-ism? Thanks
-
Have this problem on Xcode 8, but Xcode 9 worksonmyway133– onmyway1332017-08-24 11:18:34 +00:00Commented Aug 24, 2017 at 11:18
-
OMFG. You need to carefully mouse on top of the actual literal selected text. If you click in empty space, even though it is highlighted, it all deselects. This is extremely stupid. There a billion ways to make a selection go poof. Why make this useful dragging operation so ridiculously hard?Dirk Bester– Dirk Bester2022-12-18 03:19:42 +00:00Commented Dec 18, 2022 at 3:19
-
Use the force touch on the trackpad to drag selected textMohsen Fard– Mohsen Fard2023-03-06 15:57:39 +00:00Commented Mar 6, 2023 at 15:57
6 Answers
Yes, I ran into the same problem, and Apple-ism seems to be a good term for this issue :)
It works this way:
- Select (or highlight) the code your want to turn into a snippet
- EDIT: Click and hold (do not drag!) on any part of the selected text for a short moment (like 2 seconds, sometimes 8 seconds)
- EDIT: The mouse cursor will change icon (not on El Capitan).
- Now you can drag the code over the snippets library, where a green + icon will appear. EDIT: On El Capitan the green icon does not appear, but the frame of the code snippets window will become thinner.
13 Comments
This happened to me as well. The given solution didn't work but still needed to create snippets. This is a workaround although not the best option, it works.
- From Xcode, select the snippet window, and leave it selected.
- Open a text editor app.
- From Xcode, select and copy the code you want to use to create your snippet.
- Paste it into your text editor and then select all of it.
- Now drag&drop normally from the text editor into the snippets window in Xcode.
As said, not the best option but it works.
(Note for Xcode 8.1) Sometimes selecting the text and maintain the mouse button clicked for 3..8 seconds the cursor turns into an arrow and it's possible to D&D. Too bad it only works sometimes...
3 Comments
On High Sierra 10.13.3 and XCode 9 I faced the same problem. The decision that works for me is selecting code on a blank space before the first symbol and then dragging it to the snippets library.
Important: you need to drag only from the blank space (look at the screenshot below). Otherwise you will reselect your code again.
The cursor changes only when you start dragging, so don't be confused and don't wait until it changes.
Comments
I've run into this problem with Xcode 7.2 on Mac OS X 10.11.2 (El Capitan). Click and hold on the selection and the cursor never changes from the I-beam to the arrow for dragging.
Although MLBDG's answer is a usable workaround, I found that quitting and restarting Xcode fixed the problem. This might not work for everyone, but it's worth a try if you're having difficulty.
Comments
The answer is really !undisobvious. You need to select a chunk of text. Then click on actual text characters, but without moving the mouse. Only then will the gods of XCode bequeath unto you a draggable snippet of code to do with as you please. Should you dare to miss the text and click in empty but selected space, the demons of XCode will strike down your selection and make you start from scratch. The unfortunate will not even realise this feature actually exists.
Hold option to duplicate it. For instance to make a duplicate case statement without destroying your copy buffer, then replace the case you cleverly have ready to paste during your search.
As a UI designer it is not obvious to me why this has such an unreliable twitchy implementation.
