mentions in publisher autocomplete within context
This commit is contained in:
parent
150f676332
commit
77403596aa
4 changed files with 45 additions and 12 deletions
|
|
@ -234,7 +234,7 @@ $.Autocompleter = function(input, options) {
|
|||
|
||||
previousValue = currentValue;
|
||||
|
||||
currentValue = options.searchTermFromValue(currentValue);
|
||||
currentValue = options.searchTermFromValue(currentValue, $input[0].selectionStart);
|
||||
if ( currentValue.length >= options.minChars) {
|
||||
$input.addClass(options.loadingClass);
|
||||
if (!options.matchCase)
|
||||
|
|
|
|||
|
|
@ -54,11 +54,21 @@ var Publisher = {
|
|||
textarea.val(formatted);
|
||||
},
|
||||
|
||||
searchTermFromValue: function(value)
|
||||
searchTermFromValue: function(value, cursorIndex)
|
||||
{
|
||||
matches = value.match(/@(.+)/);
|
||||
var atLocation = value.lastIndexOf('@', cursorIndex);
|
||||
if(atLocation == -1){return '';}
|
||||
var nextAt = value.indexOf('@', cursorIndex+1);
|
||||
|
||||
if(nextAt == -1){nextAt = value.length;}
|
||||
if(atLocation < 2){
|
||||
atLocation = 0;
|
||||
}else{ atLocation = atLocation -2 }
|
||||
|
||||
relevantString = value.slice(atLocation, nextAt).replace(/\s+$/,"");
|
||||
matches = relevantString.match(/(^|\s)@(.+)/);
|
||||
if(matches){
|
||||
return matches[1];
|
||||
return matches[2];
|
||||
}else{
|
||||
return '';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,24 +78,46 @@ describe("Publisher", function() {
|
|||
Publisher.form().find('#status_message_fake_message').val());
|
||||
});
|
||||
});
|
||||
describe("input", function(){
|
||||
beforeEach(function(){
|
||||
spec.loadFixture('aspects_index_prefill');
|
||||
});
|
||||
it("returns the status_message_fake_message textarea", function(){
|
||||
expect(Publisher.input()[0].id).toBe('status_message_fake_message');
|
||||
expect(Publisher.input().length).toBe(1);
|
||||
});
|
||||
});
|
||||
describe("autocompletion", function(){
|
||||
describe("searchTermFromValue", function(){
|
||||
var func;
|
||||
beforeEach(function(){func = Publisher.autocompletion.searchTermFromValue;});
|
||||
it("returns everything after an @", function(){
|
||||
expect(func('not @dan grip')).toBe('dan grip');
|
||||
it("returns nothing if the cursor is before the @", function(){
|
||||
expect(func('not @dan grip', 2)).toBe('');
|
||||
});
|
||||
it("returns everything after an @ if the cursor is a word after that @", function(){
|
||||
expect(func('not @dan grip', 13)).toBe('dan grip');
|
||||
});
|
||||
it("returns everything after an @ if the cursor is after that @", function(){
|
||||
expect(func('not @dan grip', 7)).toBe('dan grip');
|
||||
});
|
||||
|
||||
it("returns everything after an @ at the start of the line", function(){
|
||||
expect(func('@dan grip', 9)).toBe('dan grip');
|
||||
});
|
||||
it("returns nothing if there is no @", function(){
|
||||
expect(func('dan')).toBe('');
|
||||
expect(func('dan', 3)).toBe('');
|
||||
});
|
||||
it("returns nothing for just an @", function(){
|
||||
expect(func('@')).toBe('');
|
||||
});
|
||||
it("returns everything after the last @", function(){
|
||||
expect(func('@siojfoi @dan"')).toBe('dan"');
|
||||
expect(func('@', 1)).toBe('');
|
||||
});
|
||||
it("returns nothing if there are letters preceding the @", function(){
|
||||
expect(func('ioj@asdo')).toBe('');
|
||||
expect(func('ioj@asdo', 8)).toBe('');
|
||||
});
|
||||
it("returns everything between @s if there are 2 @s and the cursor is between them", function(){
|
||||
expect(func('@asdpo aoisdj @asodk', 8)).toBe('asdpo aoisdj');
|
||||
});
|
||||
it("returns everything after the 2nd @ if there are 2 @s and the cursor after them", function(){
|
||||
expect(func('@asod asdo @asd asok', 15)).toBe('asd asok');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ src_files:
|
|||
- public/javascripts/vendor/Mustache.js
|
||||
- public/javascripts/vendor/timeago.js
|
||||
- public/javascripts/vendor/facebox.js
|
||||
- public/javascripts/jquery.autocomplete-custom.js
|
||||
- public/javascripts/diaspora.js
|
||||
- public/javascripts/widgets/alert.js
|
||||
- public/javascripts/widgets/embedder.js
|
||||
|
|
|
|||
Loading…
Reference in a new issue