Przeglądaj źródła

fix: textarea use `code` parameter to config codemirror

wangweimin 5 lat temu
rodzic
commit
e1a7306745
2 zmienionych plików z 9 dodań i 8 usunięć
  1. 5 4
      pywebio/demos/zh/overview.py
  2. 4 4
      pywebio/html/js/form.js

+ 5 - 4
pywebio/demos/zh/overview.py

@@ -69,15 +69,15 @@ async def feature_overview():
     text = await textarea('Text Area', rows='3', placeholder='Some text')
     put_text('Your input:%s' % text)
 
-    put_markdown("""textarea还支持使用 <a href="https://codemirror.net/" target="_blank">Codemirror</a>实现代码风格的编辑区,只需使用`codemirror`参数传入Codemirror支持的选项:
+    put_markdown("""textarea还支持使用 <a href="https://codemirror.net/" target="_blank">Codemirror</a>实现代码风格的编辑区,只需使用`code`参数传入Codemirror支持的选项:
     ```python
-    code = await textarea('Code', codemirror={
+    code = await textarea('Code', code={
         'mode': "python",  # 代码语言
         'theme': 'darcula',  # 使用darcula主题
     }, value='import something\n# Write your python code')
     ```
     """, lstrip=True)
-    code = await textarea('Code', codemirror={
+    code = await textarea('Code', code={
         'mode': "python",  # 代码语言
         'theme': 'darcula',  # 使用darcula主题
     }, value='import something\n# Write your python code')
@@ -388,4 +388,5 @@ if __name__ == '__main__':
     parser.add_argument('--port', type=int, default=0, help='server bind port')
     args = parser.parse_args()
 
-    start_server(feature_overview, host=args.host, port=args.port, auto_open_webbrowser=True)
+    # from pywebio.platform.flask import start_server
+    start_server(feature_overview, debug=1, host=args.host, port=args.port, allowed_origins=['http://localhost:63342'])

+ 4 - 4
pywebio/html/js/form.js

@@ -600,12 +600,12 @@
         // input_elem.on('blur', this.send_value_listener);
 
         // 将额外的html参数加到input标签上
-        const ignore_keys = make_set(['value', 'type', 'label', 'invalid_feedback', 'valid_feedback', 'help_text', 'rows', 'codemirror']);
+        const ignore_keys = make_set(['value', 'type', 'label', 'invalid_feedback', 'valid_feedback', 'help_text', 'rows', 'code']);
         for (var key in this.spec) {
             if (key in ignore_keys) continue;
             input_elem.attr(key, this.spec[key]);
         }
-        if (spec.codemirror) {
+        if (spec.code) {
             var that = this;
             setTimeout(function () {
                 var config = {
@@ -616,13 +616,13 @@
                     'matchBrackets': true,  //括号匹配
                     'lineWrapping': true,  //自动换行
                 };
-                for (var k in that.spec.codemirror) config[k] = that.spec.codemirror[k];
+                for (var k in that.spec.code) config[k] = that.spec.code[k];
                 that.code_mirror = CodeMirror.fromTextArea(that.element.find('textarea')[0], config);
                 that.code_mirror.setSize(null, 20 * that.spec.rows);
                 CodeMirror.autoLoadMode(that.code_mirror, config.mode);
                 if (config.theme)
                     load_codemirror_theme(config.theme);
-            }, ShowDuration + 100);
+            }, ShowDuration + 20);
         }
     };