IDEA-65256 (Quick Surround with Quotes/Parentheses improvement)

This commit is contained in:
Bas Leijdekkers
2012-01-02 23:59:19 +01:00
parent d5d36d778b
commit e60147d8e1
3 changed files with 32 additions and 3 deletions
@@ -63,9 +63,14 @@ public class SelectionQuotingTypedHandler extends TypedHandlerDelegate {
final char c2 = getMatchingDelimiter(c);
final String newText = String.valueOf(c) + selectedText + c2;
EditorModificationUtil.insertStringAtCaret(editor, newText);
if (Registry.is("editor.smarterSelectionQuoting") && !replace) {
if (Registry.is("editor.smarterSelectionQuoting")) {
myReplacedTextRange = new TextRange(caretOffset + 1, caretOffset + newText.length() - 1);
myCaretPosition += 1;
if (!replace || myCaretPosition == caretOffset) {
myCaretPosition++;
}
else if (myCaretPosition == caretOffset + newText.length()) {
myCaretPosition--;
}
} else {
myReplacedTextRange = new TextRange(caretOffset, caretOffset + newText.length());
}
@@ -97,7 +97,7 @@ editor.balloonHints=true
editor.mouseSelectionStateResetTimeout=1000
editor.mouseSelectionStateResetDeadzone=4
editor.use.new.tabs=true
editor.smarterSelectionQuoting=false
editor.smarterSelectionQuoting=true
ide.tabbedPane.bufferedPaint=true
ide.tabbedPane.dragOutMultiplier=1.2
@@ -102,6 +102,30 @@ public class SelectionQuotingTypedHandlerTest extends LightPlatformCodeInsightFi
doTest('[', "<selection><caret>\"aaa\"</selection>\nbbb\n\n", "[\"aaa\"]\nbbb\n\n");
}
public void testReplaceBracketAndText() {
doTest("'a", "<selection><caret>\"b\"</selection>\nbbb\n\n", "'a<caret>'\nbbb\n\n");
}
public void testTripleEnquote() {
doTest("\"\"\"", "<selection>text<caret></selection>\nbbb\n\n", "\"\"\"<selection>text</selection>\"\"\"\nbbb\n\n");
}
private void doTest(@NotNull final String cs, @NotNull String before, @NotNull String expected) {
myFixture.configureByText(FileTypes.PLAIN_TEXT, before);
final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
performAction(myFixture.getProject(), new Runnable() {
@Override
public void run() {
for (int i = 0, max = cs.length(); i < max; i++) {
final char c = cs.charAt(i);
typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext());
}
}
});
myFixture.checkResult(expected);
}
public void testRuby7852ErrantEditor() {
myFixture.configureByText(FileTypes.PLAIN_TEXT, "\"aaa\"\nbbb\n\n");
myFixture.getEditor().getCaretModel().moveToOffset(0);