AbstractEditor.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * return strings from BOL(beginning of line) to current position
  43. */
  44. getStrFromBolToSelectedUpperPos() {
  45. throw new Error('this method should be impelemented in subclass');
  46. }
  47. /**
  48. * replace Beggining Of Line to current position with param 'text'
  49. * @param {string} text
  50. */
  51. replaceBolToCurrentPos(text) {
  52. throw new Error('this method should be impelemented in subclass');
  53. }
  54. /**
  55. * insert text
  56. * @param {string} text
  57. */
  58. insertText(text) {
  59. }
  60. /**
  61. * insert line break to the current position
  62. */
  63. insertLinebreak() {
  64. this.insertText('\n');
  65. }
  66. /**
  67. * dispatch onSave event
  68. */
  69. dispatchSave() {
  70. if (this.props.onSave != null) {
  71. this.props.onSave();
  72. }
  73. }
  74. /**
  75. * dispatch onPasteFiles event
  76. * @param {object} event
  77. */
  78. dispatchPasteFiles(event) {
  79. if (this.props.onPasteFiles != null) {
  80. this.props.onPasteFiles(event);
  81. }
  82. }
  83. }
  84. AbstractEditor.propTypes = {
  85. value: PropTypes.string,
  86. editorOptions: PropTypes.object,
  87. onChange: PropTypes.func,
  88. onScroll: PropTypes.func,
  89. onScrollCursorIntoView: PropTypes.func,
  90. onSave: PropTypes.func,
  91. onPasteFiles: PropTypes.func,
  92. onDragEnter: PropTypes.func,
  93. };