Make wrapping behavior optional (but still enabled by default)
This commit is contained in:
parent
741451c041
commit
7e08d7b4ef
2 changed files with 29 additions and 5 deletions
|
|
@ -1025,7 +1025,9 @@ var Editor = function(renderer, session) {
|
||||||
* Editor.setBehavioursEnabled(enabled)
|
* Editor.setBehavioursEnabled(enabled)
|
||||||
* - enabled (Boolean): Enables or disables behaviors
|
* - enabled (Boolean): Enables or disables behaviors
|
||||||
*
|
*
|
||||||
* Specifies whether to use behaviors or not. ["Behaviors" in this case is the auto-pairing of special characters, like quotation marks, parenthesis, or brackets.]{: #BehaviorsDef}
|
* Specifies whether to use behaviors or not.
|
||||||
|
* See [[Editor.setWrapBehavioursEnabled]].
|
||||||
|
* ["Behaviors" in this case is the auto-pairing of special characters, like quotation marks, parenthesis, or brackets.]{: #BehaviorsDef}
|
||||||
**/
|
**/
|
||||||
this.setBehavioursEnabled = function (enabled) {
|
this.setBehavioursEnabled = function (enabled) {
|
||||||
this.$modeBehaviours = enabled;
|
this.$modeBehaviours = enabled;
|
||||||
|
|
@ -1040,6 +1042,28 @@ var Editor = function(renderer, session) {
|
||||||
return this.$modeBehaviours;
|
return this.$modeBehaviours;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.$modeWrapBehaviours = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Editor.setWrapBehavioursEnabled(enabled)
|
||||||
|
* - enabled (Boolean): Enables or disables wrapping behaviors
|
||||||
|
*
|
||||||
|
* Specifies whether to use wrapping behaviors or not, i.e. automatically wrapping the selection with characters such as brackets
|
||||||
|
* when such a character is typed in.
|
||||||
|
**/
|
||||||
|
this.setWrapBehavioursEnabled = function (enabled) {
|
||||||
|
this.$modeWrapBehaviours = enabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Editor.getWrapBehavioursEnabled() -> Boolean
|
||||||
|
*
|
||||||
|
* Returns `true` if the wrapping behaviors are currently enabled.
|
||||||
|
**/
|
||||||
|
this.getWrapBehavioursEnabled = function () {
|
||||||
|
return this.$modeWrapBehaviours;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Editor.setShowFoldWidgets(show)
|
* Editor.setShowFoldWidgets(show)
|
||||||
* - show (Boolean): Specifies whether the fold widgets are shown
|
* - show (Boolean): Specifies whether the fold widgets are shown
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ var CstyleBehaviour = function () {
|
||||||
if (text == '{') {
|
if (text == '{') {
|
||||||
var selection = editor.getSelectionRange();
|
var selection = editor.getSelectionRange();
|
||||||
var selected = session.doc.getTextRange(selection);
|
var selected = session.doc.getTextRange(selection);
|
||||||
if (selected !== "" && selected !== "{") {
|
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
|
||||||
return {
|
return {
|
||||||
text: '{' + selected + '}',
|
text: '{' + selected + '}',
|
||||||
selection: false
|
selection: false
|
||||||
|
|
@ -199,7 +199,7 @@ var CstyleBehaviour = function () {
|
||||||
if (text == '(') {
|
if (text == '(') {
|
||||||
var selection = editor.getSelectionRange();
|
var selection = editor.getSelectionRange();
|
||||||
var selected = session.doc.getTextRange(selection);
|
var selected = session.doc.getTextRange(selection);
|
||||||
if (selected !== "") {
|
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
|
||||||
return {
|
return {
|
||||||
text: '(' + selected + ')',
|
text: '(' + selected + ')',
|
||||||
selection: false
|
selection: false
|
||||||
|
|
@ -244,7 +244,7 @@ var CstyleBehaviour = function () {
|
||||||
if (text == '[') {
|
if (text == '[') {
|
||||||
var selection = editor.getSelectionRange();
|
var selection = editor.getSelectionRange();
|
||||||
var selected = session.doc.getTextRange(selection);
|
var selected = session.doc.getTextRange(selection);
|
||||||
if (selected !== "") {
|
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
|
||||||
return {
|
return {
|
||||||
text: '[' + selected + ']',
|
text: '[' + selected + ']',
|
||||||
selection: false
|
selection: false
|
||||||
|
|
@ -290,7 +290,7 @@ var CstyleBehaviour = function () {
|
||||||
var quote = text;
|
var quote = text;
|
||||||
var selection = editor.getSelectionRange();
|
var selection = editor.getSelectionRange();
|
||||||
var selected = session.doc.getTextRange(selection);
|
var selected = session.doc.getTextRange(selection);
|
||||||
if (selected !== "" && selected !== "'" && selected != '"') {
|
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
|
||||||
return {
|
return {
|
||||||
text: quote + selected + quote,
|
text: quote + selected + quote,
|
||||||
selection: false
|
selection: false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue