Jump to content


Photo

Problema Com Loop


  • Faça o login para participar
18 replies to this topic

#16 Henderson

Henderson

    12 Horas

  • Usuários
  • 279 posts
  • Sexo:Não informado
  • Localidade:Santos

Posted 15/08/2011, 15:06

cara, to testando aqui
seguinte.. pra que tu quer esse code? porque ó, esse código, funciona quando tem ponto à esquerda, ele não seleciona
HTMLTextAreaElement.prototype.wordSelect = function()
{
        if(this.selectionstart !== this.selectionend){
                this.focus();
                return; //sai da função e não retorna nada				
        }

        var startCursor = this.selectionStart;
        var endCursor = this.selectionEnd;
        var txt = this.value;
		alert(startCursor);
		alert(endCursor);
		alert(txt);
        
        while (startCursor-1 >= 0 && txt.charAt(startCursor-1) != ' ' && txt.charAt(startCursor-1) != '\n' && !txt.charAt(startCursor-1).isPoint())
        {
                startCursor--;
        }

        while (endCursor < txt.length && txt.charAt(endCursor) != ' ' && txt.charAt(endCursor) != '\n' && !txt.charAt(endCursor).isPoint())
                endCursor++;
        //alert(startCursor);
        this.selectionstart = startCursor;
        this.selectionend = endCursor;
        this.focus();
		
		alert(startCursor);
		alert(endCursor);
		alert(txt);
};

mas se tu colocar um ponto à direita, ele não vai selecionar nada da palavra, porque logo de começo ele vai achar um ponto e vai parar de mover pra esquerda, tendeu?
acho que vce vai ter que fazer outra abordagem pra isso aí. partir do meio da palavra pras pontas talvez.

Edição feita por: Henderson, 15/08/2011, 15:15.


#17 Rafael P L

Rafael P L

    Novato no fórum

  • Usuários
  • 9 posts
  • Sexo:Masculino
  • Localidade:Campos dos Goytacazes - RJ

Posted 15/08/2011, 15:30

Huahuahuahua. Estou chorando aqui de rir. Gostei do "pelo amor de Deus". Vou testar.

Funcionou garotin. Se é baum mermo eim!!!

Edição feita por: Rafael P L, 15/08/2011, 15:18.


#18 Henderson

Henderson

    12 Horas

  • Usuários
  • 279 posts
  • Sexo:Não informado
  • Localidade:Santos

Posted 15/08/2011, 15:36

hauihaui, tá vendo! se tivesse testado quando falei a primeira vez tinha evitado tudo isso, haihauihauihaui

só lê o que eu postei aí, do problema que vai surgir.
se por exemplo você colocar "teste:" vai dar pau eu acho.

#19 Rafael P L

Rafael P L

    Novato no fórum

  • Usuários
  • 9 posts
  • Sexo:Masculino
  • Localidade:Campos dos Goytacazes - RJ

Posted 15/08/2011, 17:31

Meu camarada, deu certo. Qualquer coisa, se eu precisar de algo a mais eu posto. Segue o código funcionando como pensado inicialmente.

HTMLTextAreaElement.prototype.wordSelect = function()
{
	if(this.selectionStart !== this.selectionEnd){
		this.focus();
		return; //sai da função e não retorna nada
	}

	var startCursor = this.selectionStart;
	var endCursor = this.selectionEnd;
	var txt = this.value;
	
	while (startCursor >= 0 && txt.charAt(startCursor -1) != ' ' && txt.charAt(startCursor) != '\n' && !txt.charAt(startCursor -1).isPoint())
		startCursor--;

	while (endCursor <= txt.length && txt.charAt(endCursor) != ' ' && txt.charAt(endCursor) != '\n' && !txt.charAt(endCursor).isPoint())
		endCursor++;
	//alert(startCursor);

	this.selectionStart = startCursor;
	this.selectionEnd = endCursor;
	this.focus();
};

Edição feita por: Rafael P L, 15/08/2011, 17:46.





1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq