add demo/autoresize.html
This commit is contained in:
parent
0479acfea7
commit
78585a9c5d
3 changed files with 67 additions and 3 deletions
48
demo/autoresize.html
Normal file
48
demo/autoresize.html
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||||
|
<title>Editor</title>
|
||||||
|
<style type="text/css" media="screen">
|
||||||
|
|
||||||
|
.ace_editor {
|
||||||
|
position: relative !important;
|
||||||
|
border: 1px solid lightgray;
|
||||||
|
margin: auto;
|
||||||
|
height: 200px;
|
||||||
|
width: 80%;
|
||||||
|
}
|
||||||
|
.scrollmargin {
|
||||||
|
height: 100px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<pre id="editor">autoresizing editor</pre>
|
||||||
|
<div class="scrollmargin"></div>
|
||||||
|
<pre id="editor2">minHeight = 2 lines</pre>
|
||||||
|
|
||||||
|
<script src="../build/src/ace.js"></script>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
// create first editor
|
||||||
|
var editor = ace.edit("editor");
|
||||||
|
editor.setTheme("ace/theme/tomorrow");
|
||||||
|
editor.session.setMode("ace/mode/html");
|
||||||
|
editor.setAutoScrollEditorIntoView();
|
||||||
|
editor.setOption("maxLines", 100);
|
||||||
|
|
||||||
|
var editor2 = ace.edit("editor2");
|
||||||
|
editor2.setTheme("ace/theme/tomorrow_night_blue");
|
||||||
|
editor2.session.setMode("ace/mode/html");
|
||||||
|
editor2.setAutoScrollEditorIntoView();
|
||||||
|
editor2.setOption("maxLines", 30);
|
||||||
|
editor2.setOption("minLines", 2);
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -2259,6 +2259,8 @@ config.defineOptions(Editor.prototype, "editor", {
|
||||||
displayIndentGuides: "renderer",
|
displayIndentGuides: "renderer",
|
||||||
fontSize: "renderer",
|
fontSize: "renderer",
|
||||||
fontFamily: "renderer",
|
fontFamily: "renderer",
|
||||||
|
maxLines: "renderer",
|
||||||
|
minLines: "renderer",
|
||||||
|
|
||||||
scrollSpeed: "$mouseHandler",
|
scrollSpeed: "$mouseHandler",
|
||||||
dragDelay: "$mouseHandler",
|
dragDelay: "$mouseHandler",
|
||||||
|
|
|
||||||
|
|
@ -808,7 +808,10 @@ var VirtualRenderer = function(container, theme) {
|
||||||
this.$autosize = function(height, width) {
|
this.$autosize = function(height, width) {
|
||||||
var height = this.session.getScreenLength() * this.lineHeight;
|
var height = this.session.getScreenLength() * this.lineHeight;
|
||||||
var maxHeight = this.$maxLines * this.lineHeight;
|
var maxHeight = this.$maxLines * this.lineHeight;
|
||||||
var desiredHeight = Math.max(this.lineHeight, Math.min(maxHeight, height));
|
var desiredHeight = Math.max(
|
||||||
|
(this.$minLines||1) * this.lineHeight,
|
||||||
|
Math.min(maxHeight, height)
|
||||||
|
);
|
||||||
var vScroll = height > maxHeight;
|
var vScroll = height > maxHeight;
|
||||||
|
|
||||||
if (desiredHeight != this.desiredHeight ||
|
if (desiredHeight != this.desiredHeight ||
|
||||||
|
|
@ -818,8 +821,9 @@ var VirtualRenderer = function(container, theme) {
|
||||||
this.scrollBarV.setVisible(vScroll);
|
this.scrollBarV.setVisible(vScroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var w = this.container.clientWidth;
|
||||||
this.container.style.height = desiredHeight + "px";
|
this.container.style.height = desiredHeight + "px";
|
||||||
this.$updateCachedSize(true, this.$gutterWidth, this.$size.width, desiredHeight);
|
this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight);
|
||||||
// this.$loop.changes = 0;
|
// this.$loop.changes = 0;
|
||||||
this.desiredHeight = desiredHeight;
|
this.desiredHeight = desiredHeight;
|
||||||
}
|
}
|
||||||
|
|
@ -1557,6 +1561,16 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", {
|
||||||
this.container.style.fontFamily = name;
|
this.container.style.fontFamily = name;
|
||||||
this.updateFontSize();
|
this.updateFontSize();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
maxLines: {
|
||||||
|
set: function(val) {
|
||||||
|
this.updateFull();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
minLines: {
|
||||||
|
set: function(name) {
|
||||||
|
this.updateFull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue