rename document to session

This commit is contained in:
Fabian Jakobs 2011-01-19 09:10:05 +01:00
commit d436d71c20
11 changed files with 147 additions and 139 deletions

View file

@ -51,20 +51,20 @@ var ace = {
var env = require("pilot/environment").create();
var catalog = require("pilot/plugin_manager").catalog;
catalog.startupPlugins({ env: env }).then(function() {
var Document = require("ace/document").Document;
var EditSession = require("ace/edit_session").EditSession;
var JavaScriptMode = require("ace/mode/javascript").Mode;
var UndoManager = require("ace/undomanager").UndoManager;
var Editor = require("ace/editor").Editor;
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
var theme = require("ace/theme/textmate");
var doc = new Document(el.innerHTML);
var doc = new EditSession(el.innerHTML);
el.innerHTML = '';
doc.setMode(new JavaScriptMode());
doc.setUndoManager(new UndoManager());
env.document = doc;
env.editor = new Editor(new Renderer(el, theme));
env.editor.setDocument(doc);
env.editor.setSession(doc);
env.editor.resize();
window.addEventListener("resize", function() {
env.editor.resize();

View file

@ -102,7 +102,7 @@ exports.launch = function(env) {
var modeEl = document.getElementById("mode");
function setMode() {
env.editor.getDocument().setMode(modes[modeEl.value] || modes.text);
env.editor.getSession().setMode(modes[modeEl.value] || modes.text);
}
modeEl.onchange = setMode;
setMode();
@ -120,7 +120,7 @@ exports.launch = function(env) {
var docEl = document.getElementById("doc");
function onDocChange() {
var doc = docs[docEl.value];
env.editor.setDocument(doc);
env.editor.setSession(doc);
var mode = doc.getMode();
if (mode instanceof JavaScriptMode) {
@ -240,7 +240,7 @@ exports.launch = function(env) {
env.editor.onTextInput(reader.result);
modeEl.value = mode;
env.editor.getDocument().setMode(modes[mode]);
env.editor.getSession().setMode(modes[mode]);
};
reader.readAsText(file);
}

View file

@ -77,6 +77,10 @@ var EditSession = function(text, mode) {
doc.on("change", this.onChange.bind(this));
};
this.getDocument = function() {
return this.doc;
};
this.onChange = function(e) {
var delta = e.data;
this.$modified = true;

View file

@ -48,7 +48,7 @@ var BackgroundTokenizer = require("ace/background_tokenizer").BackgroundTokenize
var Range = require("ace/range").Range;
var EventEmitter = require("pilot/event_emitter").EventEmitter;
var Editor =function(renderer, doc) {
var Editor =function(renderer, session) {
var container = renderer.getContainerElement();
this.container = container;
this.renderer = renderer;
@ -78,7 +78,7 @@ var Editor =function(renderer, doc) {
wrap: true
});
this.setDocument(doc || new EditSession(""));
this.setSession(session || new EditSession(""));
this.focus();
};
@ -118,38 +118,38 @@ var Editor =function(renderer, doc) {
return this.keyBinding.getKeyboardHandler();
}
this.setDocument = function(doc) {
if (this.doc == doc) return;
this.setSession = function(session) {
if (this.session == session) return;
if (this.doc) {
this.doc.removeEventListener("change", this.$onDocumentChange);
this.doc.removeEventListener("changeMode", this.$onDocumentModeChange);
this.doc.removeEventListener("changeTabSize", this.$onDocumentChangeTabSize);
this.doc.removeEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint);
if (this.session) {
this.session.removeEventListener("change", this.$onDocumentChange);
this.session.removeEventListener("changeMode", this.$onDocumentModeChange);
this.session.removeEventListener("changeTabSize", this.$onDocumentChangeTabSize);
this.session.removeEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint);
var selection = this.doc.getSelection();
var selection = this.session.getSelection();
selection.removeEventListener("changeCursor", this.$onCursorChange);
selection.removeEventListener("changeSelection", this.$onSelectionChange);
this.doc.setScrollTopRow(this.renderer.getScrollTopRow());
this.session.setScrollTopRow(this.renderer.getScrollTopRow());
}
this.doc = doc;
this.session = session;
this.$onDocumentChange = this.onDocumentChange.bind(this);
doc.addEventListener("change", this.$onDocumentChange);
this.renderer.setDocument(doc);
session.addEventListener("change", this.$onDocumentChange);
this.renderer.setSession(session);
this.$onDocumentModeChange = this.onDocumentModeChange.bind(this);
doc.addEventListener("changeMode", this.$onDocumentModeChange);
session.addEventListener("changeMode", this.$onDocumentModeChange);
this.$onDocumentChangeTabSize = this.renderer.updateText.bind(this.renderer);
doc.addEventListener("changeTabSize", this.$onDocumentChangeTabSize);
session.addEventListener("changeTabSize", this.$onDocumentChangeTabSize);
this.$onDocumentChangeBreakpoint = this.onDocumentChangeBreakpoint.bind(this);
this.doc.addEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint);
this.session.addEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint);
this.selection = doc.getSelection();
this.selection = session.getSelection();
this.$desiredColumn = 0;
this.$onCursorChange = this.onCursorChange.bind(this);
@ -159,18 +159,18 @@ var Editor =function(renderer, doc) {
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
this.onDocumentModeChange();
this.bgTokenizer.setDocument(doc);
this.bgTokenizer.setDocument(session.getDocument());
this.bgTokenizer.start(0);
this.onCursorChange();
this.onSelectionChange();
this.onDocumentChangeBreakpoint();
this.renderer.scrollToRow(doc.getScrollTopRow());
this.renderer.scrollToRow(session.getScrollTopRow());
this.renderer.updateFull();
};
this.getDocument = function() {
return this.doc;
this.getSession = function() {
return this.session;
};
this.getSelection = function() {
@ -201,7 +201,7 @@ var Editor =function(renderer, doc) {
setTimeout(function() {
self.$highlightPending = false;
var pos = self.doc.findMatchingBracket(self.getCursorPosition());
var pos = self.session.findMatchingBracket(self.getCursorPosition());
if (pos) {
var range = new Range(pos.row, pos.column, pos.row, pos.column+1);
self.$bracketHighlight = self.renderer.addMarker(range, "ace_bracket");
@ -280,11 +280,11 @@ var Editor =function(renderer, doc) {
};
this.onDocumentChangeBreakpoint = function() {
this.renderer.setBreakpoints(this.doc.getBreakpoints());
this.renderer.setBreakpoints(this.session.getBreakpoints());
};
this.onDocumentModeChange = function() {
var mode = this.doc.getMode();
var mode = this.session.getMode();
if (this.mode == mode)
return;
@ -308,7 +308,7 @@ var Editor =function(renderer, doc) {
var pageY = event.getDocumentY(e);
var pos = this.renderer.screenToTextCoordinates(pageX, pageY);
pos.row = Math.max(0, Math.min(pos.row, this.doc.getLength()-1));
pos.row = Math.max(0, Math.min(pos.row, this.session.getLength()-1));
if (event.getButton(e) != 0) {
if (this.selection.isEmpty()) {
@ -345,7 +345,7 @@ var Editor =function(renderer, doc) {
return;
var cursor = self.renderer.screenToTextCoordinates(mousePageX, mousePageY);
cursor.row = Math.max(0, Math.min(cursor.row, self.doc.getLength()-1));
cursor.row = Math.max(0, Math.min(cursor.row, self.session.getLength()-1));
if (self.$clickSelection) {
if (self.$clickSelection.contains(cursor.row, cursor.column)) {
@ -394,7 +394,7 @@ var Editor =function(renderer, doc) {
this.getCopyText = function() {
if (!this.selection.isEmpty()) {
return this.doc.getTextRange(this.getSelectionRange());
return this.session.getTextRange(this.getSelectionRange());
}
else {
return "";
@ -406,7 +406,7 @@ var Editor =function(renderer, doc) {
return;
if (!this.selection.isEmpty()) {
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
this.moveCursorToPosition(this.session.remove(this.getSelectionRange()));
this.clearSelection();
}
};
@ -416,28 +416,28 @@ var Editor =function(renderer, doc) {
return;
var cursor = this.getCursorPosition();
text = text.replace("\t", this.doc.getTabString());
text = text.replace("\t", this.session.getTabString());
// remove selected text
if (!this.selection.isEmpty()) {
var cursor = this.doc.remove(this.getSelectionRange());
var cursor = this.session.remove(this.getSelectionRange());
this.clearSelection();
} else if (this.$overwrite){
var range = new Range.fromPoints(cursor, cursor);
range.end.column += text.length;
this.doc.remove(range);
this.session.remove(range);
}
this.clearSelection();
var lineState = this.bgTokenizer.getState(cursor.row);
var shouldOutdent = this.mode.checkOutdent(lineState, this.doc.getLine(cursor.row), text);
var line = this.doc.getLine(cursor.row);
var lineIndent = this.mode.getNextLineIndent(lineState, line.slice(0, cursor.column), this.doc.getTabString());
var end = this.doc.insert(cursor, text);
var shouldOutdent = this.mode.checkOutdent(lineState, this.session.getLine(cursor.row), text);
var line = this.session.getLine(cursor.row);
var lineIndent = this.mode.getNextLineIndent(lineState, line.slice(0, cursor.column), this.session.getTabString());
var end = this.session.insert(cursor, text);
/* TODO: This shortcut is somehow broken
if (!shouldOutdent && line != this.doc.getLine(row) && text != "\n") {
if (!shouldOutdent && line != this.session.getLine(row) && text != "\n") {
this.moveCursorToPosition(end);
this.renderer.scrollCursorIntoView();
return;
@ -447,13 +447,13 @@ var Editor =function(renderer, doc) {
var lineState = this.bgTokenizer.getState(cursor.row);
// multi line insert
if (cursor.row !== end.row) {
var size = this.doc.getTabSize(),
var size = this.session.getTabSize(),
minIndent = Number.MAX_VALUE;
for (var row = cursor.row + 1; row <= end.row; ++row) {
var indent = 0;
line = this.doc.getLine(row);
line = this.session.getLine(row);
for (var i = 0; i < line.length; ++i)
if (line.charAt(i) == '\t')
indent += size;
@ -468,18 +468,18 @@ var Editor =function(renderer, doc) {
for (var row = cursor.row + 1; row <= end.row; ++row) {
var outdent = minIndent;
line = this.doc.getLine(row);
line = this.session.getLine(row);
for (var i = 0; i < line.length && outdent > 0; ++i)
if (line.charAt(i) == '\t')
outdent -= size;
else if (line.charAt(i) == ' ')
outdent -= 1;
this.doc.replace(new Range(row, 0, row, line.length), line.substr(i));
this.session.replace(new Range(row, 0, row, line.length), line.substr(i));
}
end.column += this.doc.indentRows(cursor.row + 1, end.row, lineIndent);
end.column += this.session.indentRows(cursor.row + 1, end.row, lineIndent);
} else {
if (shouldOutdent) {
end.column += this.mode.autoOutdent(lineState, this.doc, cursor.row);
end.column += this.mode.autoOutdent(lineState, this.session, cursor.row);
}
}
@ -595,7 +595,7 @@ var Editor =function(renderer, doc) {
if (this.selection.isEmpty()) {
this.selection.selectRight();
}
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
this.moveCursorToPosition(this.session.remove(this.getSelectionRange()));
this.clearSelection();
};
@ -606,7 +606,7 @@ var Editor =function(renderer, doc) {
if (this.selection.isEmpty())
this.selection.selectLeft();
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
this.moveCursorToPosition(this.session.remove(this.getSelectionRange()));
this.clearSelection();
};
@ -614,21 +614,21 @@ var Editor =function(renderer, doc) {
if (this.$readOnly)
return;
var doc = this.doc,
range = this.getSelectionRange();
var session = this.session;
var range = this.getSelectionRange();
if (range.start.row < range.end.row || range.start.column < range.end.column) {
var rows = this.$getSelectedRows();
var count = doc.indentRows(rows.first, rows.last, "\t");
var count = session.indentRows(rows.first, rows.last, "\t");
this.selection.shiftSelection(count);
} else {
var indentString;
if (this.doc.getUseSoftTabs()) {
var size = doc.getTabSize(),
if (this.session.getUseSoftTabs()) {
var size = session.getTabSize(),
position = this.getCursorPosition(),
column = doc.documentToScreenColumn(position.row, position.column),
column = session.documentToScreenColumn(position.row, position.column),
count = (size - column % size);
indentString = lang.stringRepeat(" ", count);
@ -642,8 +642,8 @@ var Editor =function(renderer, doc) {
if (this.$readOnly)
return;
var selection = this.doc.getSelection();
var range = this.doc.outdentRows(selection.getRange());
var selection = this.session.getSelection();
var range = this.session.outdentRows(selection.getRange());
selection.setSelectionRange(range, selection.isBackwards());
this.$updateDesiredColumn();
@ -655,7 +655,7 @@ var Editor =function(renderer, doc) {
var state = this.bgTokenizer.getState(this.getCursorPosition().row);
var rows = this.$getSelectedRows()
var addedColumns = this.mode.toggleCommentLines(state, this.doc, rows.first, rows.last);
var addedColumns = this.mode.toggleCommentLines(state, this.session, rows.first, rows.last);
this.selection.shiftSelection(addedColumns);
};
@ -667,7 +667,7 @@ var Editor =function(renderer, doc) {
this.selection.setSelectionAnchor(rows.last+1, 0);
this.selection.selectTo(rows.first, 0);
this.doc.remove(this.getSelectionRange());
this.session.remove(this.getSelectionRange());
this.clearSelection();
};
@ -676,7 +676,7 @@ var Editor =function(renderer, doc) {
return;
this.$moveLines(function(firstRow, lastRow) {
return this.doc.moveLinesDown(firstRow, lastRow);
return this.session.moveLinesDown(firstRow, lastRow);
});
};
@ -685,7 +685,7 @@ var Editor =function(renderer, doc) {
return;
this.$moveLines(function(firstRow, lastRow) {
return this.doc.moveLinesUp(firstRow, lastRow);
return this.session.moveLinesUp(firstRow, lastRow);
});
};
@ -694,7 +694,7 @@ var Editor =function(renderer, doc) {
return;
this.$moveLines(function(firstRow, lastRow) {
this.doc.duplicateLines(firstRow, lastRow);
this.session.duplicateLines(firstRow, lastRow);
return 0;
});
};
@ -704,7 +704,7 @@ var Editor =function(renderer, doc) {
return;
this.$moveLines(function(firstRow, lastRow) {
return this.doc.duplicateLines(firstRow, lastRow);
return this.session.duplicateLines(firstRow, lastRow);
});
};
@ -798,7 +798,7 @@ var Editor =function(renderer, doc) {
this.gotoPageDown = function() {
var row = this.getPageDownRow(),
column = Math.min(this.getCursorPosition().column,
this.doc.getLine(row).length);
this.session.getLine(row).length);
this.scrollToRow(row);
this.getSelection().moveCursorTo(row, column);
@ -807,7 +807,7 @@ var Editor =function(renderer, doc) {
this.gotoPageUp = function() {
var row = this.getPageUpRow(),
column = Math.min(this.getCursorPosition().column,
this.doc.getLine(row).length);
this.session.getLine(row).length);
this.scrollToRow(row);
this.getSelection().moveCursorTo(row, column);
@ -874,7 +874,7 @@ var Editor =function(renderer, doc) {
if (this.$desiredColumn) {
var cursor = this.getCursorPosition();
var column = this.doc.screenToDocumentColumn(cursor.row, this.$desiredColumn);
var column = this.session.screenToDocumentColumn(cursor.row, this.$desiredColumn);
this.selection.moveCursorTo(cursor.row, column);
}
};
@ -885,14 +885,14 @@ var Editor =function(renderer, doc) {
if (this.$desiredColumn) {
var cursor = this.getCursorPosition();
var column = this.doc.screenToDocumentColumn(cursor.row, this.$desiredColumn);
var column = this.session.screenToDocumentColumn(cursor.row, this.$desiredColumn);
this.selection.moveCursorTo(cursor.row, column);
}
};
this.$updateDesiredColumn = function() {
var cursor = this.getCursorPosition();
this.$desiredColumn = this.doc.documentToScreenColumn(cursor.row, cursor.column);
this.$desiredColumn = this.session.documentToScreenColumn(cursor.row, cursor.column);
};
this.navigateLeft = function(times) {
@ -957,7 +957,7 @@ var Editor =function(renderer, doc) {
if (options)
this.$search.set(options);
var range = this.$search.find(this.doc);
var range = this.$search.find(this.session);
this.$tryReplace(range, replacement);
if (range !== null)
this.selection.setSelectionRange(range);
@ -969,7 +969,7 @@ var Editor =function(renderer, doc) {
this.$search.set(options);
}
var ranges = this.$search.findAll(this.doc);
var ranges = this.$search.findAll(this.session);
if (!ranges.length)
return;
@ -984,10 +984,10 @@ var Editor =function(renderer, doc) {
},
this.$tryReplace = function(range, replacement) {
var input = this.doc.getTextRange(range);
var input = this.session.getTextRange(range);
var replacement = this.$search.replace(input, replacement);
if (replacement !== null) {
range.end = this.doc.replace(range, replacement);
range.end = this.session.replace(range, replacement);
return range;
} else {
return null;
@ -1024,13 +1024,13 @@ var Editor =function(renderer, doc) {
this.$find = function(backwards) {
if (!this.selection.isEmpty()) {
this.$search.set({needle: this.doc.getTextRange(this.getSelectionRange())});
this.$search.set({needle: this.session.getTextRange(this.getSelectionRange())});
}
if (typeof backwards != "undefined")
this.$search.set({backwards: backwards});
var range = this.$search.find(this.doc);
var range = this.$search.find(this.session);
if (range) {
this.gotoLine(range.end.row+1, range.end.column);
this.$updateDesiredColumn();
@ -1039,11 +1039,11 @@ var Editor =function(renderer, doc) {
};
this.undo = function() {
this.doc.getUndoManager().undo();
this.session.getUndoManager().undo();
};
this.redo = function() {
this.doc.getUndoManager().redo();
this.session.getUndoManager().redo();
};
}).call(Editor.prototype);

View file

@ -52,14 +52,14 @@ var Cursor = function(parentEl) {
(function() {
this.setDocument = function(doc) {
this.doc = doc;
this.setSession = function(session) {
this.session = session;
};
this.setCursor = function(position, overwrite) {
this.position = {
row : position.row,
column : this.doc.documentToScreenColumn(position.row, position.column)
column : this.session.documentToScreenColumn(position.row, position.column)
};
if (overwrite) {
dom.addCssClass(this.cursor, "ace_overwrite");

View file

@ -51,8 +51,8 @@ var Marker = function(parentEl) {
(function() {
this.setDocument = function(doc) {
this.doc = doc;
this.setSession = function(session) {
this.session = session;
};
this.addMarker = function(range, clazz, type) {
@ -105,7 +105,7 @@ var Marker = function(parentEl) {
// selection start
var row = range.start.row;
var lineRange = new Range(row, range.start.column, row, this.doc.getLine(row).length);
var lineRange = new Range(row, range.start.column, row, this.session.getLine(row).length);
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1);
// selection end
@ -116,13 +116,13 @@ var Marker = function(parentEl) {
for (var row = range.start.row + 1; row < range.end.row; row++) {
lineRange.start.row = row;
lineRange.end.row = row;
lineRange.end.column = this.doc.getLine(row).length; // account for endofline characters
lineRange.end.column = this.session.getLine(row).length; // account for endofline characters
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1);
}
};
this.drawMultiLineMarker = function(stringBuilder, range, clazz, layerConfig) {
var range = range.toScreenRange(this.doc);
var range = range.toScreenRange(this.session);
// from selection start to the end of the line
var height = layerConfig.lineHeight;
@ -164,7 +164,7 @@ var Marker = function(parentEl) {
};
this.drawSingleLineMarker = function(stringBuilder, range, clazz, layerConfig, extraLength) {
var range = range.toScreenRange(this.doc);
var range = range.toScreenRange(this.session);
var height = layerConfig.lineHeight;
var width = Math.round((range.end.column + (extraLength || 0) - range.start.column) * layerConfig.characterWidth);

View file

@ -125,8 +125,8 @@ var Text = function(parentEl) {
return size;
};
this.setDocument = function(doc) {
this.doc = doc;
this.setSession = function(session) {
this.session = session;
};
this.showInvisibles = false;
@ -139,7 +139,7 @@ var Text = function(parentEl) {
};
this.$computeTabString = function() {
var tabSize = this.doc.getTabSize();
var tabSize = this.session.getTabSize();
if (this.showInvisibles) {
var halfTab = (tabSize) / 2;
this.$tabString = "<span class='ace_invisible'>"
@ -280,7 +280,7 @@ var Text = function(parentEl) {
};
if (this.showInvisibles) {
if (row !== this.doc.getLength() - 1) {
if (row !== this.session.getLength() - 1) {
stringBuilder.push("<span class='ace_invisible'>" + this.EOL_CHAR + "</span>");
} else {
stringBuilder.push("<span class='ace_invisible'>" + this.EOF_CHAR + "</span>");

View file

@ -49,18 +49,18 @@ var EditSession = require("../edit_session").EditSession,
var Test = {
setUp : function(next) {
this.doc1 = new EditSession(["abc", "def"]);
this.doc2 = new EditSession(["ghi", "jkl"]);
this.session1 = new EditSession(["abc", "def"]);
this.session2 = new EditSession(["ghi", "jkl"]);
this.editor = new Editor(new MockRenderer());
next();
},
"test: change document" : function() {
this.editor.setDocument(this.doc1);
assert.equal(this.editor.getDocument(), this.doc1);
this.editor.setSession(this.session1);
assert.equal(this.editor.getSession(), this.session1);
this.editor.setDocument(this.doc2);
assert.equal(this.editor.getDocument(), this.doc2);
this.editor.setSession(this.session2);
assert.equal(this.editor.getSession(), this.session2);
},
"test: only changes to the new document should have effect" : function() {
@ -69,24 +69,24 @@ var Test = {
called = true;
};
this.editor.setDocument(this.doc1);
this.editor.setDocument(this.doc2);
this.editor.setSession(this.session1);
this.editor.setSession(this.session2);
this.doc1.duplicateLines(0, 0);
this.session1.duplicateLines(0, 0);
assert.notOk(called);
this.doc2.duplicateLines(0, 0);
this.session2.duplicateLines(0, 0);
assert.ok(called);
},
"test: should use cursor of new document" : function() {
this.doc1.getSelection().moveCursorTo(0, 1);
this.doc2.getSelection().moveCursorTo(1, 0);
this.session1.getSelection().moveCursorTo(0, 1);
this.session2.getSelection().moveCursorTo(1, 0);
this.editor.setDocument(this.doc1);
this.editor.setSession(this.session1);
assert.position(this.editor.getCursorPosition(), 0, 1);
this.editor.setDocument(this.doc2);
this.editor.setSession(this.session2);
assert.position(this.editor.getCursorPosition(), 1, 0);
},
@ -95,28 +95,28 @@ var Test = {
called = true;
};
this.editor.setDocument(this.doc1);
this.editor.setDocument(this.doc2);
this.editor.setSession(this.session1);
this.editor.setSession(this.session2);
assert.position(this.editor.getCursorPosition(), 0, 0);
var called = false;
this.doc1.getSelection().moveCursorTo(0, 1);
this.session1.getSelection().moveCursorTo(0, 1);
assert.position(this.editor.getCursorPosition(), 0, 0);
assert.notOk(called);
this.doc2.getSelection().moveCursorTo(1, 1);
this.session2.getSelection().moveCursorTo(1, 1);
assert.position(this.editor.getCursorPosition(), 1, 1);
assert.ok(called);
},
"test: should use selection of new document" : function() {
this.doc1.getSelection().selectTo(0, 1);
this.doc2.getSelection().selectTo(1, 0);
this.session1.getSelection().selectTo(0, 1);
this.session2.getSelection().selectTo(1, 0);
this.editor.setDocument(this.doc1);
this.editor.setSession(this.session1);
assert.position(this.editor.getSelection().getSelectionLead(), 0, 1);
this.editor.setDocument(this.doc2);
this.editor.setSession(this.session2);
assert.position(this.editor.getSelection().getSelectionLead(), 1, 0);
},
@ -125,16 +125,16 @@ var Test = {
called = true;
};
this.editor.setDocument(this.doc1);
this.editor.setDocument(this.doc2);
this.editor.setSession(this.session1);
this.editor.setSession(this.session2);
assert.position(this.editor.getSelection().getSelectionLead(), 0, 0);
var called = false;
this.doc1.getSelection().selectTo(0, 1);
this.session1.getSelection().selectTo(0, 1);
assert.position(this.editor.getSelection().getSelectionLead(), 0, 0);
assert.notOk(called);
this.doc2.getSelection().selectTo(1, 1);
this.session2.getSelection().selectTo(1, 1);
assert.position(this.editor.getSelection().getSelectionLead(), 1, 1);
assert.ok(called);
},
@ -143,14 +143,14 @@ var Test = {
this.editor.onDocumentModeChange = function() {
called = true;
};
this.editor.setDocument(this.doc1);
this.editor.setDocument(this.doc2);
this.editor.setSession(this.session1);
this.editor.setSession(this.session2);
var called = false;
this.doc1.setMode(new Text());
this.session1.setMode(new Text());
assert.notOk(called);
this.doc2.setMode(new JavaScriptMode());
this.session2.setMode(new JavaScriptMode());
assert.ok(called);
}
};

View file

@ -69,8 +69,12 @@ MockRenderer.prototype.getMouseEventTarget = function() {
return this.container;
};
MockRenderer.prototype.setDocument = function(doc) {
this.doc = doc;
MockRenderer.prototype.setSession = function(session) {
this.session = session;
};
MockRenderer.prototype.getSession = function(session) {
return this.session;
};
MockRenderer.prototype.setTokenizer = function() {
@ -91,7 +95,7 @@ MockRenderer.prototype.scrollCursorIntoView = function() {
};
MockRenderer.prototype.scrollToRow = function(row) {
var row = Math.min(this.doc.getLength() - this.visibleRowCount, Math.max(0,
var row = Math.min(this.session.getLength() - this.visibleRowCount, Math.max(0,
row));
this.layerConfig.firstVisibleRow = row;
this.layerConfig.lastVisibleRow = row + this.visibleRowCount;

View file

@ -38,7 +38,7 @@
define(function(require, exports, module) {
require("./mockdom");
var Document = require("../document").Document,
var EditSession = require("ace/edit_session").EditSession,
VirtualRenderer = require("../virtual_renderer").VirtualRenderer,
assert = require("./assertions");
@ -54,7 +54,7 @@ var Test = {
document.body.appendChild(el);
var renderer = new VirtualRenderer(el);
renderer.setDocument(new Document("1234"));
renderer.setSession(new EditSession("1234"));
renderer.characterWidth = 10;
renderer.lineHeight = 15;

View file

@ -133,11 +133,11 @@ var VirtualRenderer = function(container, theme) {
oop.implement(this, EventEmitter);
this.setDocument = function(doc) {
this.doc = doc;
this.$cursorLayer.setDocument(doc);
this.$markerLayer.setDocument(doc);
this.$textLayer.setDocument(doc);
this.setSession = function(session) {
this.session = session;
this.$cursorLayer.setSession(session);
this.$markerLayer.setSession(session);
this.$textLayer.setSession(session);
this.$loop.schedule(this.CHANGE_FULL);
};
@ -193,7 +193,7 @@ var VirtualRenderer = function(container, theme) {
this.scroller.style.height = height + "px";
this.scrollBar.setHeight(height);
if (this.doc) {
if (this.session) {
this.scrollToY(this.getScrollTop());
changes = changes | this.CHANGE_FULL;
}
@ -322,12 +322,12 @@ var VirtualRenderer = function(container, theme) {
};
this.$updateScrollBar = function() {
this.scrollBar.setInnerHeight(this.doc.getLength() * this.lineHeight);
this.scrollBar.setInnerHeight(this.session.getLength() * this.lineHeight);
this.scrollBar.setScrollTop(this.scrollTop);
};
this.$renderChanges = function(changes) {
if (!changes || !this.doc || !this.$tokenizer)
if (!changes || !this.session || !this.$tokenizer)
return;
// text, scrolling and resize changes can cause the view port size to change
@ -395,7 +395,7 @@ var VirtualRenderer = function(container, theme) {
var lineCount = Math.ceil(minHeight / this.lineHeight);
var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
var lastRow = Math.max(0, Math.min(this.doc.getLength(), firstRow + lineCount) - 1);
var lastRow = Math.max(0, Math.min(this.session.getLength(), firstRow + lineCount) - 1);
var layerConfig = this.layerConfig = {
width : longestLine,
@ -441,7 +441,7 @@ var VirtualRenderer = function(container, theme) {
};
this.$getLongestLine = function() {
var charCount = this.doc.getScreenWidth();
var charCount = this.session.getScreenWidth();
if (this.$textLayer.showInvisibles)
charCount += 1;
@ -530,7 +530,7 @@ var VirtualRenderer = function(container, theme) {
};
this.scrollToY = function(scrollTop) {
var maxHeight = this.doc.getLength() * this.lineHeight - this.$size.scrollerHeight;
var maxHeight = this.session.getLength() * this.lineHeight - this.$size.scrollerHeight;
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));
if (this.scrollTop !== scrollTop) {
@ -561,14 +561,14 @@ var VirtualRenderer = function(container, theme) {
return {
row : row,
column : this.doc.screenToDocumentColumn(Math.max(0, Math.min(row, this.doc.getLength()-1)), col)
column : this.session.screenToDocumentColumn(Math.max(0, Math.min(row, this.session.getLength()-1)), col)
};
};
this.textToScreenCoordinates = function(row, column) {
var canvasPos = this.scroller.getBoundingClientRect();
var x = this.$padding + Math.round(this.doc.documentToScreenColumn(row, column) * this.characterWidth);
var x = this.$padding + Math.round(this.session.documentToScreenColumn(row, column) * this.characterWidth);
var y = row * this.lineHeight;
return {