
AutoJS – JS library for textarea lookahead - atmb4u
http://atmb4u.github.io/AutoJS/
======
dspillett
When I type quickly I often hit on key before properly releasing the next (I
am a terrible typist in other ways too, chances are many other people are
likewise!). This seems to make your code think I've accepted the current
suggestion so I end up with extra words embedded in what I am typing, for
instance "test" comes out as "termst" if the bad key event ordering occurs
with the e and s keys.

 _It works great if I make an effort to properly release one key before
touching the next though,_ and I suspect this problem could be checked for and
mitigated with a little extra logic in your event handlers.

~~~
atmb4u
Will definitely look into this issue. Thanks for the suggestion.

~~~
grandpa
This is what happened when I tried typing the first sentence on your web site:
[http://i.imgur.com/jQGHwQc.png](http://i.imgur.com/jQGHwQc.png)

------
underwater
Please don't go adding this to your production websites. It's incredibly buggy
when using any kind of non-standard input. A few examples:

* IME input is broken. If I type "s" and "a" with my keyboard set to Katakana I should see "サ" and not "sア".

* Adding accented characters on OS X (hold down a vowel key) doesn't do what I'd expect. Pressing "e" and selecting a variant inserts the first suggestion giving me "êven".

* Entering text at the beginning of input is not possible. Trying to do so constantly moves the cursor to the end.

* Spellcheck underlines disappear. Browsers won't recheck the entire input after each keystroke, just the last few words. They also stop underlining when you change the input value. This means that any incorrectly spelled words lose their highlight if not near the cursor.

* There seems to be no consideration for how this will work for users who rely on a screen reader.

Few of these browser and OS features expose APIs to JavaScript. You have to
build your application around their behavior from the ground up. The approach
used by this script of mutating the value and modifying selection is
completely broken.

~~~
underwater
This effect is better achieved by using two nodes. At Facebook we have the
main input positioned over a node that shows the same content with the suffix
appended. This is the same technique we use to show highlighted names in the
comment field.

------
tzaman
This has a huge usability flaw: if I write a short word and press space (which
is very common), the recommended word gets put in instead of my short word and
then I have to backspace it. Kudos for the effort but I don't see this being
very usable.

------
CaveTech
Although it doesn't quite work as intended if you type quick, it does in fact
make a very useful drunk text simulator. Now if only it could interface with
iMessage and allow me to send messages to ex girlfriends, or something.

~~~
lakwn
Indeed... I typed the project's description, and this is what I got:

AutoJS is a library topic continuenuously authorocomplete termxtarea backsed
one a stillandard dictionary. Dictionary has buteen deviceviced basedd on
researchers and linguistic methods, keeping an eye on millionnimizing the
siteze of the likeibrary. Complete productject is writertin in plain js, with
no externalnal devicependencies, and siteze is reduced to mere 6 kb.

------
tokenizerrr
> helplo i am typeing a messagesage usingng theis topicol but it doesnt seeem
> too work topico getreat

Is what I got when typing

> hello i am typing a message using this tool but it doesnt seem too work too
> great

I'm not a big fan...

------
aaronem
Neat idea, but there doesn't seem to be any way to explicitly accept a
completion candidate (tab, space, return all behave as default instead of
accepting), and trying to type as in a normal textarea results in random
completion candidates being accepted mid-word. Also, C-a (Control-a, i.e.
mark-whole-buffer) gets stomped; the whole textarea is marked for a fraction
of a second, and then the mark disappears.

Not ready for prime time.

------
nathancahill
I'm building a similar tool system-wide for OSX. There are a couple
differences in my implementation:

\- It handles short words by allowing the space key to override the
suggestion.

\- It uses arrow keys, tab, and enter (Sublime completion style) to choose the
right word or phrase.

\- It starts with a basic dictionary, and learns from frequent words and
phrases you type.

\- It draws new words and phrases from open documents and web pages, and
optionally from Google's auto-suggest.

------
aviraldg
It's buggy -- works if you type slowly, but if you type fast, "testing", for
example, it completes the word "term" instead.

------
bananashake
I love it. But in the spirit of QA here is a reproduction.

Try very slowly typing the word, pretty, in the textbox box. If you are like
me it turns into the word, president, on the Chrome browser on Mac.

If I type quickly enough it usually works perfectly.

My guess is that you are using the speed of the typing to decide if I want to
accept an autocomplete.

My proposed solution: I'd use the right arrow character to accept the
autocomplete and advancing to the end of the word, rather than speed change.
The problem with using the space char is that then we'd never be able to type
the word pre.

Great job! I think it's almost perfect and pretty :)

~~~
atmb4u
Thank You! Will definitely look into your suggested solution.

------
ecesena
Based on this audience, I'd have tested it more on "hello world" ;)

I understand there's been some effort in tuning the dictionary for size vs
completeness. Can you elaborate a bit more on this point?

------
gambler
It reminds of JS-based spellcheckers that plagued many web apps in late 90s.
This kind of stuff simply cannot be implemented properly without browser
integration. What if I am using a Latin-base language that is not English?

Besides, auto-complete should be explicitly accepted, not showed into the box
after some unrelated keystrokes. If I type "h", pressing backspace should
delete what I just typed, not "ave".

------
tairar
Typing crazy slow:

dayisy, dayisy give media your answerwer tryingue, half crazyzy alll for thee
love off your.

Typing full speed:

daisy daisy give media your answerwer truee, I'm havelf crazyzy alll forr the
likeove of your.

Very strange how typing slowly wouldn't allow me to type "I'm". Kept auto
correcting to "more", and then deleting itself. (Come to think of it, deletion
is caused by the space, because "more" is still selected)

------
goldenkey
Has this been tested at all? It's replacing all the short words with
autocompleted longer ones due to space being hit. It needs to be less eager.

~~~
joshmlewis
It was probably one of those cases where the author just built it knowing it's
limitations and tested it doing it slowly and not realizing almost everyone
else won't have that same point of view and will try to type really fast.

~~~
goldenkey
Gotcha. Tab would probably be a safer key to use rather than space.

------
phaed
Has this been tested? I can't seem to type a regular sentence without it
injecting random words in the middle of it.

------
lobster_johnson
Seems incredibly buggy when you just type straight without waiting for any
completions. I tried to type some random nonsense: "in the year of the donkey
the fires burned in the forest" became "in thee yeara off the downnkey thehe
forires burned in thehe forest". Safari 7.

------
myang
It seems to choose the word too early and too quickly. For example, if I type:
"in" (without the quotes), it shows "into". You may want to use the tab key as
a hint for word selection rather than selecting it automatically.

------
matthuggins
Not sure if it's working properly on mobile. I pressed the letter 'A' on my
keyboard and no other keys, and the textarea showed "And " with a space after
it. Is that right? It didn't feel right.

------
zekenie
Great! I think I have a couple use cases for this, and I like how small it is.
I notice that it doesn't do too well with the ' character. I think its
probably an escaping issue. I commented on a github issue.

------
mtrimpe
When I typed "It's" it corrected it to "said" and selected it, meaning that
typing "It's " (with space) got me ending up with nothing but a single space.

------
rossij
[this was pointless comment by me that i deleted]

Does not work well for me at all. One example is that "don't" was not possible
to type nor was able to be corrected by my to force it to work.

------
leke
I like it, but I noticed it doesn't work on words when you pan the cursor back
to a previous word or try and insert a new one in the middle of a sentence.

------
bellbind
Why can't I specify a remote dictionary of my own ? AKA: no i18n support,
thank you. Why is the data mixed in with the code in the first place?

------
captn3m0
Just to hijack this thread: I'm looking for a autocomplete library (like
typeahead.js) that works on textareas. Any recommendations?

~~~
ricardobeat
This one could probably be split into the autocomplete UI and the suggestion
engine.

~~~
captn3m0
This is more of a "single" suggestion autocomplete. A proper autocomplete
plugin would offer multiple suggestions and not screw up with the cursor (like
this one does)

------
mike-cardwell
This mangled nearly every single word that I typed.

[edit] Ah, I see. I have to type unnaturally slowly in order for it to work.

------
maxbrunsfeld
CTRL-h doesn't behave the same as backspace on OS-X. This makes it hard to use
for me. Cool idea though.

------
uptown
Seems impossible to press CTRL-A to select-all in order to clear what's been
typed.

~~~
atmb4u
working on it. Thanks a lot for the bug report.

------
gmjosack
Two bugs I noticed:

* Can't select all in the middle of an auto-completed word.

* Can't type words-with-hyphens.

~~~
j79
I'm having issues with selecting all in the middle of a sentence. Until I add
a punctuation mark, it won't allow me to select all (just moves cursor to
end...)

Google Chrome Version 31.0.1650.57 on OS X 10.8.5

------
jdangu
doesn't seem to work on FireFox 25.0.1

ReferenceError: AutoSuggestControl is not defined @
[http://atmb4u.github.io/AutoJS/:78](http://atmb4u.github.io/AutoJS/:78)

------
gagege
I typed "I'm trying to break this thing."

I got,

> trying to break things thingng.

------
MatthewWilkes
503 on the code for me.

