fraserxu / ng-textcomplete

An angularjs directive for github-like autocomplete
38 stars 16 forks source link

Make it work with div contenteditable element #2

Closed bettysteger closed 10 years ago

bettysteger commented 10 years ago

Could it be possible to use like this:

                <div contenteditable="true"
                      ng-model="textInput"
                      autocomplete="{{items}}"></div>

and the directive then uses your ng-textcomplete...

it works just fine when using a textarea, but when using it with a div contenteditable the element has no value so I made the following change in your code:

        getTextFromHeadToCaret: function() {
            var text, selectionEnd, range;
            selectionEnd = this.el.selectionEnd;
            if (typeof selectionEnd === 'number') {
                text = this.el.value.substring(0, selectionEnd);
            } else if (document.selection) {
                range = this.el.createTextRange();
                range.moveStart('character', 0);
                range.moveEnd('textedit');
                text = range.text;
            } else {
                text = this.el.textContent;
            }
            return text;
        },

with this little change the dropdown appears also in contenteditable div, but one problem is that selectionEnd is undefined, and when selecting a item from the dropdown, it will not be inserted .. can you help me solve this?

nice angular module btw!

bettysteger commented 10 years ago

FYI just saw this pull request: https://github.com/yuku-t/jquery-textcomplete/pull/38 so when jquery-textcomplete 0.2.0 is finally out, it would be cool if you can update that too :)

bettysteger commented 10 years ago

what do you think of updating it now/soon? there is not much code to change: https://github.com/yuku-t/jquery-textcomplete/pull/38/files

fraserxu commented 10 years ago

Sorry, @lpsBetty I'm currently on the spring festival in China and I do not have access to internet. Sorry for the delay and I'll update the code when I come back.

bettysteger commented 10 years ago

no problem! (:

fraserxu commented 10 years ago

Merged your pull request and update package to v0.4.0, thanks!

bettysteger commented 10 years ago

thanks! unfortunately still this bug occurs: https://github.com/fraserxu/ng-textcomplete/issues/3

maybe I have time to fix this at any time ..