Fix placeholder for CodeMirror directives

This commit is contained in:
BoykoAlex
2016-09-15 13:32:30 -04:00
parent 2efc8086dd
commit 1bb339044d
7 changed files with 60 additions and 10 deletions

View File

@@ -93,9 +93,15 @@ define(function (require) {
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
autoCloseBrackets: true
autoCloseBrackets: true,
});
// CodeMirror would set 'placeholder` value at construction time based on the string value of placeholder attribute in the DOM
// Thus, set the correct placeholder value in case value is angular expression.
if (angular.isString($scope.placeholder)) {
doc.setOption('placeholder', $scope.placeholder);
}
warningRuler = doc.annotateScrollbar('CodeMirror-vertical-ruler-warning');
errorRuler = doc.annotateScrollbar('CodeMirror-vertical-ruler-error');

View File

@@ -149,6 +149,13 @@ define(function(require) {
lineNumbers: true,
lineWrapping: true
});
// CodeMirror would set 'placeholder` value at construction time based on the string value of placeholder attribute in the DOM
// Thus, set the correct placeholder value in case value is angular expression.
if (angular.isString($scope.placeholder)) {
doc.setOption('placeholder', $scope.placeholder);
}
doc.on('change', function () {
if (enableTextToGraphSyncing) {
$scope.definition.text = doc.getValue();

View File

@@ -27,7 +27,8 @@ define(function () {
language: '=codeLanguage',
text: '=codeText',
decodeFunction: '&',
encodeFunction: '&'
encodeFunction: '&',
placeholder: '@'
}
};
}];

View File

@@ -16,7 +16,7 @@
define(function () {
'use strict';
return [function () {
return ['$interpolate', function ($interpolate) {
return {
restrict: 'A',
scope: true,
@@ -25,6 +25,9 @@ define(function () {
if (attrs.contentAssistServiceName) {
scope.contentAssistServiceName = attrs.contentAssistServiceName;
}
if (attrs.placeholder) {
scope.placeholder = $interpolate(attrs.placeholder)(scope);
}
scope.init(element.context);
}
};

View File

@@ -17,6 +17,7 @@ define(function () {
'use strict';
var _ = require('underscore');
var angular = require('angular');
return [ function() {
@@ -36,7 +37,8 @@ define(function () {
scope: {
dsl: '=',
hint: '=',
lint: '='
lint: '=',
placeholder: '@'
},
link: function (scope, element, attrs) {
@@ -62,6 +64,12 @@ define(function () {
doc = CodeMirror.fromTextArea(element.context, options);
// CodeMirror would set 'placeholder` value at construction time based on the string value of placeholder attribute in the DOM
// Thus, set the correct placeholder value in case value is angular expression.
if (angular.isString(scope.placeholder)) {
doc.setOption('placeholder', scope.placeholder);
}
var dslChangedHandler = function () {
scope.$apply(function() {
scope.dsl = doc.getValue();