Improved Cstyle behaviour
This commit is contained in:
parent
8e7f4f2716
commit
deb5a01693
1 changed files with 49 additions and 11 deletions
|
|
@ -58,14 +58,17 @@ var CstyleBehaviour = function () {
|
|||
selection: [1, 1]
|
||||
}
|
||||
}
|
||||
} else if (text == '}') { // This should do some matching checks
|
||||
} else if (text == '}') {
|
||||
var cursor = editor.getCursorPosition();
|
||||
var line = session.doc.getLine(cursor.row);
|
||||
var rightChar = line.substring(cursor.column, cursor.column + 1);
|
||||
if (rightChar == '}') {
|
||||
return {
|
||||
text: '',
|
||||
selection: [1, 1]
|
||||
var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
|
||||
if (matching !== null) {
|
||||
return {
|
||||
text: '',
|
||||
selection: [1, 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (text == "\n") {
|
||||
|
|
@ -113,14 +116,17 @@ var CstyleBehaviour = function () {
|
|||
selection: [1, 1]
|
||||
}
|
||||
}
|
||||
} else if (text == ')') { // This should do some matching checks
|
||||
} else if (text == ')') {
|
||||
var cursor = editor.getCursorPosition();
|
||||
var line = session.doc.getLine(cursor.row);
|
||||
var rightChar = line.substring(cursor.column, cursor.column + 1);
|
||||
if (rightChar == ')') {
|
||||
return {
|
||||
text: '',
|
||||
selection: [1, 1]
|
||||
var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
|
||||
if (matching !== null) {
|
||||
return {
|
||||
text: '',
|
||||
selection: [1, 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -148,9 +154,41 @@ var CstyleBehaviour = function () {
|
|||
selection: false
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
text: '""',
|
||||
selection: [1,1]
|
||||
var cursor = editor.getCursorPosition();
|
||||
var line = session.doc.getLine(cursor.row);
|
||||
var leftChar = line.substring(cursor.column-1, cursor.column);
|
||||
|
||||
// We're escaped.
|
||||
if (leftChar == '\\') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find what token we're inside.
|
||||
var tokens = session.getTokens(selection.start.row, selection.start.row)[0].tokens;
|
||||
var col = 0, token;
|
||||
for (var x in tokens) {
|
||||
token = tokens[x].type;
|
||||
if ((tokens[x].value.length + col) > selection.start.column) {
|
||||
break;
|
||||
}
|
||||
col += tokens[x].value.length;
|
||||
}
|
||||
|
||||
// Try and be smart about when we auto insert.
|
||||
if (token === "text" || !token || (token !== "comment" && selection.end.column === line.length)) {
|
||||
return {
|
||||
text: '""',
|
||||
selection: [1,1]
|
||||
}
|
||||
} else if (token === "string") {
|
||||
// Ignore input and move right one if we're typing over the closing quote.
|
||||
var rightChar = line.substring(cursor.column, cursor.column + 1);
|
||||
if (rightChar == '"') {
|
||||
return {
|
||||
text: '',
|
||||
selection: [1, 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue