javascript - ace 编辑器宽度更改会丢失内容

标签 javascript jquery css ace-editor

我需要能够在用户将代码放入其中后更改我的 ace 编辑器的宽度。但是,当我更改容纳编辑器的 div 的宽度时,文本不会将其自身包装成更薄的宽度,您只是无法再看到它(请参阅 https://jsfiddle.net/0d4whvsq/1/ )

var editor = ace.edit("ace_editor_div");
editor.getSession().setUseWorker(false);

editor.setOptions({
    maxLines: 50,
    minLines: 30,
    tabSize:2,
    wrap:true,
});
//editor.$blockScrolling = Infinity;
editor.setValue("this is meant to be too much text for the width of the editor once the width is made smaller.")
$("#shrink_button").on("click",function(){
    $("#ace_editor_div").css("width","200px");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.11/ace.min.js"></script>
<script
  src="https://code.jquery.com/jquery-3.5.1.min.js"
  integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
  crossorigin="anonymous"></script>
<button id="shrink_button">
shrink</button>
</button>
<div id="ace_editor_div"></div>

从上面的例子可以看出,缩小编辑器时我丢失了很多文本!我看不到任何与宽度相关的基本设置来解决这个问题,我是否缺少一种在调整大小后将所有文本保留在编辑器中的简单方法?我目前认为我可以在调整大小后重新创建整个编辑器,但这显然不理想。

最佳答案

改变宽度后,需要调用editor.resize()

关于javascript - ace 编辑器宽度更改会丢失内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62019168/

相关文章:

javascript - 从子模板更新父模板的动态模板包含

javascript - 将 Cordova 插件添加到 Vue-Cordova?

javascript - Bootstrap 4 轮播淡入淡出动画无法正常工作

html - 如何使整个列表项可点击

javascript - 移动 Google Chart 列注释位置

javascript - 如何配置js美化以保留长字符串多行对齐

jquery点击关闭功能

javascript - 在页面退出时将参数附加到 URL

html - <p> 标签 id 样式不受尊重

javascript - js函数加载的页面无法使用js函数加载另一个页面js html