position text cursor at the end of the selection after surrounding with quotes/braces

This commit is contained in:
Bas Leijdekkers
2012-01-03 23:54:25 +01:00
parent f894869eb1
commit 4d660878b2
@@ -35,7 +35,6 @@ public class SelectionQuotingTypedHandler extends TypedHandlerDelegate {
public static final ExtensionPointName<DequotingFilter> EP_NAME =
ExtensionPointName.create("com.intellij.selectionDequotingFilter");
private TextRange myReplacedTextRange;
private int myCaretPosition;
@Override
public Result checkAutoPopup(char c, Project project, Editor editor, PsiFile psiFile) {
@@ -46,8 +45,6 @@ public class SelectionQuotingTypedHandler extends TypedHandlerDelegate {
if (selectedText.length() < 1) {
return super.checkAutoPopup(c, project, editor, psiFile);
}
myCaretPosition = editor.getCaretModel().getOffset();
boolean replace = false;
if (selectedText.length() > 1) {
final char firstChar = selectedText.charAt(0);
if (isSimilarDelimiters(firstChar, c) &&
@@ -56,7 +53,6 @@ public class SelectionQuotingTypedHandler extends TypedHandlerDelegate {
!shouldSkipReplacementOfQuotesOrBraces(psiFile, editor, selectedText, c)
) {
selectedText = selectedText.substring(1, selectedText.length() - 1);
replace = true;
}
}
final int caretOffset = editor.getSelectionModel().getSelectionStart();
@@ -65,12 +61,6 @@ public class SelectionQuotingTypedHandler extends TypedHandlerDelegate {
EditorModificationUtil.insertStringAtCaret(editor, newText);
if (Registry.is("editor.smarterSelectionQuoting")) {
myReplacedTextRange = new TextRange(caretOffset + 1, caretOffset + newText.length() - 1);
if (!replace || myCaretPosition == caretOffset) {
myCaretPosition++;
}
else if (myCaretPosition == caretOffset + newText.length()) {
myCaretPosition--;
}
} else {
myReplacedTextRange = new TextRange(caretOffset, caretOffset + newText.length());
}
@@ -117,7 +107,7 @@ public class SelectionQuotingTypedHandler extends TypedHandlerDelegate {
if (myReplacedTextRange.getEndOffset() <= editor.getDocument().getTextLength()) {
editor.getSelectionModel().setSelection(myReplacedTextRange.getStartOffset(), myReplacedTextRange.getEndOffset());
if (Registry.is("editor.smarterSelectionQuoting")) {
editor.getCaretModel().moveToOffset(myCaretPosition);
editor.getCaretModel().moveToOffset(myReplacedTextRange.getEndOffset());
}
}
myReplacedTextRange = null;