Skip to content

Commit

Permalink
Fix anon chat, tab completion and other small stuff (#2477)
Browse files Browse the repository at this point in the history
Fixes #2402 
Fixes #2397 
Fixes #2390 
Fixes #2333
  • Loading branch information
EhsanKia authored and night committed May 29, 2017
1 parent 602d591 commit ceedcc7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/css/betterttv.css
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,8 @@ input, textarea, select {
box-shadow: none;
border-radius: 0;
margin: 6px;
width: calc(100% - 10px);
padding: 6px;
width: calc(100% - 12px);
display: none;
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/anon_chat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AnonChatModule {
});

this.enabled = false;
watcher.on('load.chat', () => this.load());
watcher.on('load.chat_settings', () => this.load());
watcher.on('chat.message', ($el, msgObj) => this.onMessage($el, msgObj));
settings.on('changed.anonChat', () => this.load(true));
}
Expand Down
7 changes: 5 additions & 2 deletions src/modules/better_viewer_list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ let viewList;
let chatterList;
let chatterCount;

function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}

class BetterViewerListModule {
constructor() {
settings.add({
Expand Down Expand Up @@ -108,8 +112,7 @@ class BetterViewerListModule {
results.push({
tag: 'li',
text: users[j],
display: users[j]
// TODO(ehsankia): Replace display name
display: capitalize(users[j])
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/chat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const channelEmotesTip = require('../channel_emotes_tip');
const legacySubscribers = require('../legacy_subscribers');

const EMOTE_STRIP_SYMBOLS_REGEX = /(^[~!@#$%\^&\*\(\)]+|[~!@#$%\^&\*\(\)]+$)/g;
const MENTION_REGEX = /@\b(.*)\b/;
const MENTION_REGEX = /^@([a-zA-Z\d_]+)$/;

const badgeTemplate = (url, description) => `
<span class="balloon-wrapper float-left">
Expand Down
34 changes: 21 additions & 13 deletions src/modules/tab_completion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class TabCompletionModule {
description: 'Shows a tooltip with suggested names when using @ completion'
});

settings.add({
id: 'tabCompletionEmotePriority',
name: 'Tab Completion Emote Priority',
description: 'Prioritize emotes over usernames when using tab completion',
default: false,
});

this.load();
watcher.on('chat.message', ($el, msg) => this.storeUser($el, msg));
watcher.on('load.chat', () => this.resetChannelData());
Expand Down Expand Up @@ -106,7 +113,7 @@ class TabCompletionModule {
if (this.suggestions.length > 0) {
this.tabTries += e.shiftKey ? -1 : 1; // shift key iterates backwards
if (this.tabTries >= this.suggestions.length) this.tabTries = 0;
if (this.tabTries < 0) this.tabTries = this.suggestions.length + this.tabTries;
if (this.tabTries < 0) this.tabTries = this.suggestions.length - 1;
if (!this.suggestions[this.tabTries]) return;

let cursorOffset = 0;
Expand Down Expand Up @@ -154,25 +161,26 @@ class TabCompletionModule {
}

getSuggestions(prefix, includeUsers = true, includeEmotes = true) {
const suggestions = [];
let userList = [];
let emoteList = [];

if (includeEmotes) {
// BTTV Emotes
suggestions.push(...emotes.getEmotes().map(emote => emote.code));

// Twitch emotes
suggestions.push(...this.getTwitchEmotes().map(emote => emote.code));
emoteList.push(...emotes.getEmotes().map(emote => emote.code));
emoteList.push(...this.getTwitchEmotes().map(emote => emote.code));
emoteList = emoteList.filter(word => word.toLowerCase().indexOf(prefix.toLowerCase()) === 0);
emoteList.sort();
}

if (includeUsers) {
// Users
suggestions.push(...this.userList);
userList = Array.from(this.userList).filter(word => word.toLowerCase().indexOf(prefix.toLowerCase()) === 0);
userList.sort();
}

// Filter and sort emotes
return suggestions.filter(word => (
word.toLowerCase().indexOf(prefix.toLowerCase()) === 0
)).sort();
if (settings.get('tabCompletionEmotePriority') === true) {
return [ ...emoteList, ...userList];
} else {
return [...userList, ...emoteList];
}
}

getTwitchEmotes() {
Expand Down

0 comments on commit ceedcc7

Please sign in to comment.