Bug 964504 - Add Editor.setFontSize/getFontSize. r=msucan

This commit is contained in:
Anton Kovalyov 2014-02-10 18:21:42 -08:00
parent 7596d973db
commit d91df90422
2 changed files with 26 additions and 1 deletions

View File

@ -758,6 +758,25 @@ Editor.prototype = {
{ line: end.line + 1, ch: end.ch });
},
/**
* Returns current font size for the editor area, in pixels.
*/
getFontSize: function () {
let cm = editors.get(this);
let el = cm.getWrapperElement();
let win = el.ownerDocument.defaultView;
return parseInt(win.getComputedStyle(el).getPropertyValue("font-size"), 10);
},
/**
* Sets font size for the editor area.
*/
setFontSize: function (size) {
let cm = editors.get(this);
cm.getWrapperElement().style.fontSize = parseInt(size, 10) + "px";
},
/**
* Extends an instance of the Editor object with additional
* functions. Each function will be called with context as

View File

@ -51,6 +51,12 @@ function test() {
ed.removeLineClass(0, "test");
ok(!ed.hasLineClass(0, "test"), "test line class is gone");
// Font size
let size = ed.getFontSize();
is("number", typeof size, "we have the default font size");
ed.setFontSize(ed.getFontSize() + 1);
is(ed.getFontSize(), size + 1, "new font size was set");
teardown(ed, win);
});
}
}