MarkdownListInterceptor.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { BasicInterceptor } from 'crowi-pluginkit';
  2. import * as codemirror from 'codemirror';
  3. import mlu from './MarkdownListUtil';
  4. export default class MarkdownListInterceptor extends BasicInterceptor {
  5. constructor() {
  6. super();
  7. }
  8. /**
  9. * @inheritdoc
  10. */
  11. isInterceptWhen(contextName) {
  12. return (
  13. contextName === 'preHandleEnter'
  14. );
  15. }
  16. /**
  17. * return boolean value whether processable parallel
  18. */
  19. isProcessableParallel() {
  20. return false;
  21. }
  22. /**
  23. * @inheritdoc
  24. */
  25. process(contextName, ...args) {
  26. const context = Object.assign(args[0]); // clone
  27. const editor = context.editor;
  28. // get strings from current position to EOL(end of line) before break the line
  29. const strToEol = mlu.getStrToEol(editor);
  30. if (mlu.indentAndMarkRE.test(strToEol)) {
  31. codemirror.commands.newlineAndIndent(editor);
  32. // replace the line with strToEol (abort auto indent)
  33. editor.getDoc().replaceRange(strToEol, mlu.getBol(editor), mlu.getEol(editor));
  34. // report to manager that handling was done
  35. context.handlers.push(this.className);
  36. }
  37. // resolve
  38. return Promise.resolve(context);
  39. }
  40. }