AbstractEditor.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(editor) {
  37. throw new Error('this method should be impelemented in subclass');
  38. }
  39. /**
  40. * dispatch onSave event
  41. */
  42. dispatchSave() {
  43. if (this.props.onSave != null) {
  44. this.props.onSave();
  45. }
  46. }
  47. }
  48. AbstractEditor.propTypes = {
  49. value: PropTypes.string,
  50. editorOptions: PropTypes.object,
  51. onChange: PropTypes.func,
  52. onScroll: PropTypes.func,
  53. onScrollCursorIntoView: PropTypes.func,
  54. onSave: PropTypes.func,
  55. onPasteFiles: PropTypes.func,
  56. };