better way for managing options
This commit is contained in:
parent
4a252a0c3b
commit
f74185870f
11 changed files with 324 additions and 345 deletions
|
|
@ -42,6 +42,7 @@ var Range = require("./range").Range;
|
|||
var Document = require("./document").Document;
|
||||
var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer;
|
||||
var SearchHighlight = require("./search_highlight").SearchHighlight;
|
||||
var config = require("./config");
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -175,6 +176,9 @@ var EditSession = function(text, mode) {
|
|||
|
||||
this.selection = new Selection(this);
|
||||
this.setMode(mode);
|
||||
|
||||
config.resetOptions(this);
|
||||
config._emit("session", this);
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -452,50 +456,26 @@ var EditSession = function(text, mode) {
|
|||
}
|
||||
};
|
||||
|
||||
this.$useSoftTabs = true;
|
||||
/**
|
||||
* Pass `true` to enable the use of soft tabs. Soft tabs means you're using spaces instead of the tab character (`'\t'`).
|
||||
* @param {Boolean} useSoftTabs Value indicating whether or not to use soft tabs
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setUseSoftTabs = function(useSoftTabs) {
|
||||
if (this.$useSoftTabs === useSoftTabs) return;
|
||||
|
||||
this.$useSoftTabs = useSoftTabs;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns `true` if soft tabs are being used, `false` otherwise.
|
||||
* @returns {Boolean}
|
||||
**/
|
||||
this.getUseSoftTabs = function() {
|
||||
return this.$useSoftTabs;
|
||||
};
|
||||
|
||||
this.$tabSize = 4;
|
||||
/**
|
||||
* Set the number of spaces that define a soft tab; for example, passing in `4` transforms the soft tabs to be equivalent to four spaces. This function also emits the `changeTabSize` event.
|
||||
* @param {Number} tabSize The new tab size
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setTabSize = function(tabSize) {
|
||||
if (isNaN(tabSize) || this.$tabSize === tabSize) return;
|
||||
|
||||
this.$modified = true;
|
||||
this.$rowLengthCache = [];
|
||||
this.$tabSize = tabSize;
|
||||
this._emit("changeTabSize");
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the current tab size.
|
||||
**/
|
||||
this.getTabSize = function() {
|
||||
return this.$tabSize;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns `true` if the character at the position is a soft tab.
|
||||
|
|
@ -864,31 +844,14 @@ var EditSession = function(text, mode) {
|
|||
return this.doc.getNewLineMode();
|
||||
};
|
||||
|
||||
this.$useWorker = true;
|
||||
|
||||
/**
|
||||
* Identifies if you want to use a worker for the `EditSession`.
|
||||
* @param {Boolean} useWorker Set to `true` to use a worker
|
||||
*
|
||||
**/
|
||||
this.setUseWorker = function(useWorker) {
|
||||
if (this.$useWorker == useWorker)
|
||||
return;
|
||||
|
||||
this.$useWorker = useWorker;
|
||||
|
||||
this.$stopWorker();
|
||||
if (useWorker)
|
||||
this.$startWorker();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns `true` if workers are being used.
|
||||
**/
|
||||
this.getUseWorker = function() {
|
||||
return this.$useWorker;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reloads all the tokens on the current session. This function calls [[BackgroundTokenizer.start `BackgroundTokenizer.start ()`]] to all the rows; it also emits the `'tokenizerUpdate'` event.
|
||||
**/
|
||||
|
|
@ -2403,5 +2366,57 @@ var EditSession = function(text, mode) {
|
|||
require("./edit_session/folding").Folding.call(EditSession.prototype);
|
||||
require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype);
|
||||
|
||||
config.defineOptions(EditSession.prototype, "session", {
|
||||
wrap: {
|
||||
set: function(value) {
|
||||
if (!value || value == "off")
|
||||
value = false;
|
||||
else if (value == "free")
|
||||
value = true;
|
||||
else if (typeof value == "string")
|
||||
value = parseInt(value, 10) || false;
|
||||
|
||||
if (!value) {
|
||||
this.setUseWrapMode(false);
|
||||
} else {
|
||||
var col = typeof value == "number" && value;
|
||||
this.setUseWrapMode(true);
|
||||
this.setWrapLimitRange(value, value);
|
||||
}
|
||||
this.$wrap = value;
|
||||
},
|
||||
get: function() {
|
||||
return this.getUseWrapMode() ? this.getWrapLimitRange().min || "free" : "off";
|
||||
},
|
||||
handlesSet: true
|
||||
},
|
||||
firstLineNumber: {
|
||||
set: function() {this._emit("changeBreakpoint");},
|
||||
initialValue: 1
|
||||
},
|
||||
useWorker: {
|
||||
set: function(useWorker) {
|
||||
this.$useWorker = useWorker;
|
||||
|
||||
this.$stopWorker();
|
||||
if (useWorker)
|
||||
this.$startWorker();
|
||||
},
|
||||
initialValue: true
|
||||
},
|
||||
useSoftTabs: {initialValue: true},
|
||||
tabSize: {
|
||||
set: function(tabSize) {
|
||||
if (isNaN(tabSize) || this.$tabSize === tabSize) return;
|
||||
|
||||
this.$modified = true;
|
||||
this.$rowLengthCache = [];
|
||||
this.$tabSize = tabSize;
|
||||
this._emit("changeTabSize");
|
||||
},
|
||||
initialValue: 4
|
||||
}
|
||||
});
|
||||
|
||||
exports.EditSession = EditSession;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue