82

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

3
  • Have this problem on Xcode 8, but Xcode 9 works Commented 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? Commented Dec 18, 2022 at 3:19
  • Use the force touch on the trackpad to drag selected text Commented Mar 6, 2023 at 15:57

6 Answers 6

147

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.
Sign up to request clarification or add additional context in comments.

13 Comments

Following these instructions I fail more often than I succeed. I don't understand how it can be so hard to drag and drop some text. Also the user interface for creating code snippets could be much improved. This is an extremely awkward way of managing your code snippets.
if you use a trackpad you can use the three finger drag gesture (support.apple.com/en-us/HT204609) in place of steps 2 and 3
On a Macbook with Force Touch trackpad running 10.11 El Capitan and 7.2 Xcode, the solution of selecting text, click and hold, then drag to snippets library works, but with the following caveat: you must click in the blank space to the right of your text within the selection, and when you hold, the cursor will not change. I count until 3 and then drag. It's pretty reliable, although I forget about clicking in the blank space pretty frequently ;)
My problem was that I wasn't waiting long enough. Rather than the usual 2 seconds, it was taking like 8 seconds before the cursor would change.
In xcode 8 / macos sierra it takes me 10 seconds to activate! The cursor changes from an "I-beam" to a regular arrow cursor. WTF, this must surely be the most hidden UI interaction Apple ever dreamed up. Why not just make a "create snippet" button and let me paste the code in?
|
14

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.

  1. From Xcode, select the snippet window, and leave it selected.
  2. Open a text editor app.
  3. From Xcode, select and copy the code you want to use to create your snippet.
  4. Paste it into your text editor and then select all of it.
  5. 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

ML, if you're a Windows user, I'd suspect, despite your comment, that the problem is the following, because the explanations above are ever so slightly lacking. The drag technique requires what I'm told is the perfectly routine and expected (!) Mac method for drag-and-drop: after 1) selecting (highlighting) some text, and then 2) clicking it in anticipation of dragging, one must wait approximately 1/4 second before actually moving the mouse to drag. I believe the display gives some feedback cue. In Windows there is no dependency on doing that 1/4 second delay. Please report back. Thanks
Jack, I'm a Mac user. There could be a bug which is still not fixed by Apple. Some users (me included) can use "Drag&Drop" without problem in their system. However, specifically inside Xcode can happen that Drag&Drop does not work, even "Selecting the text, wait until the cursor changes to arrow etc". So I believe this workaround, as I said, not the best option but functional until this bug is fixed.
Using a second app was the only way that worked for me. Why no buttons Apple? Shortcut maybe, drag and drop... not necessary.
9

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.

enter image description here

Comments

2

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

0
  1. just highlight your text
  2. copy in filter text field that u can see on your bottom of snippet library
  3. paste the text
  4. now select the text and drag from there to snippet library

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.