add support for overwrite/insert mode
This commit is contained in:
parent
00a2749553
commit
e8546965ee
5 changed files with 49 additions and 6 deletions
|
|
@ -27,10 +27,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.cursor {
|
.cursor {
|
||||||
width: 2px;
|
border-left: 2px solid black;
|
||||||
background: black;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cursor.overwrite {
|
||||||
|
border-left: 0px;
|
||||||
|
border-bottom: 1px solid black;
|
||||||
|
}
|
||||||
|
|
||||||
.line .invisible {
|
.line .invisible {
|
||||||
color: rgb(191, 191, 191);
|
color: rgb(191, 191, 191);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ ace.Editor = function(renderer, doc) {
|
||||||
|
|
||||||
this.onCursorChange = function() {
|
this.onCursorChange = function() {
|
||||||
this.$highlightBrackets();
|
this.$highlightBrackets();
|
||||||
this.renderer.updateCursor(this.getCursorPosition());
|
this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite);
|
||||||
|
|
||||||
if (!this.$blockScrolling) {
|
if (!this.$blockScrolling) {
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
|
|
@ -295,6 +295,15 @@ ace.Editor = function(renderer, doc) {
|
||||||
if (!this.selection.isEmpty()) {
|
if (!this.selection.isEmpty()) {
|
||||||
var cursor = this.doc.remove(this.getSelectionRange());
|
var cursor = this.doc.remove(this.getSelectionRange());
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
|
} else if (this.$overwrite){
|
||||||
|
var range = {
|
||||||
|
start: cursor,
|
||||||
|
end: {
|
||||||
|
row: cursor.row,
|
||||||
|
column: cursor.column + text.length
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.doc.remove(range);
|
||||||
}
|
}
|
||||||
|
|
||||||
var lineState = this.bgTokenizer.getState(cursor.row-1);
|
var lineState = this.bgTokenizer.getState(cursor.row-1);
|
||||||
|
|
@ -329,6 +338,25 @@ ace.Editor = function(renderer, doc) {
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.$overwrite = false;
|
||||||
|
this.setOverwrite = function(overwrite) {
|
||||||
|
if (this.$overwrite == overwrite) return;
|
||||||
|
|
||||||
|
this.$overwrite = overwrite;
|
||||||
|
|
||||||
|
this.$blockScrolling = true;
|
||||||
|
this.onCursorChange();
|
||||||
|
this.$blockScrolling = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getOverwrite = function() {
|
||||||
|
return this.$overwrite;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.toggleOverwrite = function() {
|
||||||
|
this.setOverwrite(!this.$overwrite);
|
||||||
|
};
|
||||||
|
|
||||||
this.$selectionStyle = "line";
|
this.$selectionStyle = "line";
|
||||||
this.setSelectionStyle = function(style) {
|
this.setSelectionStyle = function(style) {
|
||||||
if (this.$selectionStyle == style) return;
|
if (this.$selectionStyle == style) return;
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ ace.KeyBinding = function(element, editor) {
|
||||||
38 : "Up",
|
38 : "Up",
|
||||||
39 : "Right",
|
39 : "Right",
|
||||||
40 : "Down",
|
40 : "Down",
|
||||||
|
45 : "Insert",
|
||||||
46 : "Delete",
|
46 : "Delete",
|
||||||
91 : "Meta"
|
91 : "Meta"
|
||||||
};
|
};
|
||||||
|
|
@ -79,6 +80,10 @@ ace.KeyBinding = function(element, editor) {
|
||||||
this.editor.find(needle);
|
this.editor.find(needle);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this["Insert"] = function() {
|
||||||
|
this.editor.toggleOverwrite();
|
||||||
|
};
|
||||||
|
|
||||||
this["Control-Alt-Up"] = function() {
|
this["Control-Alt-Up"] = function() {
|
||||||
this.editor.copyLinesUp();
|
this.editor.copyLinesUp();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,8 @@ ace.VirtualRenderer = function(container) {
|
||||||
this.markerLayer.removeMarker(markerId);
|
this.markerLayer.removeMarker(markerId);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.updateCursor = function(position) {
|
this.updateCursor = function(position, overwrite) {
|
||||||
this.cursorLayer.setCursor(this.$documentToScreenPosition(position));
|
this.cursorLayer.setCursor(this.$documentToScreenPosition(position), overwrite);
|
||||||
this.cursorLayer.update(this.layerConfig);
|
this.cursorLayer.update(this.layerConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,16 @@ ace.layer.Cursor = function(parentEl) {
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.setCursor = function(position) {
|
this.setCursor = function(position, overwrite) {
|
||||||
this.position = {
|
this.position = {
|
||||||
row : position.row,
|
row : position.row,
|
||||||
column : position.column
|
column : position.column
|
||||||
};
|
};
|
||||||
|
if (overwrite) {
|
||||||
|
ace.addCssClass(this.cursor, "overwrite");
|
||||||
|
} else {
|
||||||
|
ace.removeCssClass(this.cursor, "overwrite");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.hideCursor = function() {
|
this.hideCursor = function() {
|
||||||
|
|
@ -74,6 +79,7 @@ ace.layer.Cursor = function(parentEl) {
|
||||||
this.cursor.style.left = cursorLeft + "px";
|
this.cursor.style.left = cursorLeft + "px";
|
||||||
this.cursor.style.top = (cursorTop - (config.firstRow * config.lineHeight))
|
this.cursor.style.top = (cursorTop - (config.firstRow * config.lineHeight))
|
||||||
+ "px";
|
+ "px";
|
||||||
|
this.cursor.style.width = config.characterWidth + "px";
|
||||||
this.cursor.style.height = config.lineHeight + "px";
|
this.cursor.style.height = config.lineHeight + "px";
|
||||||
|
|
||||||
if (this.isVisible) {
|
if (this.isVisible) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue