Add oriantation to Split and demo option
This commit is contained in:
parent
c38ddf3245
commit
55328f3690
3 changed files with 76 additions and 12 deletions
28
demo/demo.js
28
demo/demo.js
|
|
@ -365,6 +365,29 @@ exports.launch = function(env) {
|
||||||
env.editor.getSession().setUseSoftTabs(checked);
|
env.editor.getSession().setUseSoftTabs(checked);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var secondSplitSession = null;
|
||||||
|
bindDropdown("split", function(value) {
|
||||||
|
var sp = env.split;
|
||||||
|
if (value == "none") {
|
||||||
|
sp.setSplits(1);
|
||||||
|
} else {
|
||||||
|
var newEditor = (sp.getSplits() == 1);
|
||||||
|
if (value == "below") {
|
||||||
|
sp.setOriantation(sp.BELOW);
|
||||||
|
} else {
|
||||||
|
sp.setOriantation(sp.BESIDE);
|
||||||
|
}
|
||||||
|
sp.setSplits(2);
|
||||||
|
|
||||||
|
if (newEditor) {
|
||||||
|
var session = secondSplitSession || sp.getEditor(0).session;
|
||||||
|
var newSession = sp.setSession(session, 1);
|
||||||
|
newSession.name = session.name;
|
||||||
|
secondSplitSession = newSession;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function bindCheckbox(id, callback) {
|
function bindCheckbox(id, callback) {
|
||||||
var el = document.getElementById(id);
|
var el = document.getElementById(id);
|
||||||
var onCheck = function() {
|
var onCheck = function() {
|
||||||
|
|
@ -577,11 +600,6 @@ exports.launch = function(env) {
|
||||||
session.addFold(placeHolder, range);
|
session.addFold(placeHolder, range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
env.split.setSplits(2);
|
|
||||||
sp = env.split;
|
|
||||||
session = sp.setSession(sp.getEditor(0).session, 1);
|
|
||||||
session.name = sp.getEditor(0).session.name;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
11
index.html
11
index.html
|
|
@ -11,6 +11,17 @@
|
||||||
<body>
|
<body>
|
||||||
<img id="logo" src="demo/logo.png">
|
<img id="logo" src="demo/logo.png">
|
||||||
<table id="controls">
|
<table id="controls">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="split">Split</label>
|
||||||
|
</td><td>
|
||||||
|
<select id="split" size="1">
|
||||||
|
<option value="none">None</option>
|
||||||
|
<option value="below">Below</option>
|
||||||
|
<option value="beside">Beside</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="doc">Document</label>
|
<label for="doc">Document</label>
|
||||||
|
|
|
||||||
|
|
@ -47,15 +47,20 @@ var Renderer = require("ace/virtual_renderer").VirtualRenderer;
|
||||||
var EditSession = require("ace/edit_session").EditSession;
|
var EditSession = require("ace/edit_session").EditSession;
|
||||||
|
|
||||||
var Split = function(container, theme, splits) {
|
var Split = function(container, theme, splits) {
|
||||||
|
this.BELOW = 1;
|
||||||
|
this.BESIDE = 0;
|
||||||
|
|
||||||
this.$container = container;
|
this.$container = container;
|
||||||
this.$theme = theme;
|
this.$theme = theme;
|
||||||
this.$splits = 0;
|
this.$splits = 0;
|
||||||
this.$editorCSS = "";
|
this.$editorCSS = "";
|
||||||
this.$editors = [];
|
this.$editors = [];
|
||||||
|
this.$oriantation = this.BESIDE;
|
||||||
|
|
||||||
this.setSplits(splits || 1);
|
this.setSplits(splits || 1);
|
||||||
this.$cEditor = this.$editors[0];
|
this.$cEditor = this.$editors[0];
|
||||||
|
|
||||||
|
|
||||||
this.on("focus", function(editor) {
|
this.on("focus", function(editor) {
|
||||||
this.$cEditor = editor;
|
this.$cEditor = editor;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
@ -106,6 +111,10 @@ var Split = function(container, theme, splits) {
|
||||||
this.resize();
|
this.resize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getSplits = function() {
|
||||||
|
return this.$splits;
|
||||||
|
}
|
||||||
|
|
||||||
this.getEditor = function(idx) {
|
this.getEditor = function(idx) {
|
||||||
return this.$editors[idx];
|
return this.$editors[idx];
|
||||||
}
|
}
|
||||||
|
|
@ -191,18 +200,44 @@ var Split = function(container, theme, splits) {
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getOriantation = function() {
|
||||||
|
return this.$oriantation;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setOriantation = function(oriantation) {
|
||||||
|
if (this.$oriantation == oriantation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.$oriantation = oriantation;
|
||||||
|
this.resize();
|
||||||
|
}
|
||||||
|
|
||||||
this.resize = function() {
|
this.resize = function() {
|
||||||
var width = this.$container.clientWidth;
|
var width = this.$container.clientWidth;
|
||||||
var height = this.$container.clientHeight;
|
var height = this.$container.clientHeight;
|
||||||
var editor;
|
var editor;
|
||||||
|
|
||||||
|
if (this.$oriantation == this.BESIDE) {
|
||||||
var editorWidth = width / this.$splits;
|
var editorWidth = width / this.$splits;
|
||||||
for (var i = 0; i < this.$splits; i++) {
|
for (var i = 0; i < this.$splits; i++) {
|
||||||
editor = this.$editors[i];
|
editor = this.$editors[i];
|
||||||
editor.container.style.width = editorWidth + "px";
|
editor.container.style.width = editorWidth + "px";
|
||||||
|
editor.container.style.top = "0px";
|
||||||
editor.container.style.left = i * editorWidth + "px";
|
editor.container.style.left = i * editorWidth + "px";
|
||||||
editor.container.style.height = height + "px";
|
editor.container.style.height = height + "px";
|
||||||
editor.resize();
|
editor.resize();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
var editorHeight = height / this.$splits;
|
||||||
|
for (var i = 0; i < this.$splits; i++) {
|
||||||
|
editor = this.$editors[i];
|
||||||
|
editor.container.style.width = width + "px";
|
||||||
|
editor.container.style.top = i * editorHeight + "px"
|
||||||
|
editor.container.style.left = "0px";
|
||||||
|
editor.container.style.height = editorHeight + "px";
|
||||||
|
editor.resize();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}).call(Split.prototype);
|
}).call(Split.prototype);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue