且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ACE编辑器中更改字体样式?

更新时间:2023-02-04 19:07:28

要更改字体,您可以要么为 #editor 添加一个CSS规则。
或使用

  editor.setOptions({
fontFamily: tahoma,
fontSize : 10pt
});

但是Ace目前仅支持等宽字体,而tahoma不是等宽字体,因此光标位置将是错误。


I am using ACE editor on my page,

<script src="ace-builds-master/src-noconflict/ace.js" type="text/javascript" charset="utf-8">
</script>
<script>
    var editor = ace.edit("editor");
    editor.setTheme("ace/theme/cobalt");
    editor.getSession().setMode("ace/mode/geco");
</script>

By default it is showing a font, I want to change my font to 'Tahoma 10pt'.

How do I do that?

To change font you can either add a css rule for #editor. or use

editor.setOptions({
  fontFamily: "tahoma",
  fontSize: "10pt"
});

But Ace only supports monospace fonts for now, and tahoma isn't monospace, so cursor position will be wrong.