JSFiddle - React, Tailwind, and code Playground
HTML
<textarea id="textEditor" wrap="off" style="width:400px;height:150px;">Este Ă© um exemplo de teste de um text area
putz, quebrei a linha
denovo</textarea>
Linha: <span id="spanLinha">1</span>
Coluna: <span id="spanColuna">1</span>
JavaScript
var textEditor = document.getElementById('textEditor');
var spanLinha = document.getElementById('spanLinha');
var spanColuna = document.getElementById('spanColuna');
function refreshColumn()
{
var linha = 1;
var coluna = 1;
var selectionStart = textEditor.selectionStart;
var value = textEditor.value;
for(var i = 0; i < value.length; i++)
{
if(i == selectionStart)
break;
var ch = value.charAt(i);
if(ch == "\n")
{
linha++;
coluna = 1;
}
else
coluna++;
}
spanLinha.innerHTML = linha;
spanColuna.innerHTML = coluna;
}
textEditor.onkeyup = function() { refreshColumn(); }