AbstractEditor.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. this.forceToFocus = this.forceToFocus.bind(this);
  7. this.setCaretLine = this.setCaretLine.bind(this);
  8. this.setScrollTopByLine = this.setScrollTopByLine.bind(this);
  9. this.getStrFromBol = this.getStrFromBol.bind(this);
  10. this.getStrToEol = this.getStrToEol.bind(this);
  11. this.insertText = this.insertText.bind(this);
  12. this.insertLinebreak = this.insertLinebreak.bind(this);
  13. this.dispatchSave = this.dispatchSave.bind(this);
  14. }
  15. forceToFocus() {
  16. }
  17. /**
  18. * set caret position of codemirror
  19. * @param {string} number
  20. */
  21. setCaretLine(line) {
  22. }
  23. /**
  24. * scroll
  25. * @param {number} line
  26. */
  27. setScrollTopByLine(line) {
  28. }
  29. /**
  30. * return strings from BOL(beginning of line) to current position
  31. */
  32. getStrFromBol() {
  33. throw new Error('this method should be impelemented in subclass');
  34. }
  35. /**
  36. * return strings from current position to EOL(end of line)
  37. */
  38. getStrToEol() {
  39. throw new Error('this method should be impelemented in subclass');
  40. }
  41. /**
  42. * replace Beggining Of Line to current position with param 'text'
  43. * @param {string} text
  44. */
  45. replaceBolToCurrentPos(text) {
  46. throw new Error('this method should be impelemented in subclass');
  47. }
  48. /**
  49. * insert text
  50. * @param {string} text
  51. */
  52. insertText(text) {
  53. }
  54. /**
  55. * insert line break to the current position
  56. */
  57. insertLinebreak() {
  58. this.insertText('\n');
  59. }
  60. /**
  61. * dispatch onSave event
  62. */
  63. dispatchSave() {
  64. if (this.props.onSave != null) {
  65. this.props.onSave();
  66. }
  67. }
  68. }
  69. AbstractEditor.propTypes = {
  70. value: PropTypes.string,
  71. editorOptions: PropTypes.object,
  72. onChange: PropTypes.func,
  73. onScroll: PropTypes.func,
  74. onScrollCursorIntoView: PropTypes.func,
  75. onSave: PropTypes.func,
  76. onPasteFiles: PropTypes.func,
  77. };