2

I'm using Textangular 1.4.6 and Angular 1.4.7. I need to add a drop down to the toolbar, so i wrote this code:

$provide.decorator('taOptions', [
            'taRegisterTool',
            '$delegate',
            function (taRegisterTool, taOptions) {
                // $delegate is the taOptions we are decorating
                // register the tool with textAngular
                taRegisterTool('parameterscombo', {
                    display: '<button class="btn" type="button" data-animation="am-fade" bs-dropdown="content" aria-haspopup="true" aria-expanded="false">Select parameter</button>',
                    content: [
                        {
                            text: 1,
                            click: 'action(item)'
                        },
                        {
                            text: 2,
                            click: 'action(item)'
                        },
                        {
                            text: 3,
                            click: 'action(item)'
                        },
                        {
                            text: 4,
                            click: 'action(item)'
                        }
                    ],
                    action: function (item) {
                        if (item.text) {
                            this.$editor().wrapSelection('insertHtml', item.text + '***');
                        }
                    }
                });
                // add the button to the default toolbar definition
                taOptions.toolbar[1].push('parameterscombo');
                return taOptions;
            }
        ]);

The dropdown is shown and I'm able to choose a value and insert it to the textarea. The problem is that the first time I choose a value, it's inserted in the correct place (where the cursor is), but the second time onward , it always puts the value in the beginning of the text.

Here's a plunkr: http://plnkr.co/edit/UZQk3jQ5xEpMJdNLonBO?p=preview

Tomer
  • 17,787
  • 15
  • 78
  • 137
  • Perhaps you can try to include 'taSelection' after '$delegate' and set the selection manually? – Fraction Nov 10 '15 at 14:05
  • @Fraction when i try to do that i get : {code: 1, codeName: "INDEX_SIZE_ERR", message: "DOMException: INDEX_SIZE_ERR"} – Tomer Nov 10 '15 at 14:31

0 Answers0