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

Improve: ensure to scroll when Editor.setCaretLine invoked

Yuki Takei 8 лет назад
Родитель
Сommit
ef4744ca1e
1 измененных файлов с 8 добавлено и 1 удалено
  1. 8 1
      resource/js/components/PageEditor/Editor.js

+ 8 - 1
resource/js/components/PageEditor/Editor.js

@@ -94,7 +94,14 @@ export default class Editor extends React.Component {
    */
   setCaretLine(line) {
     const editor = this.getCodeMirror();
-    editor.setCursor({line: line-1});   // leave 'ch' field as null/undefined to indicate the end of line
+
+    // scroll to the bottom for a moment
+    const eol = editor.getDoc().lineCount() - 1;
+    editor.scrollIntoView(eol);
+
+    const linePosition = Math.max(0, line - 1);
+    editor.scrollIntoView(linePosition);
+    editor.setCursor({line: linePosition});   // leave 'ch' field as null/undefined to indicate the end of line
   }
 
   /**