javascript 如何在 ACE 编辑器中更改字体样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21900938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I change the Font Style in ACE editor?
提问by a user
I am using ACE editor on my page,
我在我的页面上使用 ACE 编辑器,
<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'.
默认情况下,它显示一种字体,我想将字体更改为“Tahoma 10pt”。
How do I do that?
我怎么做?
回答by a user
To change font you can either add a css rule for #editor
.
or use
要更改字体,您可以为 .css 添加 css 规则#editor
。或使用
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.
但是 Ace 目前只支持等宽字体,而 tahoma 不是等宽字体,所以光标位置会出错。
回答by Jivan
To my knowledge there is no shortcut to directly change Ace's font family other than editor.setOptions()
.
据我所知,没有直接更改 Ace 字体系列的捷径,除了editor.setOptions()
.
However you can set the font size in pixels directly by calling:
但是,您可以通过调用直接以像素为单位设置字体大小:
editor.setFontSize(10) // will set font-size: 10px