Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

add changeAnnotation listener #126

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/ui-ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ angular.module('ui.ace', [])
*/
var onChangeListener;

/**
* Reference to a change annotation listener created by the listener factory.
* @function
* @see listenerFactory.onChangeAnnotation
*/
var onChangeAnnotationListener;

/**
* Reference to a blur listener created by the listener factory.
* @function
Expand Down Expand Up @@ -237,6 +244,22 @@ angular.module('ui.ace', [])
executeUserCallback(callback, e, acee);
};
},
/**
* Creates an annotation listener which propagates the editor session
* to the callback from the user option onChangeAnnotation. It might be
* exchanged during runtime, if this happens the old listener
* will be unbound.
*
* @param callback callback function defined in the user options
* @see onChangeAnnotation
*/
onChangeAnnotation: function (callback) {
return function () {
if (angular.isFunction(callback)) {
callback(session.getAnnotations());
}
};
},
/**
* Creates a blur listener which propagates the editor session
* to the callback from the user option onBlur. It might be
Expand Down Expand Up @@ -294,6 +317,15 @@ angular.module('ui.ace', [])
onChangeListener = listenerFactory.onChange(opts.onChange);
session.on('change', onChangeListener);

// unbind old annotation listener
//session.removeListener('blur', onChangeAnnotationListener);
session.removeListener('changeAnnotation', onChangeAnnotationListener);

// bind new blur listener
onChangeAnnotationListener = listenerFactory.onChangeAnnotation(opts.onChangeAnnotation);
session.on('changeAnnotation', onChangeAnnotationListener);


// unbind old blur listener
//session.removeListener('blur', onBlurListener);
acee.removeListener('blur', onBlurListener);
Expand Down