text-editor-view.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. (function() {
  2. var $, TextEditorView, View, _ref,
  3. __hasProp = {}.hasOwnProperty,
  4. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  5. _ref = require('space-pen'), View = _ref.View, $ = _ref.$;
  6. module.exports = TextEditorView = (function(_super) {
  7. __extends(TextEditorView, _super);
  8. function TextEditorView(params) {
  9. var attributes, editor, mini, name, placeholderText, value;
  10. if (params == null) {
  11. params = {};
  12. }
  13. mini = params.mini, placeholderText = params.placeholderText, attributes = params.attributes, editor = params.editor;
  14. if (attributes == null) {
  15. attributes = {};
  16. }
  17. if (mini != null) {
  18. attributes['mini'] = mini;
  19. }
  20. if (placeholderText != null) {
  21. attributes['placeholder-text'] = placeholderText;
  22. }
  23. if (editor != null) {
  24. this.element = atom.views.getView(editor);
  25. } else {
  26. this.element = document.createElement('atom-text-editor');
  27. }
  28. for (name in attributes) {
  29. value = attributes[name];
  30. this.element.setAttribute(name, value);
  31. }
  32. if (this.element.__spacePenView != null) {
  33. this.element.__spacePenView = this;
  34. this.element.__allowViewAccess = true;
  35. }
  36. TextEditorView.__super__.constructor.apply(this, arguments);
  37. this.setModel(this.element.getModel());
  38. }
  39. TextEditorView.prototype.setModel = function(model) {
  40. this.model = model;
  41. };
  42. TextEditorView.prototype.getModel = function() {
  43. return this.model;
  44. };
  45. TextEditorView.prototype.getText = function() {
  46. return this.model.getText();
  47. };
  48. TextEditorView.prototype.setText = function(text) {
  49. return this.model.setText(text);
  50. };
  51. TextEditorView.prototype.hasFocus = function() {
  52. return this.element.hasFocus();
  53. };
  54. return TextEditorView;
  55. })(View);
  56. }).call(this);