add readonly mode
This commit is contained in:
parent
188d4b9362
commit
43eafdcc6b
1 changed files with 45 additions and 0 deletions
|
|
@ -271,6 +271,9 @@ ace.Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onCut = function() {
|
this.onCut = function() {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!this.selection.isEmpty()) {
|
if (!this.selection.isEmpty()) {
|
||||||
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
|
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
|
|
@ -278,6 +281,9 @@ ace.Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onTextInput = function(text) {
|
this.onTextInput = function(text) {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
var cursor = this.getCursorPosition();
|
var cursor = this.getCursorPosition();
|
||||||
|
|
||||||
text = text.replace("\t", this.doc.getTabString());
|
text = text.replace("\t", this.doc.getTabString());
|
||||||
|
|
@ -350,7 +356,19 @@ ace.Editor = function(renderer, doc) {
|
||||||
return this.showInvisibles;
|
return this.showInvisibles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.$readOnly = false;
|
||||||
|
this.setReadOnly = function(readOnly) {
|
||||||
|
this.$readOnly = readOnly;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getReadOnly = function() {
|
||||||
|
return this.readOnly;
|
||||||
|
};
|
||||||
|
|
||||||
this.removeRight = function() {
|
this.removeRight = function() {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
if (this.selection.isEmpty()) {
|
if (this.selection.isEmpty()) {
|
||||||
this.selection.selectRight();
|
this.selection.selectRight();
|
||||||
}
|
}
|
||||||
|
|
@ -359,6 +377,9 @@ ace.Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.removeLeft = function() {
|
this.removeLeft = function() {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
if (this.selection.isEmpty()) {
|
if (this.selection.isEmpty()) {
|
||||||
this.selection.selectLeft();
|
this.selection.selectLeft();
|
||||||
}
|
}
|
||||||
|
|
@ -367,6 +388,9 @@ ace.Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.blockIndent = function(indentString) {
|
this.blockIndent = function(indentString) {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
var indentString = indentString || this.doc.getTabString();
|
var indentString = indentString || this.doc.getTabString();
|
||||||
var addedColumns = this.doc.indentRows(this.getSelectionRange(), indentString);
|
var addedColumns = this.doc.indentRows(this.getSelectionRange(), indentString);
|
||||||
|
|
||||||
|
|
@ -374,6 +398,9 @@ ace.Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.blockOutdent = function(indentString) {
|
this.blockOutdent = function(indentString) {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
var indentString = indentString || this.doc.getTabString();
|
var indentString = indentString || this.doc.getTabString();
|
||||||
var addedColumns = this.doc.outdentRows(this.getSelectionRange(), indentString);
|
var addedColumns = this.doc.outdentRows(this.getSelectionRange(), indentString);
|
||||||
|
|
||||||
|
|
@ -381,6 +408,9 @@ ace.Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.toggleCommentLines = function() {
|
this.toggleCommentLines = function() {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
var rows = this.$getSelectedRows();
|
var rows = this.$getSelectedRows();
|
||||||
|
|
||||||
var range = {
|
var range = {
|
||||||
|
|
@ -400,6 +430,9 @@ ace.Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.removeLines = function() {
|
this.removeLines = function() {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
var rows = this.$getSelectedRows();
|
var rows = this.$getSelectedRows();
|
||||||
this.selection.setSelectionAnchor(rows.last+1, 0);
|
this.selection.setSelectionAnchor(rows.last+1, 0);
|
||||||
this.selection.selectTo(rows.first, 0);
|
this.selection.selectTo(rows.first, 0);
|
||||||
|
|
@ -409,18 +442,27 @@ ace.Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.moveLinesDown = function() {
|
this.moveLinesDown = function() {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
this.$moveLines(function(firstRow, lastRow) {
|
this.$moveLines(function(firstRow, lastRow) {
|
||||||
return this.doc.moveLinesDown(firstRow, lastRow);
|
return this.doc.moveLinesDown(firstRow, lastRow);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.moveLinesUp = function() {
|
this.moveLinesUp = function() {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
this.$moveLines(function(firstRow, lastRow) {
|
this.$moveLines(function(firstRow, lastRow) {
|
||||||
return this.doc.moveLinesUp(firstRow, lastRow);
|
return this.doc.moveLinesUp(firstRow, lastRow);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.copyLinesUp = function() {
|
this.copyLinesUp = function() {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
this.$moveLines(function(firstRow, lastRow) {
|
this.$moveLines(function(firstRow, lastRow) {
|
||||||
this.doc.duplicateLines(firstRow, lastRow);
|
this.doc.duplicateLines(firstRow, lastRow);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -428,6 +470,9 @@ ace.Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.copyLinesDown = function() {
|
this.copyLinesDown = function() {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
this.$moveLines(function(firstRow, lastRow) {
|
this.$moveLines(function(firstRow, lastRow) {
|
||||||
return this.doc.duplicateLines(firstRow, lastRow);
|
return this.doc.duplicateLines(firstRow, lastRow);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue