Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve @-mention UX #102

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/lib/stores/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import hueHash from '../hueHash'


const mentionDelim = String.raw`^|$|[,.!?;&<'"\s]|&#39;|&quot;|&amp;`
const mentionFindRe = module.exports.mentionFindRe = new RegExp('(' + mentionDelim + String.raw`)@(\S+?)(?=` + mentionDelim + ')', 'g')
const mentionFindRe = module.exports.mentionFindRe = new RegExp('(' + mentionDelim + String.raw`|[([{])@(\S+?)(?=` + mentionDelim + String.raw`|[)\]}])`, 'g')

const storeActions = module.exports.actions = Reflux.createActions([
'messageReceived',
Expand Down
12 changes: 10 additions & 2 deletions client/lib/ui/ChatEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,25 @@ export default React.createClass({
return
}

// Scan backwards for beginning of word
let wordStart
for (wordStart = wordEnd - 1; wordStart >= 0; wordStart--) {
if (!charRe.test(text[wordStart])) {
break
}
}
wordStart++
if (text[wordStart] === '@') {
wordStart++

// Scan forward for the first @ sign
let mentionStart
for (mentionStart = wordStart; mentionStart < text.length && charRe.test(text[mentionStart]); mentionStart++) {
if (text[mentionStart] === '@') {
wordStart = mentionStart + 1
break
}
}

// Scan forward for end of word
for (; wordEnd < text.length; wordEnd++) {
if (!charRe.test(text[wordEnd])) {
break
Expand Down