- don't store state in the cursor layer
- move overwrite setting to the session
This commit is contained in:
parent
707f38ff9d
commit
9e8b49224f
4 changed files with 58 additions and 57 deletions
|
|
@ -177,6 +177,22 @@ var EditSession = function(text, mode) {
|
|||
return this.$useSoftTabs && (position.column % this.$tabSize == 0);
|
||||
};
|
||||
|
||||
this.$overwrite = false;
|
||||
this.setOverwrite = function(overwrite) {
|
||||
if (this.$overwrite == overwrite) return;
|
||||
|
||||
this.$overwrite = overwrite;
|
||||
this._dispatchEvent("changeOverwrite");
|
||||
};
|
||||
|
||||
this.getOverwrite = function() {
|
||||
return this.$overwrite;
|
||||
};
|
||||
|
||||
this.toggleOverwrite = function() {
|
||||
this.setOverwrite(!this.$overwrite);
|
||||
};
|
||||
|
||||
this.getBreakpoints = function() {
|
||||
return this.$breakpoints;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -121,14 +121,15 @@ var Editor =function(renderer, session) {
|
|||
if (this.session) {
|
||||
var oldSession = this.session;
|
||||
this.session.removeEventListener("change", this.$onDocumentChange);
|
||||
this.session.removeEventListener("changeMode", this.$onDocumentModeChange);
|
||||
this.session.removeEventListener("changeTabSize", this.$onDocumentChangeTabSize);
|
||||
this.session.removeEventListener("changeWrapLimit", this.$onDocumentChangeWrapLimit);
|
||||
this.session.removeEventListener("changeWrapMode", this.$onDocumentChangeWrapMode);
|
||||
this.session.removeEventListener("changeMode", this.$onModeChange);
|
||||
this.session.removeEventListener("changeTabSize", this.$onChangeTabSize);
|
||||
this.session.removeEventListener("changeWrapLimit", this.$onChangeWrapLimit);
|
||||
this.session.removeEventListener("changeWrapMode", this.$onChangeWrapMode);
|
||||
this.session.removeEventListener("changeFrontMarker", this.$onChangeFrontMarker);
|
||||
this.session.removeEventListener("changeBackMarker", this.$onChangeBackMarker);
|
||||
this.session.removeEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint);
|
||||
this.session.removeEventListener("changeAnnotation", this.$onDocumentChangeAnnotation);
|
||||
this.session.removeEventListener("changeBreakpoint", this.$onChangeBreakpoint);
|
||||
this.session.removeEventListener("changeAnnotation", this.$onChangeAnnotation);
|
||||
this.session.removeEventListener("changeOverwrite", this.$onCursorChange);
|
||||
|
||||
var selection = this.session.getSelection();
|
||||
selection.removeEventListener("changeCursor", this.$onCursorChange);
|
||||
|
|
@ -143,17 +144,17 @@ var Editor =function(renderer, session) {
|
|||
session.addEventListener("change", this.$onDocumentChange);
|
||||
this.renderer.setSession(session);
|
||||
|
||||
this.$onDocumentModeChange = this.onDocumentModeChange.bind(this);
|
||||
session.addEventListener("changeMode", this.$onDocumentModeChange);
|
||||
this.$onModeChange = this.onModeChange.bind(this);
|
||||
session.addEventListener("changeMode", this.$onModeChange);
|
||||
|
||||
this.$onDocumentChangeTabSize = this.renderer.updateText.bind(this.renderer);
|
||||
session.addEventListener("changeTabSize", this.$onDocumentChangeTabSize);
|
||||
this.$onChangeTabSize = this.renderer.updateText.bind(this.renderer);
|
||||
session.addEventListener("changeTabSize", this.$onChangeTabSize);
|
||||
|
||||
this.$onDocumentChangeWrapLimit = this.onDocumentChangeWrapLimit.bind(this);
|
||||
session.addEventListener("changeWrapLimit", this.$onDocumentChangeWrapLimit);
|
||||
this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this);
|
||||
session.addEventListener("changeWrapLimit", this.$onChangeWrapLimit);
|
||||
|
||||
this.$onDocumentChangeWrapMode = this.onDocumentChangeWrapMode.bind(this);
|
||||
session.addEventListener("changeWrapMode", this.$onDocumentChangeWrapMode);
|
||||
this.$onChangeWrapMode = this.onChangeWrapMode.bind(this);
|
||||
session.addEventListener("changeWrapMode", this.$onChangeWrapMode);
|
||||
|
||||
this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this);
|
||||
this.session.addEventListener("changeFrontMarker", this.$onChangeFrontMarker);
|
||||
|
|
@ -161,21 +162,22 @@ var Editor =function(renderer, session) {
|
|||
this.$onChangeBackMarker = this.onChangeBackMarker.bind(this);
|
||||
this.session.addEventListener("changeBackMarker", this.$onChangeBackMarker);
|
||||
|
||||
this.$onDocumentChangeBreakpoint = this.onDocumentChangeBreakpoint.bind(this);
|
||||
this.session.addEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint);
|
||||
this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this);
|
||||
this.session.addEventListener("changeBreakpoint", this.$onChangeBreakpoint);
|
||||
|
||||
this.$onDocumentChangeAnnotation = this.onDocumentChangeAnnotation.bind(this);
|
||||
this.session.addEventListener("changeAnnotation", this.$onDocumentChangeAnnotation);
|
||||
this.$onChangeAnnotation = this.onChangeAnnotation.bind(this);
|
||||
this.session.addEventListener("changeAnnotation", this.$onChangeAnnotation);
|
||||
|
||||
this.$onCursorChange = this.onCursorChange.bind(this);
|
||||
this.session.addEventListener("changeOverwrite", this.$onCursorChange);
|
||||
|
||||
this.selection = session.getSelection();
|
||||
|
||||
this.$onCursorChange = this.onCursorChange.bind(this);
|
||||
this.selection.addEventListener("changeCursor", this.$onCursorChange);
|
||||
|
||||
this.$onSelectionChange = this.onSelectionChange.bind(this);
|
||||
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
|
||||
|
||||
this.onDocumentModeChange();
|
||||
this.onModeChange();
|
||||
this.bgTokenizer.setDocument(session.getDocument());
|
||||
this.bgTokenizer.start(0);
|
||||
|
||||
|
|
@ -183,8 +185,8 @@ var Editor =function(renderer, session) {
|
|||
this.onSelectionChange();
|
||||
this.onChangeFrontMarker();
|
||||
this.onChangeBackMarker();
|
||||
this.onDocumentChangeBreakpoint();
|
||||
this.onDocumentChangeAnnotation();
|
||||
this.onChangeBreakpoint();
|
||||
this.onChangeAnnotation();
|
||||
this.renderer.scrollToRow(session.getScrollTopRow());
|
||||
this.renderer.updateFull();
|
||||
|
||||
|
|
@ -281,7 +283,7 @@ var Editor =function(renderer, session) {
|
|||
this.renderer.updateLines(range.start.row, lastRow);
|
||||
|
||||
// update cursor because tab characters can influence the cursor position
|
||||
this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite);
|
||||
this.renderer.updateCursor();
|
||||
};
|
||||
|
||||
this.onTokenizerUpdate = function(e) {
|
||||
|
|
@ -290,7 +292,7 @@ var Editor =function(renderer, session) {
|
|||
};
|
||||
|
||||
this.onCursorChange = function(e) {
|
||||
this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite);
|
||||
this.renderer.updateCursor();
|
||||
|
||||
if (!this.$blockScrolling) {
|
||||
this.renderer.scrollCursorIntoView();
|
||||
|
|
@ -347,15 +349,15 @@ var Editor =function(renderer, session) {
|
|||
this.renderer.updateBackMarkers();
|
||||
};
|
||||
|
||||
this.onDocumentChangeBreakpoint = function() {
|
||||
this.onChangeBreakpoint = function() {
|
||||
this.renderer.setBreakpoints(this.session.getBreakpoints());
|
||||
};
|
||||
|
||||
this.onDocumentChangeAnnotation = function() {
|
||||
this.onChangeAnnotation = function() {
|
||||
this.renderer.setAnnotations(this.session.getAnnotations());
|
||||
};
|
||||
|
||||
this.onDocumentModeChange = function() {
|
||||
this.onModeChange = function() {
|
||||
var mode = this.session.getMode();
|
||||
if (this.mode == mode)
|
||||
return;
|
||||
|
|
@ -374,12 +376,11 @@ var Editor =function(renderer, session) {
|
|||
this.renderer.setTokenizer(this.bgTokenizer);
|
||||
};
|
||||
|
||||
this.onDocumentChangeWrapLimit = function() {
|
||||
this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite);
|
||||
this.onChangeWrapLimit = function() {
|
||||
this.renderer.updateFull();
|
||||
};
|
||||
|
||||
this.onDocumentChangeWrapMode = function() {
|
||||
this.onChangeWrapMode = function() {
|
||||
this.renderer.onResize(true);
|
||||
};
|
||||
|
||||
|
|
@ -413,7 +414,8 @@ var Editor =function(renderer, session) {
|
|||
if (!this.selection.isEmpty()) {
|
||||
var cursor = this.session.remove(this.getSelectionRange());
|
||||
this.clearSelection();
|
||||
} else if (this.$overwrite){
|
||||
}
|
||||
else if (this.session.getOverwrite()) {
|
||||
var range = new Range.fromPoints(cursor, cursor);
|
||||
range.end.column += text.length;
|
||||
this.session.remove(range);
|
||||
|
|
@ -481,25 +483,16 @@ var Editor =function(renderer, session) {
|
|||
this.keyBinding.onCommandKey(e, hashId, keyCode);
|
||||
};
|
||||
|
||||
this.$overwrite = false;
|
||||
this.setOverwrite = function(overwrite) {
|
||||
if (this.$overwrite == overwrite) return;
|
||||
|
||||
this.$overwrite = overwrite;
|
||||
|
||||
this.$blockScrolling += 1;
|
||||
this.onCursorChange();
|
||||
this.$blockScrolling -= 1;
|
||||
|
||||
this._dispatchEvent("changeOverwrite", {data: overwrite});
|
||||
this.session.setOverwrite();
|
||||
};
|
||||
|
||||
this.getOverwrite = function() {
|
||||
return this.$overwrite;
|
||||
return this.session.getOverwrite();
|
||||
};
|
||||
|
||||
this.toggleOverwrite = function() {
|
||||
this.setOverwrite(!this.$overwrite);
|
||||
this.session.toggleOverwrite();
|
||||
};
|
||||
|
||||
this.setScrollSpeed = function(speed) {
|
||||
|
|
|
|||
|
|
@ -57,11 +57,6 @@ var Cursor = function(parentEl) {
|
|||
this.session = session;
|
||||
};
|
||||
|
||||
this.setCursor = function(position, overwrite) {
|
||||
this.position = position;
|
||||
this.overwrite = overwrite;
|
||||
};
|
||||
|
||||
this.hideCursor = function() {
|
||||
this.isVisible = false;
|
||||
if (this.cursor.parentNode) {
|
||||
|
|
@ -95,14 +90,15 @@ var Cursor = function(parentEl) {
|
|||
};
|
||||
|
||||
this.getPixelPosition = function(onScreen) {
|
||||
if (!this.config || !this.position) {
|
||||
if (!this.config || !this.session) {
|
||||
return {
|
||||
left : 0,
|
||||
top : 0
|
||||
};
|
||||
}
|
||||
|
||||
var pos = this.session.documentToScreenPosition(this.position);
|
||||
var position = this.session.selection.getCursor();
|
||||
var pos = this.session.documentToScreenPosition(position);
|
||||
var cursorLeft = Math.round(pos.column * this.config.characterWidth);
|
||||
var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
|
||||
this.config.lineHeight;
|
||||
|
|
@ -114,9 +110,6 @@ var Cursor = function(parentEl) {
|
|||
};
|
||||
|
||||
this.update = function(config) {
|
||||
if (!this.position)
|
||||
return;
|
||||
|
||||
this.config = config;
|
||||
|
||||
this.pixelPos = this.getPixelPosition(true);
|
||||
|
|
@ -130,7 +123,7 @@ var Cursor = function(parentEl) {
|
|||
this.element.appendChild(this.cursor);
|
||||
}
|
||||
|
||||
if (this.overwrite) {
|
||||
if (this.session.getOverwrite()) {
|
||||
dom.addCssClass(this.cursor, "ace_overwrite");
|
||||
} else {
|
||||
dom.removeCssClass(this.cursor, "ace_overwrite");
|
||||
|
|
|
|||
|
|
@ -568,8 +568,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
this.$loop.schedule(this.CHANGE_GUTTER);
|
||||
};
|
||||
|
||||
this.updateCursor = function(position, overwrite) {
|
||||
this.$cursorLayer.setCursor(position, overwrite);
|
||||
this.updateCursor = function() {
|
||||
this.$loop.schedule(this.CHANGE_CURSOR);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue