summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorSteve Jahns2013-09-06 15:38:32 (EDT)
committer Gabriel Luong2013-09-08 12:57:41 (EDT)
commitc52db4522ea43d6e7154ab3604a58031a9a4efe1 (patch)
tree6ec7e9df7391d916672d8e2318eae3576e703c91
parent0936e39448386378a52dd2bf73c612e5eac7d3b9 (diff)
downloadorg.eclipse.orion.client-c52db4522ea43d6e7154ab3604a58031a9a4efe1.zip
org.eclipse.orion.client-c52db4522ea43d6e7154ab3604a58031a9a4efe1.tar.gz
org.eclipse.orion.client-c52db4522ea43d6e7154ab3604a58031a9a4efe1.tar.bz2
[Bug 415727] [Editor] Improve smart indentations (ignore + remove extra whitespace) --Signed-off-by: Steve Jahns <s.t.jahns@gmail.com>v20130908-1657
-rw-r--r--bundles/org.eclipse.orion.client.editor/web/orion/editor/actions.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/actions.js b/bundles/org.eclipse.orion.client.editor/web/orion/editor/actions.js
index 1b2ff57..a328a74 100644
--- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/actions.js
+++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/actions.js
@@ -631,12 +631,18 @@ define("orion/editor/actions", [ //$NON-NLS-0$
var lineTextAfterCaret = lineText.substring(lineOffset);
var text;
// If the character before the caret is an opening brace, smart indent the next line.
- if (this.smartIndentation && lineText.charCodeAt(lineOffset - 1) === 123) {
- text = lineText.charCodeAt(lineOffset) === 125 ?
+ var prevCharIdx = lineTextBeforeCaret.trimRight().length - 1;
+ if (this.smartIndentation && lineText.charCodeAt(prevCharIdx) === 123) {
+ // Remove any extra whitespace
+ var whitespaceBeforeCaret = lineOffset - prevCharIdx - 1;
+ var whitespaceAfterCaret = lineTextAfterCaret.length - lineTextAfterCaret.trimLeft().length;
+
+ text = lineText.charCodeAt(lineOffset + whitespaceAfterCaret) === 125 ?
lineDelimiter + prefix + tab + lineDelimiter + prefix :
lineDelimiter + prefix + tab;
- editor.setText(text, selection.start, selection.end);
- editor.setCaretOffset(selection.start + lineDelimiter.length + prefix.length + tab.length);
+
+ editor.setText(text, selection.start - whitespaceBeforeCaret, selection.end + whitespaceAfterCaret);
+ editor.setCaretOffset(selection.start + lineDelimiter.length + prefix.length + tab.length - whitespaceBeforeCaret);
return true;
// Proceed with autocompleting multi-line comment if the text before the caret matches
// the start or comment delimiter (*) of a multi-line comment