Просмотр исходного кода

Considering shouldCallCheckWhetherEmojiPickerShouldBeShown WIP

Taichi Masuyama 3 лет назад
Родитель
Сommit
58ce54fc11
1 измененных файлов с 19 добавлено и 2 удалено
  1. 19 2
      packages/app/src/components/PageEditor/CodeMirrorEditor.jsx

+ 19 - 2
packages/app/src/components/PageEditor/CodeMirrorEditor.jsx

@@ -8,6 +8,7 @@ import PropTypes from 'prop-types';
 import { Button } from 'reactstrap';
 import * as loadScript from 'simple-load-script';
 import urljoin from 'url-join';
+import { debounce } from 'throttle-debounce';
 
 import InterceptorManager from '~/services/interceptor-manager';
 import loggerFactory from '~/utils/logger';
@@ -583,9 +584,25 @@ class CodeMirrorEditor extends AbstractEditor {
 
   }
 
+  shouldCallCheckWhetherEmojiPickerShouldBeShown(event) { // 引数は要検討
+    const state = {
+      isEmojiPickerMode: true,
+      currentLetter: 'a', // :, Space, Backspace, Enter
+    };
+
+    if (state.currentLetter === 'Space') {
+      state.isEmojiPickerMode = false;
+    }
+    if (state.currentLetter === ':') {
+      state.isEmojiPickerMode = true;
+    }
+
+    return event.key !== 'Backspace';
+  }
+
   keyUpHandler(editor, event) {
-    if (event.key === ':') {
-      this.checkWhetherEmojiPickerShouldBeShown();
+    if (this.shouldCallCheckWhetherEmojiPickerShouldBeShown(event)) {
+      debounce(100, () => this.checkWhetherEmojiPickerShouldBeShown());
     }
   }