Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Select a range of texts from specific line and specific column in textarea

I'm using Blazor Server Side. I want to select certain text from the text inside textarea.

The thing is I got the following info from JSON and pass it the JS function is like parsing a text to extract the errors. So I have the line number first/end and column number first/end

this my json file:

"error 1": [
       {
           "error ": "issue with sometext",
           "lineStart": 3,
           "lineEnd": 3,
           "columnStart": 1,
           "columnEnd": 3
       }
   ],
"error 2": [
       {
           "error ": "issue with sometext",
           "lineStart": 4,
           "lineEnd": 8,
           "columnStart": 2,
           "columnEnd": 5
       }
   ],
"error 3": [
       {
           "error ": "issue with sometext",
           "lineStart": 7,
           "lineEnd": 5,
           "columnStart": 1,
           "columnEnd": 2
       }
   ]

How can I find a function that do that for me. I've tried this function How to select line of text in textarea but it selects/highlights only one line, while in my case I may need to highlight multi-lines. I've made some changes but could not get the solution.

This the function that i tried.

function selectTextareaLine(tarea,lineNum) {
    lineNum--; // array starts at 0
    var lines = tarea.value.split("\n");

    // calculate start/end
    var startPos = 0, endPos = tarea.value.length;
    for(var x = 0; x < lines.length; x++) {
        if(x == lineNum) {
            break;
        }
        startPos += (lines[x].length+1);

    }

    var endPos = lines[lineNum].length+startPos;

    // do selection
    // Chrome / Firefox

    if(typeof(tarea.selectionStart) != "undefined") {
        tarea.focus();
        tarea.selectionStart = startPos;
        tarea.selectionEnd = endPos;
        return true;
    }
}

function CheckText(tarea,lineNum)

{


var tarea = document.getElementById('TareaID');
window.getSelection().removeAllRanges()

 selectTextareaLine(tarea,3); // selects line 3


}

The desired result if I have like this text inside textarea.

Line 1: Say hello to your friend

Line 2: Say hello to your friend

Line 3: Sya hello to your friend

Line 4: Say hello to your friend

so based on the error 1 in json there is an error the third line with the first three digits. because it is 'Sya' and it should Be 'Say' so the desire result is to highlight the line number and column start/end which the 'Say' in our example

Any idea ?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda