【问题标题】:Wrong cursor position of Ace Editor inside a dialog对话框内 Ace Editor 的光标位置错误
【发布时间】:2018-01-04 10:34:48
【问题描述】:

根据 Ace 编辑器嵌入指南 Ace Embedding 我将 Ace 添加到我的网站。

您也可以在这里查看 Ace Editor 最简单的工作示例(不是我的)Ace Editor jsfiddle

但我面临以下问题:

我想在对话框中添加编辑器的 div,但在键入时遇到编辑器光标在对话框中位置的问题。

光标总是显示得比它应该在的位置更正确。

有什么办法可以解决的吗?

请记住,我的网站中 Ace 编辑器的光标位置在将其添加到对话框之前效果很好。

这是我的编辑器和对话框的确切代码:

HTML

    <div id="dialog-message" title="Script Editor">
        <div id="editor" style="display:none"></div>
    </div>  

    <!--  Ace Dependencies: -->
    <script src="./ace/ace.js" type="text/javascript" charset="utf-8"></script>
    <script>
        var editor = ace.edit("editor");
        editor.setTheme("ace/theme/monokai");
        editor.getSession().setMode("ace/mode/javascript");
    </script>

CSS

        <style type="text/css" media="screen">
        #editor { 
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
        }           

    </style>

Javascript

                $("#dialog-message").dialog({
                width: 800,
                height:600,
                buttons: {
                    "Download Workitem Code": function() {
                        /*Create the content of file workitem.html*/
                        var currentEditorValue = editor.getValue();

                        /*HTTP request to get the code of sample_workitem.html*/
                        var url = 'http://patrasrv.motivian.com:8080/BPM_PRODUCT/docroot/designer_standalone/bpm_designer/sample_workitem.html';

                        $(function() {
                          $.get(url, function(data) {

                            var htmlCode = data.replace("[[[[[AAAAA]]]]]", editor.getValue());

                            /*Download workitem.html*/
                            var filename = 'workitem.html';
                            var contentType = 'application/octet-stream';
                            var a = document.createElement('a');
                            var blob = new Blob([htmlCode], {
                              'type': contentType
                            });
                            a.href = window.URL.createObjectURL(blob);
                            a.download = filename;
                            a.click();          

                          });
                        });


                    },
                    "Save Script": function() {
                        $(this).dialog("close");
                        cell.set('wi_script_on_page', $("#editor").text());
                        cell.set('wi_script_editor', false);
                        var testing = editor.getValue();
                        cell.set('wi_script_on_page', testing);
                    },
                    "Cancel": function() {
                        $(this).dialog("close");
                    }
                },
                open: function(){
                    $('#editor').show();
                    $('#editor').focus();
                },
                close: function() {
                        //When closing form by pressing 'X'
                        $('#editor').hide();
                        cell.set('wi_script_editor', false);
                }
            });

忽略 3 个对话框按钮的功能。与问题本身无关。

【问题讨论】:

    标签: javascript html css dialog ace-editor


    【解决方案1】:

    看起来您有一些 css 规则,当您将其放入对话框时会更改 ace 的字体系列。 您需要确保设置为 ace 的字体系列是等宽字体。

    【讨论】:

    • 我设置了 editor.setOptions({fontFamily: "monospace"});在编辑器的初始化脚本和对话框的内部功能打开期间,问题仍然存在。我无法找到解决这个真正令人恼火的问题的方法。
    • 您有一个覆盖 ace 设置的样式的 css 规则。使用浏览器开发工具查找规则,或创建一个页面来演示问题,我可以为您找到它
    • 对不起,我不熟悉这个过程。我应该查看我的开发人员工具吗?你能给我发一个截图让我理解或一些指导方针来理解我必须做什么吗?
    • 我忘了告诉你,对于我的项目中造成问题的 css 规则,你绝对是正确的。我更新了我在 Internet 上找到的一个 jsfiddle,它现在包含一个对话框,并且光标就像一个魅力一样工作。 jsfiddle.net/zmdf50q1那么我怎样才能找到我自己的css问题呢?
    • 只需在样式面板中查找字体系列规则,您屏幕截图中的.ui-widget * 规则肯定会干扰ace,因为它正在改变ace中所有节点的样式,但可能还有其他规则太
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    相关资源
    最近更新 更多