xatkit-bot-platform / xatkit-chat-widget

(React) Chat widget for Xatkit
https://xatkit.com
MIT License
6 stars 2 forks source link

Support for caching last sentence #24

Closed gdaniel closed 4 years ago

gdaniel commented 4 years ago

And reuse it with up arrow.

Reported by @jlcanovas

gdaniel commented 4 years ago

@hamzaed I used a setTimeout call in Sender/index.js to make sure the selection was correctly updated after changing the value when the ArrowUp key is pressed (i.e. the cursor is correctly displayed after the last character of the input). Without the setTimeout the cursor is displayed at the beginning of the input, and moves back to its proper location after typing 1 character.

This looks like a ugly hack but I couldn't find something else to make it work. If you have an idea let me know

hamzaed commented 4 years ago

@gdaniel The problem was that you were mapping arrowUp key which has the default action of moving the cursor to the beginning of the input text.

The solution is to add e.preventDefault(); to onKeyDown. With that, no need to add anything to componentDidUpdate.

I refactored the code and now it's even possible to get all old messages.