Example #1
0
/*
 * Expand a doubleclick at p0, return the resulting range.
 */
Range
text_doubleclick(Text *t, ulong p0) {
	int c, i;
	Rune *r, *l;
	Range	dot;

	assert (p0 <= t->length);
	dot.p0 = dot.p1 = p0;
	for(i=0; left[i]; i++){
		l = left[i];
		r = right[i];
		/* try left match */
		if(p0 == 0){
			Tgetcset(t, p0);
			c = '\n';
		}else{
			Tgetcset(t, p0-1);
			c = Tgetc(t);
		}
		if(c!=-1 && strrune(l, c)){
			if(clickmatch(t, c, r[strrune(l, c)-l], 1)){
				dot.p0 = p0;
				dot.p1 = t->pos-(c!='\n');
			}
			assert(ROK(dot));
			return dot;
		}
		/* try right match */
		if(p0 == t->length){
			Tbgetcset(t, p0);
			c = '\n';
		}else{
			Tbgetcset(t, p0+1);
			c = Tbgetc(t);
		}
		if(c !=-1 && strrune(r, c)){
			if(clickmatch(t, c, l[strrune(r, c)-r], -1)){
				dot.p0 = t->pos;
				if(c!='\n' || t->pos!=0 ||
				   (Tgetcset(t, 0),Tgetc(t))=='\n')
					dot.p0++;
				dot.p1 = p0+(p0<t->length && c=='\n');
			}
			assert(ROK(dot));
			return dot;
		}
	}
	/* try filling out word to right */
	Tgetcset(t, p0);
	while((c=Tgetc(t))!=-1 && okchar(c, notdoubleclick))
		dot.p1++;
	/* try filling out word to left */
	Tbgetcset(t, p0);
	while((c=Tbgetc(t))!=-1 && okchar(c, notdoubleclick))
		dot.p0--;
	assert(ROK(dot));
	return dot;
}
Example #2
0
File: moveto.c Project: 8l/sam
void
doubleclick(File *f, Posn p1)
{
	int c, i;
	Rune *r, *l;

	if(p1 > f->nrunes)
		return;
	f->dot.r.p1 = f->dot.r.p2 = p1;
	for(i=0; left[i]; i++){
		l = left[i];
		r = right[i];
		/* try left match */
		if(p1 == 0){
			Fgetcset(f, p1);
			c = '\n';
		}else{
			Fgetcset(f, p1-1);
			c = Fgetc(f);
		}
		if(c!=-1 && strrune(l, c)){
			if(clickmatch(f, c, r[strrune(l, c)-l], 1)){
				f->dot.r.p1 = p1;
				f->dot.r.p2 = f->getcp-(c!='\n');
			}
			return;
		}
		/* try right match */
		if(p1 == f->nrunes){
			Fbgetcset(f, p1);
			c = '\n';
		}else{
			Fbgetcset(f, p1+1);
			c = Fbgetc(f);
		}
		if(c!=-1 && strrune(r, c)){
			if(clickmatch(f, c, l[strrune(r, c)-r], -1)){
				f->dot.r.p1 = f->getcp;
				if(c!='\n' || f->getcp!=0 ||
				   (Fgetcset(f, (Posn)0),Fgetc(f))=='\n')
					f->dot.r.p1++;
				f->dot.r.p2 = p1+(p1<f->nrunes && c=='\n');
			}
			return;
		}
	}
	/* try filling out word to right */
	Fgetcset(f, p1);
	while((c=Fgetc(f))!=-1 && alnum(c))
		f->dot.r.p2++;
	/* try filling out word to left */
	Fbgetcset(f, p1);
	while((c=Fbgetc(f))!=-1 && alnum(c))
		f->dot.r.p1--;
}
Example #3
0
void
doubleclick(File *f, Posn p1)
{
	int c, i;
	Rune *r, *l;
	Posn p;

	if(p1 > f->nc)
		return;
	f->dot.r.p1 = f->dot.r.p2 = p1;
	for(i=0; left[i]; i++){
		l = left[i];
		r = right[i];
		/* try left match */
		p = p1;
		if(p1 == 0)
			c = '\n';
		else
			c = filereadc(f, p - 1);
		if(strrune(l, c)){
			if(clickmatch(f, c, r[strrune(l, c)-l], 1, &p)){
				f->dot.r.p1 = p1;
				f->dot.r.p2 = p-(c!='\n');
			}
			return;
		}
		/* try right match */
		p = p1;
		if(p1 == f->nc)
			c = '\n';
		else
			c = filereadc(f, p);
		if(strrune(r, c)){
			if(clickmatch(f, c, l[strrune(r, c)-r], -1, &p)){
				f->dot.r.p1 = p;
				if(c!='\n' || p!=0 || filereadc(f, 0)=='\n')
					f->dot.r.p1++;
				f->dot.r.p2 = p1+(p1<f->nc && c=='\n');
			}
			return;
		}
	}
	/* try filling out word to right */
	p = p1;
	while(p < f->nc && alnum(filereadc(f, p++)))
		f->dot.r.p2++;
	/* try filling out word to left */
	p = p1;
	while(--p >= 0 && alnum(filereadc(f, p)))
		f->dot.r.p1--;
}