Created
June 13, 2012 20:18
-
-
Save camerond/2926259 to your computer and use it in GitHub Desktop.
Get the location of an @reply symbol in a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Implementation for a plugin that allows vaguely-Tweetbot-style @mention autofills. | |
# Finds the index of the @ symbol that should trigger a mention: the @ closest to the typing cursor | |
# that is preceded by a non-word character or the beginning of the string | |
# | |
# "@dave hey" | |
# ^ | |
# | |
# "@john, I thought you should talk to @tony" | |
# ^ | |
# | |
# "john@internet.com is his email address (@dave should know it) | |
# ^ | |
$textarea | |
search_in = $textarea.val().slice(0, $textarea[0].selectionStart) | |
regex = /(^|[\W])@/gi | |
while (sym = regex.exec(search_in)) | |
at_symbol = if sym.index == 0 then sym.index else sym.index + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment