You have selected right-to-left mode (bidirectional text), which is used when entering text in (for example) Arabic and Hebrew. It's actually a Firefox keyboard shortcut in Linux and OS X. The behaviour is perfectly correct, but as you found out, it's a little strange if you're not expecting it!
Some additional background reading:
Chen, Raymond. "Whether the Unicode Bidi algorithm is intuitive depends on your definition of 'intuitive'". The Old New Thing, updated October 26, 2012 (retrieved March 2, 2018).
W3C. Unicode Bidirectional Algorithm basics. Updated August 9, 2016 (retrieved March 2, 2018).
Official document from 2011 covering its origin here - Additional Requirements for Bidi in HTML
Latest official document (even longer to read :p)- https://www.w3.org/TR/html-bidi/