Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/mode/behaviour/behaviour_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

require("../../multi_select");
var assert = require("../../test/assertions");
var Range = require("../../range").Range;

Check warning on line 9 in src/mode/behaviour/behaviour_test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'Range' is assigned a value but never used
var Editor = require("../../editor").Editor;
var UndoManager = require("../../undomanager").UndoManager;
var EditSession = require("../../edit_session").EditSession;
Expand All @@ -24,7 +24,7 @@
editor.commands.exec(name, editor, args);
} while(times --> 1);
};
var testRanges = function(str) {

Check warning on line 27 in src/mode/behaviour/behaviour_test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'testRanges' is assigned a value but never used
assert.equal(editor.selection.getAllRanges() + "", str + "");
};

Expand Down Expand Up @@ -96,7 +96,15 @@
assert.equal(editor.getValue(), "{");
exec("insertstring", 1, "\n");
assert.equal(editor.getValue(), "{\n \n}");


//test bracket indentation
editor.setValue("");
exec("insertstring", 1, " ");
exec("insertstring", 1, "[");
assert.equal(editor.getValue(), " []");
exec("insertstring", 1, "\n");
assert.equal(editor.getValue(), " [\n \n ]");

editor.setValue("");
exec("insertstring", 1, "(");
exec("insertstring", 1, '"');
Expand Down
21 changes: 19 additions & 2 deletions src/mode/behaviour/cstyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ CstyleBehaviour = function(options) {
});

this.add("brackets", "insertion", function(state, action, editor, session, text) {
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
if (text == '[') {
initContext(editor);
var selection = editor.getSelectionRange();
Expand All @@ -211,8 +213,6 @@ CstyleBehaviour = function(options) {
}
} else if (text == ']') {
initContext(editor);
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
var rightChar = line.substring(cursor.column, cursor.column + 1);
if (rightChar == ']') {
var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
Expand All @@ -224,6 +224,23 @@ CstyleBehaviour = function(options) {
};
}
}
} else if (text == "\n" || text == "\r\n") {
initContext(editor);
var rightChar = line.substring(cursor.column, cursor.column + 1);
if (rightChar === ']') {
var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column + 1}, ']');
if (!openBracePos)
return null;
var next_indent = this.$getIndent(session.getLine(openBracePos.row));
} else {
return;
}
var indent = next_indent + session.getTabString();

return {
text: '\n' + indent + '\n' + next_indent,
selection: [1, indent.length, 1, indent.length]
};
}
});

Expand Down
Loading