Jump to content

Possible to to add a cursor insert location in a Snippet?


Recommended Posts

  • 3 weeks later...

Any way to have a cursor appear in the middle of a snippet after executing?

 

For example:

 

snippet would = "Some text here {cursor would end up here} some more text here" after you call it.

 

Hoping for something similar to how Sublime Text does it with the $1

 

No this currently isn't possible with the Snippets feature. It could potentially be done with AppleScript but it wouldn't be a very elegant solution at all.

Link to comment
Share on other sites

  • 2 years later...

This would be a great addition (I actually assumed it was there already, it's pretty common in other snippet expansion utilities).

 

{cursor} would be fine.  Alternatively, something visual like {|} for the post-expansion cursor location.

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...
  • 2 months later...
  • 2 weeks later...
On 11/8/2016 at 11:40 AM, Andrew said:

{cursor} placement is available in Alfred 3.2 :)

 

Very cool - thanks! I'm running into a possible bug with this feature, specifically in google docs. 

 

I'm trying to make a snippet that will expand to:

[explanation]

[explanation]

 

With the cursor on the middle line. Using...

[explanation]
{cursor}
[explanation]

The result is... confusing:

 

ROWj5U0.gif

 

This doesn't happen in atom or sublime text, and if I use a different key like {date} it works completely as expected.

Link to comment
Share on other sites

@kevbonham I've had a play with Google Docs, and as suspected, the issue is down to Google Docs manipulating what you're pasting and changing it from the original snippet.

 

If your snippet in Alfred consists of:

Quote

 

[explanation]

{cursor}

[explanation]<--- No further line break, your cursor can't go further than immediately after the closing bracket above

 

 

When you paste it in Google Docs, an extra line break is added so your cursor can go to the line BELOW your final closing square bracket. As such, when Alfred then performs the expected number of left arrow actions to return to the right place, it isn't aware of the text manipulation Google has done, and ends up in the wrong location. It's likely that you're seeing normal behaviour in Atom and Sublime Text because they don't add unexpected line breaks.

 

That's not something we can change, as Alfred is agnostic to the pasting destination, so you'll just need to keep the limitations of Google Docs in mind when using cursor placement.

 

Cheers,
Vero

Link to comment
Share on other sites

 

5 hours ago, Vero said:

When you paste it in Google Docs, an extra line break is added so your cursor can go to the line BELOW your final closing square bracket. As such, when Alfred then performs the expected number of left arrow actions to return to the right place, it isn't aware of the text manipulation Google has done, and ends up in the wrong location. It's likely that you're seeing normal behaviour in Atom and Sublime Text because they don't add unexpected line breaks.

 

@Vero Any sense of why it occasionally jumps where the cursor is prior to the paste action? In the last example in the gif I posted, I'm two lines below, but the paste happens inside some of the other text above it. 

 

5 hours ago, Vero said:

That's not something we can change, as Alfred is agnostic to the pasting destination, so you'll just need to keep the limitations of Google Docs in mind when using cursor placement.

 

I understand - thanks for looking into it. I suppose I'll just have to suffer through an extra couple of keystrokes :P

Link to comment
Share on other sites

@kevbonham You may also want to turn on "Slow down simulated key events" in the Snippets > cog in the top right > Tweaking preferences, which ensures that Alfred waits a fraction of a second longer to allow deletions to happen fully before anything is pasted. This ensures the actions happen in the right order if the browser/Google Docs is taking longer than a native app to respond to actions.

 

Cheers,
Vero

Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

@Vero An odd update to this issue (cursor movement in google docs) I stumbled on that might help some people.

 

To reiterate, I have a snippet keyed to `!expl` that looks like this:

 

[explanation]  
{cursor}
[explanation]

Google docs does weird stuff when I use `!expl` to invoke it, but if I invoke from the clipboard viewer, it seems to work (almost) perfectly:

 

e9SMKBl.gif

Edited by kevbonham
Link to comment
Share on other sites

@kevbonham Based on your clip, it looks like the cursor position is being performed before the paste. When you select the snippet from the clipboard viewer, it's a simple paste with no snippet keyword to delete first.

 

As mentioned before, did you check the box to "Slow down key events"? This ensures that there's a little more time between the deletion of the snippet keyword and pasting of your snippet content. I suspect that Google Docs is, by nature, pasting very slowly compared to a normal native application, causing this out-of-sync behaviour.

 

For fear of sounding like I'm repeating myself, Alfred is agnostic to the pasting destination, so if Google Docs is particularly slow due to being a web-based word processor, you'll just have to keep those limitations in mind. :)

 

Cheers,
Vero

Link to comment
Share on other sites

  • 2 months later...

I did try slowing down key events, which doesn't seem to make a difference. My intent was not to suggest that a change needs to be made in Alfred - this feature clearly works great in other editors (I'm starting to write more in markdown anyway, so this isn't as much of an issue for me). Just thought I'd being it up as a workaround for google docs :-)

Link to comment
Share on other sites

@deanishe If you take a look at my reply from earlier on, the issue with Google Docs is that it adds an extra line break when pasting (which isn't included in the snippet itself), which Alfred can't know about.

 

On 11/18/2016 at 0:01 PM, Vero said:

When you paste it in Google Docs, an extra line break is added so your cursor can go to the line BELOW your final closing square bracket. As such, when Alfred then performs the expected number of left arrow actions to return to the right place, it isn't aware of the text manipulation Google has done, and ends up in the wrong location. It's likely that you're seeing normal behaviour in Atom and Sublime Text because they don't add unexpected line breaks.

 

That's not something we can change, as Alfred is agnostic to the pasting destination, so you'll just need to keep the limitations of Google Docs in mind when using cursor placement.

 

No amount of delay will help if Google Docs is adding line breaks. ;) 

 

Cheers,
Vero

Link to comment
Share on other sites

  • 5 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...