Merge pull request #1304 from ajaxorg/options

Add missing options
This commit is contained in:
Ruben Daniels 2013-03-14 09:32:23 -07:00
commit 9696c1f9b3
6 changed files with 73 additions and 28 deletions

View file

@ -491,10 +491,7 @@ var EditSession = function(text, mode) {
* *
**/ **/
this.setOverwrite = function(overwrite) { this.setOverwrite = function(overwrite) {
if (this.$overwrite == overwrite) return; this.setOption("overwrite", overwrite)
this.$overwrite = overwrite;
this._emit("changeOverwrite");
}; };
/** /**
@ -1573,9 +1570,12 @@ var EditSession = function(text, mode) {
* *
* @private * @private
**/ **/
this.adjustWrapLimit = function(desiredLimit) { this.adjustWrapLimit = function(desiredLimit, $printMargin) {
var wrapLimit = this.$constrainWrapLimit(desiredLimit); var limits = this.$wrapLimitRange
if (wrapLimit != this.$wrapLimit && wrapLimit > 0) { if (limits.max < 0)
limits = {min: $printMargin, max: $printMargin};
var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max);
if (wrapLimit != this.$wrapLimit && wrapLimit > 1) {
this.$wrapLimit = wrapLimit; this.$wrapLimit = wrapLimit;
this.$modified = true; this.$modified = true;
if (this.$useWrapMode) { if (this.$useWrapMode) {
@ -1588,17 +1588,14 @@ var EditSession = function(text, mode) {
return false; return false;
}; };
this.$constrainWrapLimit = function(wrapLimit) { this.$constrainWrapLimit = function(wrapLimit, min, max) {
var min = this.$wrapLimitRange.min;
if (min) if (min)
wrapLimit = Math.max(min, wrapLimit); wrapLimit = Math.max(min, wrapLimit);
var max = this.$wrapLimitRange.max;
if (max) if (max)
wrapLimit = Math.min(max, wrapLimit); wrapLimit = Math.min(max, wrapLimit);
// What would a limit of 0 even mean? return wrapLimit;
return Math.max(1, wrapLimit);
}; };
/** /**
@ -2394,9 +2391,13 @@ config.defineOptions(EditSession.prototype, "session", {
value = false; value = false;
else if (value == "free") else if (value == "free")
value = true; value = true;
else if (value == "printMargin")
value = -1;
else if (typeof value == "string") else if (typeof value == "string")
value = parseInt(value, 10) || false; value = parseInt(value, 10) || false;
if (this.$wrap == value)
return;
if (!value) { if (!value) {
this.setUseWrapMode(false); this.setUseWrapMode(false);
} else { } else {
@ -2437,6 +2438,15 @@ config.defineOptions(EditSession.prototype, "session", {
}, },
initialValue: 4, initialValue: 4,
handlesSet: true handlesSet: true
},
overwrite: {
set: function(val) {this._emit("changeOverwrite");},
initialValue: false
},
newLineMode: {
set: function(val) {this.doc.setNewLineMode(val)},
get: function() {return this.doc.getNewLineMode(newLineMode)},
handlesSet: true
} }
}); });

View file

@ -344,10 +344,7 @@ var Editor = function(renderer, session) {
* *
**/ **/
this.setFontSize = function(size) { this.setFontSize = function(size) {
if (typeof size == "number") this.setOption("fontSize", size);
size = size + "px";
this.container.style.fontSize = size;
this.renderer.updateFontSize();
}; };
this.$highlightBrackets = function() { this.$highlightBrackets = function() {
@ -2219,21 +2216,27 @@ config.defineOptions(Editor.prototype, "editor", {
behavioursEnabled: {initialValue: true}, behavioursEnabled: {initialValue: true},
wrapBehavioursEnabled: {initialValue: true}, wrapBehavioursEnabled: {initialValue: true},
hScrollBarAlwaysVisible: "renderer",
highlightGutterLine: "renderer", highlightGutterLine: "renderer",
animatedScroll: "renderer", animatedScroll: "renderer",
showInvisibles: "renderer", showInvisibles: "renderer",
showPrintMargin: "renderer", showPrintMargin: "renderer",
printMarginColumn: "renderer", printMarginColumn: "renderer",
printMargin: "renderer",
fadeFoldWidgets: "renderer", fadeFoldWidgets: "renderer",
showFoldWidgets: "renderer", showFoldWidgets: "renderer",
showGutter: "renderer", showGutter: "renderer",
displayIndentGuides: "renderer", displayIndentGuides: "renderer",
fontSize: "renderer",
fontFamily: "renderer",
scrollSpeed: "$mouseHandler", scrollSpeed: "$mouseHandler",
dragDelay: "$mouseHandler", dragDelay: "$mouseHandler",
focusTimout: "$mouseHandler", focusTimout: "$mouseHandler",
firstLineNumber: "session", firstLineNumber: "session",
overwrite: "session",
newLineMode: "session",
useWorker: "session", useWorker: "session",
useSoftTabs: "session", useSoftTabs: "session",
tabSize: "session", tabSize: "session",

View file

@ -109,7 +109,7 @@ oop.inherits(Mode, TextMode);
if (tok.type == KW_START || tok.type == KW_END) if (tok.type == KW_START || tok.type == KW_END)
break; break;
} }
if (!tok) if (!tok || tok.type == startToken.type)
return; return;
var col = it.getCurrentTokenColumn(); var col = it.getCurrentTokenColumn();

View file

@ -49,7 +49,7 @@ function FoldHandler(editor) {
} }
}); });
editor.on("guttermousedown", function(e) { editor.on("gutterclick", function(e) {
var gutterRegion = editor.renderer.$gutterLayer.getRegion(e); var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
if (gutterRegion == "foldWidgets") { if (gutterRegion == "foldWidgets") {

View file

@ -137,7 +137,7 @@ var MouseHandler = function(editor) {
}).call(MouseHandler.prototype); }).call(MouseHandler.prototype);
config.defineOptions(MouseHandler.prototype, "mouseHandler", { config.defineOptions(MouseHandler.prototype, "mouseHandler", {
scrollSpeed: {initialValue: 1}, scrollSpeed: {initialValue: 2},
dragDelay: {initialValue: 150}, dragDelay: {initialValue: 150},
focusTimout: {initialValue: 0} focusTimout: {initialValue: 0}
}); });

View file

@ -102,7 +102,6 @@ var VirtualRenderer = function(container, theme) {
// Indicates whether the horizontal scrollbar is visible // Indicates whether the horizontal scrollbar is visible
this.$horizScroll = false; this.$horizScroll = false;
this.$horizScrollAlwaysVisible = false;
this.scrollBar = new ScrollBar(this.container); this.scrollBar = new ScrollBar(this.container);
this.scrollBar.addEventListener("scroll", function(e) { this.scrollBar.addEventListener("scroll", function(e) {
@ -355,7 +354,7 @@ var VirtualRenderer = function(container, theme) {
this.adjustWrapLimit = function() { this.adjustWrapLimit = function() {
var availableWidth = this.$size.scrollerWidth - this.$padding * 2; var availableWidth = this.$size.scrollerWidth - this.$padding * 2;
var limit = Math.floor(availableWidth / this.characterWidth); var limit = Math.floor(availableWidth / this.characterWidth);
return this.session.adjustWrapLimit(limit); return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn);
}; };
/** /**
@ -494,6 +493,9 @@ var VirtualRenderer = function(container, theme) {
var style = this.$printMarginEl.style; var style = this.$printMarginEl.style;
style.left = ((this.characterWidth * this.$printMarginColumn) + this.$padding) + "px"; style.left = ((this.characterWidth * this.$printMarginColumn) + this.$padding) + "px";
style.visibility = this.$showPrintMargin ? "visible" : "hidden"; style.visibility = this.$showPrintMargin ? "visible" : "hidden";
if (this.session && this.session.$wrap == -1)
this.adjustWrapLimit();
}; };
/** /**
@ -615,7 +617,7 @@ var VirtualRenderer = function(container, theme) {
* @returns {Boolean} * @returns {Boolean}
**/ **/
this.getHScrollBarAlwaysVisible = function() { this.getHScrollBarAlwaysVisible = function() {
return this.$horizScrollAlwaysVisible; return this.$hScrollBarAlwaysVisible;
}; };
/** /**
@ -625,11 +627,7 @@ var VirtualRenderer = function(container, theme) {
* *
**/ **/
this.setHScrollBarAlwaysVisible = function(alwaysVisible) { this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
if (this.$horizScrollAlwaysVisible != alwaysVisible) { this.setOption("hScrollBarAlwaysVisible", alwaysVisible);
this.$horizScrollAlwaysVisible = alwaysVisible;
if (!this.$horizScrollAlwaysVisible || !this.$horizScroll)
this.$loop.schedule(this.CHANGE_SCROLL);
}
}; };
this.$updateScrollBar = function() { this.$updateScrollBar = function() {
@ -744,7 +742,7 @@ var VirtualRenderer = function(container, theme) {
var longestLine = this.$getLongestLine(); var longestLine = this.$getLongestLine();
var horizScroll = this.$horizScrollAlwaysVisible || this.$size.scrollerWidth - longestLine < 0; var horizScroll = this.$hScrollBarAlwaysVisible || this.$size.scrollerWidth - longestLine < 0;
var horizScrollChanged = this.$horizScroll !== horizScroll; var horizScrollChanged = this.$horizScroll !== horizScroll;
this.$horizScroll = horizScroll; this.$horizScroll = horizScroll;
if (horizScrollChanged) { if (horizScrollChanged) {
@ -1358,6 +1356,17 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", {
set: function() { this.$updatePrintMargin(); }, set: function() { this.$updatePrintMargin(); },
initialValue: 80 initialValue: 80
}, },
printMargin: {
set: function(val) {
if (typeof val == "number")
this.$printMarginColumn = val;
this.$showPrintMargin = !!val;
this.$updatePrintMargin();
},
get: function() {
return this.$showPrintMargin && this.$printMarginColumn;
}
},
showGutter: { showGutter: {
set: function(show){ set: function(show){
this.$gutter.style.display = show ? "block" : "none"; this.$gutter.style.display = show ? "block" : "none";
@ -1398,6 +1407,29 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", {
}, },
initialValue: false, initialValue: false,
value: true value: true
},
hScrollBarAlwaysVisible: {
set: function(alwaysVisible) {
this.$hScrollBarAlwaysVisible = alwaysVisible;
if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll)
this.$loop.schedule(this.CHANGE_SCROLL);
},
initialValue: false
},
fontSize: {
set: function(size) {
if (typeof size == "number")
size = size + "px";
this.container.style.fontSize = size;
this.updateFontSize();
},
initialValue: 12
},
fontFamily: {
set: function(name) {
this.container.style.fontFamily = name;
this.updateFontSize();
}
} }
}); });