Forums > MaxMSP

auto-completion text entering


jln
September 17, 2008 | 5:39 pm

Hi,

I’m building a patch to tag my daily files more easily. As my
(meta-)tags are predefined, I’d like them to be automatically added in
[textedit] as I start typing in it. The problem is I’m running a bit
out of idea as for how to implement such a feature. Amongst
unsuccessful methods, I tried the regexp route in order to get which
tags from my predefined list matches what’s being typed in textedit.
However, my knowledge of regular expressions being still close to
none, I could not manage to do it out of trials and errors.

Does someone have another idea to patch such a feature ? For example :
assuming I have a list of tags such as ‘&author= &source= &title=
etc’, the point is to get ‘&author=’ added in [textedit] when I type
‘a’ ; ‘&source=’ if I type ‘s’ etc.

Thanks in advance for any hint

Best,
Julien


September 17, 2008 | 6:19 pm

Hi Julien,
I don’t have access to Max right now to validate this approach, but I think you could do something like this with textedit and standard Max objects.

One limitation is textedit can only set the entire text or append. A fairly straightforward approach would be to make the user type ‘&a’ to autocomplete ‘&author=’ by appending ‘uthor=’. If you really want to type ‘a’ then it’s probably easiest to do something with javascript.

If you’re ok with typing ‘&a’, then here’s what I would do. I’d rely on the user hitting tab to attempt an autocomplete, rather than doing it fully automatically. I think it will be easier to implement *and* to use if you do it this way. So I’d configure textedit to output when enter is pressed, but not output when tab is pressed (I believe it does the opposite by default).

Say you’re typing into textedit and want to autocomplete ‘&a’ -> ‘&author=’, so you type ‘&a’ and then hit tab. The patch will watch the character outlet (the 2nd) for a tab key press. Just figure out what ASCII value is tab and use a [select] to match that. At that point, I’d send an ‘enter’ message to textedit via a [grab], so we can grab the current contents without triggering normal output. Please note there is some funkiness in Max 5 right now and you may need to use a deferlow or delay until 5.0.5 is release (see this thread http://www.cycling74.com/forums/index.php?t=msg&goto=148955)

At this point you have the current text in textedit and you just need to get the last two characters to see if an autocomplete should happen. I’m sure there are various ways to do this in Max, maybe regexp will do it if you capture the last 2 characters with parentheses, something like this .*(..)

Then run the last 2 characters through a [coll] that maps characters to autocompletion text, if there is match, append it to the textedit. ‘&a’ should match to ‘uthor=’, you append that and you should be done. One potential problem is you may have an extra tab character in there. If that is an issue, I have some ideas about how to work around that, or maybe it really would be better to do this all in javascript…

And unfortunately this approach will not work if you put the cursor in the middle of some text and try to autocomplete. It will only work when appending at the end of the text. Again, javascript could solve this.

Anyway, maybe that will give you some ideas. If you are stuck, I might have some time to try this later.


September 17, 2008 | 6:21 pm

Sorry, I forgot. We are not supposed to use the ‘enter’ message for textedit. So when I said send ‘enter’ -> [grab] -> [textedit], that should have been a ‘bang’. That’s discussed in the thread I referred to.


September 17, 2008 | 6:44 pm

bonsoir julien

have a look at this patch, it’s pretty much Adam way but I read his post
after finishing m example so… here is it ;)

Ciao

ps: you have to type a "key" to trigger autocompletion, here "&a" will
be replaced by "&author", etc…

max v2;

#N vpatcher 15 55 729 644;
#P window setfont "Sans Serif" 9.;
#P newex 161 76 59 9109513 r $0-textEdit;
#P newex 457 233 40 9109513 atoi;
#P newex 468 376 41 9109513 prepend;
#P newex 552 247 29 9109513 zl len;
#P newex 521 199 40 9109513 atoi;
#P user textedit 146 104 339 177 32788 139 9 let’s try auto &author &title;
#P window setfont "Sans Serif" 9.;
#N coll ;
#T flags 1 0;
#T store &a &author;
#T store &s &source;
#T store &t &title;
#P newobj 482 70 53 196617 coll;
#P newex 237 214 33 196617 sel 38;
#P newex 237 241 19 196617 t 1;
#P newex 237 268 45 196617 gate;
#P newex 237 294 27 196617 t 0 i;
#P newex 254 376 75 196617 prepend symbol;
#P newex 254 353 40 196617 itoa;
#P message 254 322 31 196617 38 $1;
#P newex 482 94 63 196617 route symbol;
#P newex 237 186 45 196617 t i i;
#P newex 482 119 40 196617 t s b b;
#P newex 521 146 27 196617 grab;
#P newex 521 174 48 196617 route text;
#P newex 521 225 72 196617 t l l l;
#P newex 521 298 41 196617 zl ecils;
#P newex 583 247 45 196617 zl sub 32;
#P newex 552 270 41 196617 -;
#P newex 497 322 34 196617 zl reg;
#P newex 497 348 57 196617 prepend set;
#P newex 468 400 40 196617 itoa;
#P newex 468 444 57 196617 prepend set;
#P newex 468 422 59 196617 fromsymbol;
#P newex 468 467 61 196617 s $0-textEdit;
#P fasten 11 1 23 0 543 168 574 168 574 50 151 50;
#P connect 28 0 23 0;
#P connect 23 1 13 0;
#P connect 13 0 21 0;
#P connect 21 0 20 0;
#P connect 20 0 19 0;
#P connect 18 0 19 0;
#P connect 19 0 18 0;
#P connect 18 1 15 0;
#P connect 15 0 16 0;
#P connect 16 0 17 0;
#P connect 13 1 19 1;
#P connect 12 0 27 0;
#P connect 27 0 26 0;
#P connect 4 0 26 0;
#P connect 26 0 3 0;
#P connect 3 0 1 0;
#P connect 1 0 2 0;
#P connect 2 0 0 0;
#P connect 17 0 22 0;
#P connect 22 0 14 0;
#P connect 14 0 12 0;
#P connect 12 1 5 0;
#P connect 5 0 4 0;
#P connect 12 2 11 0;
#P connect 11 0 10 0;
#P connect 10 0 24 0;
#P connect 24 0 9 0;
#P connect 9 0 8 0;
#P connect 8 0 5 1;
#P connect 9 1 25 0;
#P connect 25 0 6 0;
#P connect 6 0 8 1;
#P connect 9 2 7 0;
#P connect 7 0 6 1;
#P pop;


September 17, 2008 | 6:57 pm

… slightly simpler :

max v2;
#N vpatcher 15 55 729 644;
#P window setfont "Sans Serif" 9.;
#P newex 161 76 59 9109513 r $0-textEdit;
#P newex 452 212 40 9109513 atoi;
#P newex 464 301 41 9109513 prepend;
#P newex 512 197 40 9109513 atoi;
#P user textedit 146 104 339 177 32788 139 9 bon &author ca narche
&title &source;
#P window setfont "Sans Serif" 9.;
#N coll ;
#T flags 1 0;
#T store a &author;
#T store s &source;
#T store t &title;
#P newobj 482 70 53 196617 coll;
#P newex 237 214 33 196617 sel 38;
#P newex 237 241 19 196617 t 1;
#P newex 237 268 45 196617 gate;
#P newex 237 294 27 196617 t 0 i;
#P newex 254 345 75 196617 prepend symbol;
#P newex 254 322 40 196617 itoa;
#P newex 482 94 63 196617 route symbol;
#P newex 237 186 45 196617 t i i;
#P newex 482 119 40 196617 t s b b;
#P newex 512 144 27 196617 grab;
#P newex 512 172 48 196617 route text;
#P newex 464 325 40 196617 itoa;
#P newex 464 369 57 196617 prepend set;
#P newex 464 347 59 196617 fromsymbol;
#P newex 464 392 61 196617 s $0-textEdit;
#P newex 512 223 44 196617 zl ecils 2;
#P newex 492 247 30 196617 zl reg;
#P newex 492 271 57 196617 prepend set;
#P fasten 8 1 19 0 534 168 574 168 574 50 151 50;
#P connect 23 0 19 0;
#P connect 19 1 10 0;
#P connect 10 0 17 0;
#P connect 17 0 16 0;
#P connect 16 0 15 0;
#P connect 14 0 15 0;
#P connect 15 0 14 0;
#P connect 14 1 12 0;
#P connect 12 0 13 0;
#P connect 10 1 15 1;
#P connect 9 0 22 0;
#P connect 0 0 21 0;
#P connect 22 0 21 0;
#P connect 21 0 6 0;
#P connect 6 0 4 0;
#P connect 4 0 5 0;
#P connect 5 0 3 0;
#P connect 13 0 18 0;
#P connect 18 0 11 0;
#P connect 11 0 9 0;
#P connect 9 1 1 0;
#P connect 1 0 0 0;
#P connect 9 2 8 0;
#P connect 8 0 7 0;
#P connect 7 0 20 0;
#P connect 20 0 2 0;
#P connect 2 0 1 1;
#P pop;



jln
September 17, 2008 | 9:34 pm


Viewing 6 posts - 1 through 6 (of 6 total)