为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕尼黑5688855 2022-09-02 11:07:41
我需要能够在用户将代码放入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>展开代码段从上面的例子中可以看出,我在缩小编辑器时丢失了很多文本!我看不到任何与宽度相关的基本设置来解决这个问题,我是否缺少一种简单的方法来在调整大小后将所有文本保留在编辑器中?我目前正在想,我可以在调整大小后重新创建整个编辑器,但这显然不理想。
查看完整描述

1 回答

?
Cats萌萌

TA贡献1805条经验 获得超9个赞

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



查看完整回答
反对 回复 2022-09-02
  • 1 回答
  • 0 关注
  • 196 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号