From ffd5eae774bb345862cdff31ecc0112f638f6d6f Mon Sep 17 00:00:00 2001 From: SirStendec Date: Mon, 28 Mar 2016 20:48:58 -0400 Subject: [PATCH] 3.5.150. International keyboard layout support via keypress event for the input handler. Fixed a typo in the My Emoticons menu. --- src/ember/chat-input.js | 125 ++++++++++++++++++++-------------------- src/main.js | 2 +- src/ui/my_emotes.js | 2 +- 3 files changed, 65 insertions(+), 64 deletions(-) diff --git a/src/ember/chat-input.js b/src/ember/chat-input.js index f71716bd..41f16edc 100644 --- a/src/ember/chat-input.js +++ b/src/ember/chat-input.js @@ -4,6 +4,11 @@ var FFZ = window.FrankerFaceZ, is_android = navigator.userAgent.indexOf('Android') !== -1, + CHARCODES = { + AT_SIGN: 64, + COLON: 58 + }, + KEYCODES = { BACKSPACE: 8, TAB: 9, @@ -235,6 +240,7 @@ FFZ.prototype._modify_chat_input = function(component) { t.off("keydown"); t.off("keyup"); + t.on("keypress", this._ffzKeyPress.bind(this)); t.on("keydown", this._ffzKeyDown.bind(this)); t.attr('rows', 1); @@ -261,6 +267,8 @@ FFZ.prototype._modify_chat_input = function(component) { t.off("keyup"); t.off("keydown"); + t.off("keypress"); + t.on("keyup", this._onKeyUp.bind(this)); t.on("keydown", this._onKeyDown.bind(this)); }, @@ -787,6 +795,57 @@ FFZ.prototype._modify_chat_input = function(component) { this.ffzHideSuggestions(); }), + + _ffzKeyPress: function(event) { + var t = this, + e = event || window.event, + key = e.charCode || e.keyCode; + + switch(key) { + case CHARCODES.AT_SIGN: + // If we get an @, show the menu. But only if we're at a new word + // boundary, or the start of the line. + if ( ! this.get('ffz_suggestions_visible') ) { + var ind = selection_start(this.get('chatTextArea')) - 1; + Ember.run.next(function() { + if ( ind < 0 || t.get('textareaValue').charAt(ind) === ' ' ) { + t.ffzShowSuggestions(); + t.trackSuggestions("@"); + } + }); + } + + break; + + case CHARCODES.COLON: + if ( f.settings.input_emoji ) { + var textarea = this.get('chatTextArea'), + ind = selection_start(textarea); + + ind > 0 && Ember.run.next(function() { + var text = t.get('textareaValue'), + emoji_start = text.lastIndexOf(':', ind - 1); + + if ( emoji_start !== -1 && ind !== -1 && text.charAt(ind) === ':' ) { + var match = text.substr(emoji_start + 1, ind - emoji_start - 1), + emoji_id = f.emoji_names[match], + emoji = f.emoji_data[emoji_id]; + + if ( emoji ) { + var prefix = text.substr(0, emoji_start) + emoji.raw; + t.ffzHideSuggestions(); + t.set('textareaValue', prefix + text.substr(ind + 1)); + Ember.run.next(function() { + move_selection(t.get('chatTextArea'), prefix.length); + }); + } + } + }) + } + } + }, + + _ffzKeyDown: function(event) { var t = this, e = event || window.event, @@ -842,34 +901,6 @@ FFZ.prototype._modify_chat_input = function(component) { break; - case KEYCODES.TWO: - // Should: Pop open the suggestions tab if we add an @. This is - // probably not the correct way to check for this, given how - // different region keyboards work. - if ( ! this.get('ffz_suggestions_visible') && (e.shiftKey || e.shiftLeft) ) { - this.ffzFetchNameSuggestions(); - this.set('ffz_suggestions_visible', true); - this.trackSuggestions("@"); - } - - break; - - - /* Not convinced this isn't annoying. - case KEYCODES.HOME: - case KEYCODES.END: - // Navigate through suggestions if those are open. - if ( this.get('ffz_suggestions_visible') && !( e.shiftKey || e.shiftLeft || e.ctrlKey || e.metaKey ) ) { - var suggestions = this.get('ffz_sorted_suggestions'), - current = key === KEYCODES.HOME ? 0 : (suggestions.length - 1); - - this.set('ffz_freeze_suggestions', -1); - this.set('ffz_current_suggestion', current); - e.preventDefault(); - } - - break;*/ - case KEYCODES.PAGE_UP: case KEYCODES.PAGE_DOWN: // Navigate through suggestions if those are open. @@ -923,40 +954,6 @@ FFZ.prototype._modify_chat_input = function(component) { break; - case KEYCODES.COLON: - case KEYCODES.FAKE_COLON: - // If the appropriate setting is enabled and the user has entered - // an actual emoji, we need to replace the name in chat. - - // This is also not the right place to do this. We need to find the - // character that was pressed, not the key. - if ( f.settings.input_emoji && ( e.shiftKey || e.shiftLeft ) ) { - var ind = selection_start(this.get('chatTextArea')); - - ind > 0 && Ember.run.next(function() { - var text = t.get('textareaValue'), - emoji_start = text.lastIndexOf(':', ind - 1); - - if ( emoji_start !== -1 && ind !== -1 && text.charAt(ind) === ':' ) { - var match = text.substr(emoji_start + 1, ind - emoji_start - 1), - emoji_id = f.emoji_names[match], - emoji = f.emoji_data[emoji_id]; - - if ( emoji ) { - var prefix = text.substr(0, emoji_start) + emoji.raw; - t.ffzHideSuggestions(); - t.set('textareaValue', prefix + text.substr(ind + 1)); - Ember.run.next(function() { - move_selection(t.get('chatTextArea'), prefix.length); - }); - } - } - }); - } - - break; - - case KEYCODES.ENTER: if ( e.shiftKey || e.shiftLeft ) break; @@ -977,6 +974,10 @@ FFZ.prototype._modify_chat_input = function(component) { case KEYCODES.SPACE: + // First things first, if we're currently showing suggestions, get rid of them. + if ( this.get('ffz_suggestions_visible') ) + this.ffzHideSuggestions(); + // After pressing space, if we're entering a command, do stuff! // TODO: Better support for commands. var sel = selection_start(this.get('chatTextArea')); diff --git a/src/main.js b/src/main.js index 804861e6..603b9627 100644 --- a/src/main.js +++ b/src/main.js @@ -35,7 +35,7 @@ FFZ.msg_commands = {}; // Version var VER = FFZ.version_info = { - major: 3, minor: 5, revision: 148, + major: 3, minor: 5, revision: 150, toString: function() { return [VER.major, VER.minor, VER.revision].join(".") + (VER.extra || ""); } diff --git a/src/ui/my_emotes.js b/src/ui/my_emotes.js index 079ba369..0a4e1f63 100644 --- a/src/ui/my_emotes.js +++ b/src/ui/my_emotes.js @@ -125,7 +125,7 @@ FFZ.menu_pages.myemotes = { var el = document.createElement("div"); el.className = "emoticon-grid ffz-no-emotes center"; - el.innerHTML = "You have no favorite emoticons.

To make an emote a favorite, find it on the All Emoticons tab and Ctrl-Click it."; + el.innerHTML = "You have no favorite emoticons.

To make an emote a favorite, find it on the All Emoticons tab and Ctrl-Click it."; container.appendChild(el); } },