I want to implement a line number and column number functionality for a custom code editor kind of project. I don't know how to implement syntax highlighting in a textarea tag, hence contenteditable div. But I am unable to figure out how to get the line number. I want a solution that will work whenever the caret's position is changed by mouse or keyboard.
Asked
Active
Viewed 389 times
2
-
see https://stackoverflow.com/questions/1995370/html-adding-line-numbers-to-textarea/2347259#2347259 – Hamid Shoja Feb 07 '20 at 12:20
-
see https://embed.plnkr.co/plunk/EKgvbm – Hamid Shoja Feb 07 '20 at 12:21
-
Thanks for the response. Actually I want the row number in the backend. The above solution is fine only if you want to display it on the front end. But I am trying to implement cut, copy and paste functionality for which I require the caret's exact position at all times. I can't use textarea as syntax highlighting is not possible in it. – Shubham Jawandhiya Feb 10 '20 at 06:31