简体   繁体   English

面板中的CodeMirror编辑器

[英]CodeMirror editor within a panel

I am building a small extjs 5.1 app for personal use, designed to save examples of functions / methods used in my extjs apps. 我正在构建一个供个人使用的小型extjs 5.1应用程序,旨在保存extjs应用程序中使用的函数/方法的示例。

The most relevant part, has a grid with a list of functions, and a panel with a textarea that displays the contents of records (scripts). 最相关的部分是带有功能列表的网格和带有文本区域的面板,该面板显示记录(脚本)的内容。

This works. 这可行。

Now I'm trying to replace the textarea field by CodeMirror editor for optimal scripts viewing and have syntax higlighter. 现在,我试图用CodeMirror编辑器替换textarea字段,以查看最佳脚本并使用语法高亮显示。

I downloaded CodeMirror and put it in one the folder of my app with the name CodeMirror. 我下载了CodeMirror,并将其命名为CodeMirror放在我的应用程序文件夹中。

In my app index file was added: 在我的应用程序索引文件中添加了:

<link rel = "stylesheet" href = "CodeMirror / lib / codemirror.css">
<script src = "CodeMirror / lib / codemirror.js"> </ script>

However, I am not able to access thes files codemirror.css and codemirror.js or add the editor to the panel, for example with 但是,我无法访问它们的文件codemirror.css和codemirror.js或将编辑器添加到面板中,例如使用

var editor = CodeMirror.fromTextArea (textarea, {
   lineNumbers: true
});

I would appreciate some guidance on this issue. 我希望能对此问题提供一些指导。

You should never edit the index file. 您永远不要编辑索引文件。 Instead add the files you want to include to the corresponding section in app.json. 而是将要包含的文件添加到app.json的相应部分。

For JavaScript: 对于JavaScript:

/**
 * List of all JavaScript assets in the right execution order.
 *
 * Each item is an object with the following format:
 *
 *      {
 *          // Path to file. If the file is local this must be a relative path from
 *          // this app.json file.
 *          //
 *          "path": "path/to/script.js",   // REQUIRED
 *
 *          // Set to true on one file to indicate that it should become the container
 *          // for the concatenated classes.
 *          //
 *          "bundle": false,    // OPTIONAL
 *
 *          // Set to true to include this file in the concatenated classes.
 *          //
 *          "includeInBundle": false,  // OPTIONAL
 *
 *          // Specify as true if this file is remote and should not be copied into the
 *          // build folder. Defaults to false for a local file which will be copied.
 *          //
 *          "remote": false,    // OPTIONAL
 *
 *          // If not specified, this file will only be loaded once, and cached inside
 *          // localStorage until this value is changed. You can specify:
 *          //
 *          //   - "delta" to enable over-the-air delta update for this file
 *          //   - "full" means full update will be made when this file changes
 *          //
 *          "update": "",        // OPTIONAL
 *
 *          // A value of true indicates that is a development mode only dependency.
 *          // These files will not be copied into the build directory or referenced
 *          // in the generate app.json manifest for the micro loader.
 *          //
 *          "bootstrap": false   // OPTIONAL
 *      }
 *
 */
"js": [
    {
        "path": "${framework.dir}/build/ext-all-rtl-debug.js"
    },
    {
        "path": "app.js",
        "bundle": true
    }
],

and for CSS: 对于CSS:

/**
 * List of all CSS assets in the right inclusion order.
 *
 * Each item is an object with the following format:
 *
 *      {
 *          // Path to file. If the file is local this must be a relative path from
 *          // this app.json file.
 *          //
 *          "path": "path/to/stylesheet.css",   // REQUIRED
 *
 *          // Specify as true if this file is remote and should not be copied into the
 *          // build folder. Defaults to false for a local file which will be copied.
 *          //
 *          "remote": false,    // OPTIONAL
 *
 *          // If not specified, this file will only be loaded once, and cached inside
 *          // localStorage until this value is changed. You can specify:
 *          //
 *          //   - "delta" to enable over-the-air delta update for this file
 *          //   - "full" means full update will be made when this file changes
 *          //
 *          "update": ""      // OPTIONAL
 *      }
 */
"css": [
    {
        "path": "bootstrap.css",
        "bootstrap": true
    }
],

If you put the files you want to include above the 'default files' like app.js you have always access to those namespaces, they are included in your production builds, they are cacheable and you can use them in your update process.. 如果将要包含的文件放在诸如“ app.js”之类的“默认文件”之上,则您始终可以访问这些名称空间,它们包含在生产版本中,它们是可缓存的,您可以在更新过程中使用它们。

I support what Tarabass has advised about including library files. 我支持Tarabass关于包含库文件的建议。 But if you face issue in converting ExtJS textarea component to CodeMirror, then please refer following code: 但是,如果在将ExtJS textarea组件转换为CodeMirror时遇到问题,请参考以下代码:

xtype: 'textarea',
listeners: {
    afterrender:function(textarea){

       var textAreaElement = textarea.getEl( ).query('textarea')[0];
       var editableCodeMirror = CodeMirror.fromTextArea(textAreaElement, {
              mode: "javascript",
              theme: "default",
              lineNumbers: true
        });

        editableCodeMirror.getDoc().setValue("console.log('Hello CodeMirror')");
    } 
}

I have created a fiddle for you; 我为你制造了一个小提琴。 https://fiddle.sencha.com/#fiddle/te1 https://fiddle.sencha.com/#fiddle/te1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM