Reputation: 5861
I've been trying to develop a text-editor (as a personal project) using HTML5 canvas, but I've encountered problems with implementing copy / paste / backspace functionality. I've studied the source code for about half-a-dozen projects much like this one, but I still haven't found a solution.
Can anyone recommend a fast, efficient way to implement this sort of functionality?
Upvotes: 1
Views: 951
Reputation: 513
We use such way: focus is in hidden textarea, so ctrl-v works properly. On text change you change your canvas image. You can easy synchronize selection. You can bind textarea "input" event to catch all changes:
Input: This event is sent when a user enters text in a textbox. This event is only called when the text displayed would change, thus it is not called when the user presses non-displayable keys.
I think, this is the best and the only right way (you can't work with clipboard in javascript without it)
Upvotes: 5