Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created October 16, 2010 22:24
Show Gist options
  • Save rwaldron/630341 to your computer and use it in GitHub Desktop.
Save rwaldron/630341 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="script.js"></script>
</head>
<body>
<textarea id="whatever">foo bar #hash</textarea>
Proof Of Concept: If you arrow right until just before the #hash and type shift-@, a "faked" autocomplete will trigger and insert @user - but will retain the string following. Currently, if you try this in #newTwitter, it will blow away any text following the autocompleted @user.
</body>
</html>
$(function() {
// Proof of concept
var handleCurrentInput = function (e) {
var $this = $(this),
valStr = $this.val(),
valArr, lastIndexAt, lastItem;
if ( e.shiftKey && e.which === 50 ) {
lastIndexAt = valStr.lastIndexOf('@');
valArr = valStr.split('@');
lastItem = valArr.pop();
// fake logic that pretends to be twitter user autocomplete
valArr.push('@user ')
valArr.push(lastItem);
$this.val(valArr.map(function(str) {
return $.trim(str);
}).join(' '));
}
};
$('textarea')
.bind('keyup', handleCurrentInput)
.trigger('focus');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment