More work on Split. Update the demo UI on changes

This commit is contained in:
Julian Viereck 2011-05-20 22:51:16 +02:00
commit c38ddf3245
7 changed files with 210 additions and 18 deletions

View file

@ -58,7 +58,7 @@ function FoldLine(foldData, folds) {
this.end = this.range.end;
this.folds.forEach(function(fold) {
fold.foldLine = this;
fold.setFoldLine(this);
}, this);
}

View file

@ -59,6 +59,22 @@ Fold.prototype.toString = function() {
return '"' + this.placeholder + '" ' + this.range.toString();
}
Fold.prototype.setFoldLine = function(foldLine) {
this.foldLine = foldLine;
this.subFolds.forEach(function(fold) {
fold.setFoldLine(foldLine);
});
}
Fold.prototype.clone = function() {
var range = this.range.clone();
var fold = new Fold(range, this.placeholder);
this.subFolds.forEach(function(subFold) {
fold.subFolds.push(subFold.clone());
});
return fold;
}
function Folding() {
/**
* Looks up a fold at a given row/column. Possible values for side:
@ -526,6 +542,19 @@ function Folding() {
foldLine, row, endColumn, startRow, startColumn);
}
};
this.$cloneFoldData = function() {
var foldData = this.$foldData;
var fd = [];
fd = this.$foldData.map(function(foldLine) {
var folds = foldLine.folds.map(function(fold) {
return fold.clone();
});
return new FoldLine(fd, folds);
});
return fd;
};
}
exports.Folding = Folding;

View file

@ -217,6 +217,10 @@ var Editor =function(renderer, session) {
this.renderer.setTheme(theme);
};
this.getTheme = function() {
this.renderer.getTheme();
}
this.setStyle = function(style) {
this.renderer.setStyle(style)
};

View file

@ -39,6 +39,7 @@
define(function(require, exports, module) {
var oop = require("pilot/oop");
var lang = require("pilot/lang");
var EventEmitter = require("pilot/event_emitter").EventEmitter;
var Editor = require("ace/editor").Editor;
@ -50,10 +51,10 @@ var Split = function(container, theme, splits) {
this.$theme = theme;
this.$splits = 0;
this.$editorCSS = "";
this.$cEditor = null;
this.$editors = [];
this.setSplits(splits || 1);
this.$cEditor = this.$editors[0];
this.on("focus", function(editor) {
this.$cEditor = editor;
@ -109,6 +110,18 @@ var Split = function(container, theme, splits) {
return this.$editors[idx];
}
this.getCurrentEditor = function() {
return this.$cEditor;
}
this.focus = function() {
this.$cEditor.focus();
}
this.blur = function() {
this.$cEditor.blur();
}
this.setTheme = function(theme) {
this.$editors.forEach(function(editor) {
editor.setTheme(theme);
@ -121,6 +134,63 @@ var Split = function(container, theme, splits) {
});
}
this.forEach = function(callback, scope) {
this.$ditors.forEach(callback, scope);
}
this.$cloneSession = function(session) {
var s = new EditSession(session.getDocument(), session.getMode());
var undoManager = session.getUndoManager();
if (undoManager) {
var undoManagerProxy = new UndoManagerProxy(undoManager, s);
s.setUndoManager(undoManagerProxy);
}
// Overwrite the default $informUndoManager function such that new delas
// aren't added to the undo manager from the new and the old session.
s.$informUndoManager = lang.deferredCall(function() { s.$deltas = []; });
// Copy over 'settings' from the session.
s.setTabSize(session.getTabSize());
s.setUseSoftTabs(session.getUseSoftTabs());
s.setOverwrite(session.getOverwrite());
s.setBreakpoints(session.getBreakpoints());
s.setUseWrapMode(session.getUseWrapMode());
s.setUseWorker(session.getUseWorker());
s.setWrapLimitRange(session.$wrapLimitRange.min,
session.$wrapLimitRange.max);
s.$foldData = session.$cloneFoldData();
return s;
}
this.setSession = function(session, idx) {
var editor
if (idx == null) {
editor = this.$cEditor;
} else {
editor = this.$editors[idx];
}
// Check if the session is used already by any of the editors in the
// split. If it is, we have to clone the session as two editors using
// the same session can cause terrible side effects (e.g. UndoQueue goes
// wrong). This also gives the user of Split the possibility to treat
// each session on each split editor different.
var isUsed = this.$editors.some(function(editor) {
return editor.session === session;
});
if (isUsed) {
session = this.$cloneSession(session);
}
editor.setSession(session);
// Return the session set on the editor. This might be a cloned one.
return session;
}
this.resize = function() {
var width = this.$container.clientWidth;
var height = this.$container.clientHeight;
@ -137,6 +207,46 @@ var Split = function(container, theme, splits) {
}).call(Split.prototype);
function UndoManagerProxy(undoManager, session) {
this.$u = undoManager;
this.$doc = session;
}
(function() {
this.execute = function(options) {
this.$u.execute(options);
}
this.undo = function() {
var u = this.$u;
var deltas = u.$undoStack.pop();
if (deltas) {
this.$doc.undoChanges(deltas);
u.$redoStack.push(deltas);
}
}
this.redo = function() {
var u = this.$u;
var deltas = u.$redoStack.pop();
if (deltas) {
this.$doc.redoChanges(deltas);
u.$undoStack.push(deltas);
}
}
this.reset = function() {
this.$u.reset();
}
this.hasUndo = function() {
return this.$u.hasUndo();
}
this.hasRedo = function() {
return this.$u.hasRedo();
}
}).call(UndoManagerProxy.prototype);
exports.Split = Split;
});

View file

@ -750,6 +750,7 @@ var VirtualRenderer = function(container, theme) {
this.setTheme = function(theme) {
var _self = this;
this.$themeValue = theme;
if (!theme || typeof theme == "string") {
theme = theme || "ace/theme/textmate";
require([theme], function(theme) {
@ -777,6 +778,10 @@ var VirtualRenderer = function(container, theme) {
}
};
this.getTheme = function() {
return this.$themeValue;
}
// Methods allows to add / remove CSS classnames to the editor element.
// This feature can be used by plug-ins to provide a visual indication of
// a certain mode that editor is in.