angular-ui / ui-ace

This directive allows you to add ACE editor elements.
http://angular-ui.github.io/ui-ace
MIT License
578 stars 172 forks source link

ng-model deleted when pasting the same content to the editor #176

Open vrockai opened 7 years ago

vrockai commented 7 years ago

I've made a very basic plnkr to make this easy to test: http://plnkr.co/edit/PWh57DPNuks7rA5oI7r4

To reproduce, do:

  1. Select editor contents with ctrl-a and copy it to clipboard with ctrl-c. image

  2. Press ctrl-v to overwrite current selection. This will erase the ng-model contents, but in editor, everything looks all-right: image

Tested on Ubuntu with Firefox 55.0.2 and Chromium 60.0.3112.78

gerzenstl commented 7 years ago

I can confirm same issue. Tested with Angular v1.4.11 on Chrome 60.0.3112.101, OSX El Capitan.

I'm using this workaround to deal with this issue is to use the onChange event handler and check if action == 'insert' and ng-model is empty, I copy the lines to the ng-model like this: on HTML:

<div ui-ace="aceOptions" ng-model="foo"></div>

on AceCtrl controller:

$scope.aceOptions = {
  onChange: function (e) {
    if (($scope.foo.length == 0) && (e[0].action == 'insert')) {
        $scope.foo = e[0].lines[0];
      }
    }
}