From b7cafc532741999f7b8789c7b4928b7a813bb724 Mon Sep 17 00:00:00 2001 From: khlieng Date: Thu, 12 Feb 2015 02:14:56 +0100 Subject: [PATCH] Made backspace work on input history items --- client/src/js/components/MessageInput.jsx | 2 ++ client/src/js/socket.js | 4 ++-- client/src/js/stores/inputHistory.js | 6 ++++-- storage/user.go | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/src/js/components/MessageInput.jsx b/client/src/js/components/MessageInput.jsx index 67bc3f5a..0505ca2d 100644 --- a/client/src/js/components/MessageInput.jsx +++ b/client/src/js/components/MessageInput.jsx @@ -48,6 +48,8 @@ var MessageInput = React.createClass({ inputHistoryActions.increment(); } else if (e.which === 40) { inputHistoryActions.decrement(); + } else if (e.key === 'Backspace' || e.key === 'Delete') { + inputHistoryActions.reset(); } else if (e.key === 'Unidentified') { inputHistoryActions.reset(); } diff --git a/client/src/js/socket.js b/client/src/js/socket.js index ee5b0152..323eaaf7 100644 --- a/client/src/js/socket.js +++ b/client/src/js/socket.js @@ -2,6 +2,8 @@ var EventEmitter = require('events').EventEmitter; var _ = require('lodash'); +var ws = new WebSocket('ws://' + window.location.host + '/ws'); + var socket = { send: function(type, data) { ws.send(JSON.stringify({ type: type, request: data })); @@ -10,8 +12,6 @@ var socket = { _.extend(socket, EventEmitter.prototype); -var ws = new WebSocket('ws://' + window.location.host + '/ws'); - ws.onopen = function() { socket.emit('connect'); }; diff --git a/client/src/js/stores/inputHistory.js b/client/src/js/stores/inputHistory.js index 462d344f..2377b45c 100644 --- a/client/src/js/stores/inputHistory.js +++ b/client/src/js/stores/inputHistory.js @@ -31,8 +31,10 @@ var inputHistoryStore = Reflux.createStore({ }, reset: function() { - index = -1; - this.trigger(history[index]); + if (index !== -1) { + index = -1; + this.trigger(history[index]); + } }, increment: function() { diff --git a/storage/user.go b/storage/user.go index 2b5d4050..c30c2cf8 100644 --- a/storage/user.go +++ b/storage/user.go @@ -20,7 +20,7 @@ type Server struct { type Channel struct { Server string `json:"server"` Name string `json:"name"` - Users []string `json:"users"` + Users []string `json:"users,omitempty"` Topic string `json:"topic,omitempty"` }