|
158 | 158 | }; |
159 | 159 |
|
160 | 160 | // This happens when a chat message is submitted. |
161 | | - const chatHistory = []; |
162 | | - let currrentHistoryIndex = -1; |
163 | 161 | $scope.submitChat = function() { |
164 | 162 | if (chatMessagesService.chatMessage == null || chatMessagesService.chatMessage.length < 1) { |
165 | 163 | return; |
166 | 164 | } |
167 | 165 | chatMessagesService.submitChat(chatMessagesService.chatSender, chatMessagesService.chatMessage, chatMessagesService.threadDetails?.replyToMessageId); |
168 | | - chatHistory.unshift(chatMessagesService.chatMessage); |
169 | | - currrentHistoryIndex = -1; |
| 166 | + chatMessagesService.chatHistory.unshift(chatMessagesService.chatMessage); |
| 167 | + chatMessagesService.currrentHistoryIndex = -1; |
170 | 168 | chatMessagesService.chatMessage = ""; |
171 | 169 | chatMessagesService.threadDetails = null; |
172 | 170 | }; |
173 | 171 |
|
174 | 172 | $scope.onMessageFieldUpdate = () => { |
175 | | - currrentHistoryIndex = -1; |
| 173 | + chatMessagesService.currrentHistoryIndex = -1; |
176 | 174 | }; |
177 | 175 |
|
178 | 176 | $scope.onMessageFieldKeypress = ($event) => { |
|
181 | 179 | //up arrow |
182 | 180 | if ( |
183 | 181 | chatMessagesService.chatMessage.length < 1 || |
184 | | - chatMessagesService.chatMessage === chatHistory[currrentHistoryIndex] |
| 182 | + chatMessagesService.currrentHistoryIndex === -1 || |
| 183 | + chatMessagesService.chatMessage === chatMessagesService.chatHistory[chatMessagesService.currrentHistoryIndex] |
185 | 184 | ) { |
186 | | - if (currrentHistoryIndex + 1 < chatHistory.length) { |
187 | | - currrentHistoryIndex++; |
188 | | - chatMessagesService.chatMessage = chatHistory[currrentHistoryIndex]; |
| 185 | + if (chatMessagesService.currrentHistoryIndex + 1 < chatMessagesService.chatHistory.length) { |
| 186 | + chatMessagesService.currrentHistoryIndex++; |
| 187 | + chatMessagesService.chatMessage = chatMessagesService.chatHistory[chatMessagesService.currrentHistoryIndex]; |
189 | 188 | } |
190 | 189 | } |
191 | 190 | } else if (keyCode === 40) { |
192 | 191 | //down arrow |
193 | 192 | if ( |
194 | 193 | chatMessagesService.chatMessage.length > 0 || |
195 | | - chatMessagesService.chatMessage === chatHistory[currrentHistoryIndex] |
| 194 | + chatMessagesService.chatMessage === chatMessagesService.chatHistory[chatMessagesService.currrentHistoryIndex] |
196 | 195 | ) { |
197 | | - if (currrentHistoryIndex - 1 >= 0) { |
198 | | - currrentHistoryIndex--; |
199 | | - chatMessagesService.chatMessage = chatHistory[currrentHistoryIndex]; |
| 196 | + if (chatMessagesService.currrentHistoryIndex >= 0) { |
| 197 | + chatMessagesService.currrentHistoryIndex--; |
| 198 | + if (chatMessagesService.currrentHistoryIndex >= 0) { |
| 199 | + chatMessagesService.chatMessage = chatMessagesService.chatHistory[chatMessagesService.currrentHistoryIndex]; |
| 200 | + } else { |
| 201 | + chatMessagesService.chatMessage = ""; |
| 202 | + } |
200 | 203 | } |
201 | 204 | } |
202 | 205 | } else if (keyCode === 13) { |
|
0 commit comments