Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Dec 8, 2013
1 parent fc2a662 commit d17795c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/gwt/acesupport/acemode/r_code_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@ var RCodeModel = function(doc, tokenizer, statePattern, codeBeginPattern) {
if (endState == "qstring" || endState == "qqstring")
return "";

// TODO: optimize
var tabAsSpaces = Array(tabSize + 1).join(" ");

// This lineOverrides nonsense is necessary because the line has not
// changed in the real document yet. We need to simulate it by replacing
// the real line with the `line` param, and when we finish with this
Expand Down Expand Up @@ -742,7 +745,34 @@ var RCodeModel = function(doc, tokenizer, statePattern, codeBeginPattern) {
buffer += tab;
for (var j = 0; j < spacesToAdd; j++)
buffer += " ";
return leadingIndent + buffer + continuationIndent;
var result = leadingIndent + buffer;

// Sometimes even though verticallyAlignFunctionArgs is used,
// the user chooses to manually "break the rules" and use the
// non-aligned style, like so:
//
// plot(foo,
// bar, baz,
//
// Without the below loop, hitting Enter after "baz," causes
// the cursor to end up aligned with foo. The loop simply
// replaces the indentation with the minimal indentation.
//
// TODO: Perhaps we can skip the above few lines of code if
// there are other lines present
var thisIndent;
for (var i = nextTokenPos.row + 1; i <= lastRow; i++) {
// If a line contains only whitespace, it doesn't count
if (!/[^\s]/.test(this.$getLine(i)))
continue;
// TODO: If a line is a continuation of a multi-line string,
// its indentation doesn't count
thisIndent = this.$getLine(i).replace(/[^\s].*$/, '');
if (thisIndent.length < result.length)
result = thisIndent;
}

return result + continuationIndent;
}
}

Expand Down

0 comments on commit d17795c

Please sign in to comment.