AbstractEditor.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. export default class AbstractEditor extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. }
  7. forceToFocus() {
  8. }
  9. /**
  10. * set caret position of codemirror
  11. * @param {string} number
  12. */
  13. setCaretLine(line) {
  14. }
  15. /**
  16. * scroll
  17. * @param {number} line
  18. */
  19. setScrollTopByLine(line) {
  20. }
  21. /**
  22. * insert text
  23. * @param {string} text
  24. */
  25. insertText(text) {
  26. }
  27. /**
  28. * return strings from BOL(beginning of line) to current position
  29. */
  30. getStrFromBol() {
  31. throw new Error('this method should be impelemented in subclass');
  32. }
  33. /**
  34. * return strings from current position to EOL(end of line)
  35. */
  36. getStrToEol() {
  37. throw new Error('this method should be impelemented in subclass');
  38. }
  39. /**
  40. * replace Beggining Of Line to current position with param 'text'
  41. * @param {string} text
  42. */
  43. replaceBolToCurrentPos(text) {
  44. throw new Error('this method should be impelemented in subclass');
  45. }
  46. /**
  47. * dispatch onSave event
  48. */
  49. dispatchSave() {
  50. if (this.props.onSave != null) {
  51. this.props.onSave();
  52. }
  53. }
  54. }
  55. AbstractEditor.propTypes = {
  56. value: PropTypes.string,
  57. editorOptions: PropTypes.object,
  58. onChange: PropTypes.func,
  59. onScroll: PropTypes.func,
  60. onScrollCursorIntoView: PropTypes.func,
  61. onSave: PropTypes.func,
  62. onPasteFiles: PropTypes.func,
  63. };