This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ------- */ | |
// Clean mess from previous session | |
Components.utils.import("resource:///modules/source-editor.jsm"); | |
let nbox = gBrowser.getNotificationBox(); | |
while (nbox.lastChild.id == "foobar-container" || | |
nbox.lastChild.id == "foobar-splitter") { | |
nbox.removeChild(nbox.lastChild); | |
} | |
/* ------- */ | |
// Build container | |
let container = document.createElement("vbox"); | |
container.setAttribute("flex", "0"); // This makes it take only the required height | |
container.id = "foobar-container"; | |
container.setAttribute("pack", "start"); | |
container.setAttribute("style", "max-height:0px;overflow:hidden"); | |
container.height = 0; // This makes its height 0 which is then adjusted later to fit one line | |
let splitter = document.createElement("splitter"); | |
splitter.className = "devtools-horizontal-splitter"; | |
splitter.id = "foobar-splitter"; | |
nbox.appendChild(splitter); | |
nbox.appendChild(container); | |
/* ------- */ | |
// Editor!!! | |
let input = new SourceEditor(); | |
input.init(container, { | |
initialText: "/* input */", | |
}, autofitEditor); | |
input.editorElement.flex = 0; | |
function autofitEditor(e) { | |
let lineHeight = e._view.getLineHeight(); | |
e.previousLineCount = 1; | |
// This call will make the 0 height container to be of appropriate initial height | |
setEditorSize(e, lineHeight); | |
e.addEventListener(SourceEditor.EVENTS.TEXT_CHANGED, function() { | |
let count = e.getLineCount(); | |
if (count != e.previousLineCount) { | |
e.previousLineCount = count; | |
setEditorSize(e, lineHeight * count); | |
} | |
}); | |
} | |
function setEditorSize(e, height) { | |
container.style.minHeight = | |
container.style.maxHeight = | |
container.style.height = | |
e.editorElement.style.minHeight = | |
e.editorElement.style.maxHeight = | |
e.editorElement.style.height = (3 + height) + "px"; // 3 being the margin | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the max-height and height of container are not set 0 initially (as in previous version), then the editor height jumps from around 50px to 17px. 50px is the initial height before the first setEditorSize call is made.
So I set the initial heights to 0, so that the jump is not visible.