Skip to content

Commit

Permalink
Merge pull request #26 from scala-ide/issue/auto-indenter-get-confuse…
Browse files Browse the repository at this point in the history
…d-1000688

Created a new indenter strategy that will automatically add a closing bracket
  • Loading branch information
dotta committed Nov 1, 2011
2 parents 5ecaba6 + 12ce545 commit 5be348c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -34,6 +34,7 @@ import scala.tools.eclipse.util.ReflectionUtils
import scala.tools.eclipse.lexical._
import scala.tools.eclipse.formatter.ScalaFormattingStrategy
import scala.tools.eclipse.properties.ScalaSyntaxClasses
import scala.tools.eclipse.ui.AutoCloseBracketStrategy

class ScalaSourceViewerConfiguration(store: IPreferenceStore, scalaPreferenceStore: IPreferenceStore, editor: ITextEditor)
extends JavaSourceViewerConfiguration(JavaPlugin.getDefault.getJavaTextTools.getColorManager, store, editor, IJavaPartitions.JAVA_PARTITIONING) {
Expand Down Expand Up @@ -120,7 +121,7 @@ class ScalaSourceViewerConfiguration(store: IPreferenceStore, scalaPreferenceSto
case IJavaPartitions.JAVA_STRING =>
Array(new SmartSemicolonAutoEditStrategy(partitioning), new JavaStringAutoIndentStrategy(partitioning))
case IJavaPartitions.JAVA_CHARACTER | IDocument.DEFAULT_CONTENT_TYPE =>
Array(new SmartSemicolonAutoEditStrategy(partitioning), new ScalaAutoIndentStrategy(partitioning, getProject, sourceViewer, new JdtPreferenceProvider(getProject)))
Array(new SmartSemicolonAutoEditStrategy(partitioning), new ScalaAutoIndentStrategy(partitioning, getProject, sourceViewer, new JdtPreferenceProvider(getProject)), new AutoCloseBracketStrategy)
case _ =>
Array(new ScalaAutoIndentStrategy(partitioning, getProject, sourceViewer, new JdtPreferenceProvider(getProject)))
}
Expand Down
@@ -0,0 +1,16 @@
package scala.tools.eclipse.ui

import org.eclipse.jface.text.DocumentCommand
import org.eclipse.jface.text.IAutoEditStrategy
import org.eclipse.jface.text.IDocument

/** Automatically adds a matching closing bracket whenever the user enters a left bracket. */
class AutoCloseBracketStrategy extends IAutoEditStrategy {
def customizeDocumentCommand(document: IDocument, command: DocumentCommand) {
if (command.text == "{") {
command.text = command.text + "}"
command.caretOffset = command.offset + 1
command.shiftsCaret = false
}
}
}

0 comments on commit 5be348c

Please sign in to comment.