IDEA-63225 Provide key for CamelHump selection

This commit is contained in:
Denis.Zhdanov
2013-02-14 20:31:06 +04:00
parent c02ea9bbeb
commit 1d636477f1
15 changed files with 258 additions and 23 deletions
@@ -32,27 +32,38 @@ import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler;
public class DeleteToWordEndAction extends TextComponentEditorAction {
public DeleteToWordEndAction() {
super(new Handler());
super(new Handler(false));
}
private static class Handler extends EditorWriteActionHandler {
static class Handler extends EditorWriteActionHandler {
private final boolean myNegateCamelMode;
Handler(boolean negateCamelMode) {
myNegateCamelMode = negateCamelMode;
}
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP);
deleteToWordEnd(editor);
boolean camelMode = editor.getSettings().isCamelWords();
if (myNegateCamelMode) {
camelMode = !camelMode;
}
deleteToWordEnd(editor, camelMode);
}
}
private static void deleteToWordEnd(Editor editor) {
private static void deleteToWordEnd(Editor editor, boolean camelMode) {
int startOffset = editor.getCaretModel().getOffset();
int endOffset = getWordEndOffset(editor, startOffset);
int endOffset = getWordEndOffset(editor, startOffset, camelMode);
if(endOffset > startOffset) {
Document document = editor.getDocument();
document.deleteString(startOffset, endOffset);
}
}
private static int getWordEndOffset(Editor editor, int offset) {
private static int getWordEndOffset(Editor editor, int offset, boolean camelMode) {
Document document = editor.getDocument();
CharSequence text = document.getCharsSequence();
if(offset >= document.getTextLength() - 1)
@@ -65,10 +76,9 @@ public class DeleteToWordEndAction extends TextComponentEditorAction {
return offset;
maxOffset = document.getLineEndOffset(lineNumber+1);
}
boolean camel = editor.getSettings().isCamelWords();
for (; newOffset < maxOffset; newOffset++) {
if (EditorActionUtil.isWordEnd(text, newOffset, camel) ||
EditorActionUtil.isWordStart(text, newOffset, camel)) {
if (EditorActionUtil.isWordEnd(text, newOffset, camelMode) ||
EditorActionUtil.isWordStart(text, newOffset, camelMode)) {
break;
}
}
@@ -0,0 +1,27 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.editor.actions;
/**
* @author Denis Zhdanov
* @since 2/14/13 7:35 PM
*/
public class DeleteToWordEndInDifferentHumpsModeAction extends TextComponentEditorAction {
public DeleteToWordEndInDifferentHumpsModeAction() {
super(new DeleteToWordEndAction.Handler(true));
}
}
@@ -65,13 +65,18 @@ public class DeleteToWordStartAction extends TextComponentEditorAction {
private static final int[] QUOTE_SYMBOLS_ARRAY = QUOTE_SYMBOLS.toArray();
public DeleteToWordStartAction() {
super(new Handler());
super(new Handler(false));
}
private static class Handler extends EditorWriteActionHandler {
static class Handler extends EditorWriteActionHandler {
@NotNull private final TIntIntHashMap myQuotesNumber = new TIntIntHashMap();
private final boolean myNegateCamelMode;
Handler(boolean negateCamelMode) {
myNegateCamelMode = negateCamelMode;
}
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP);
@@ -79,6 +84,10 @@ public class DeleteToWordStartAction extends TextComponentEditorAction {
}
private void deleteToWordStart(Editor editor) {
boolean camel = editor.getSettings().isCamelWords();
if (myNegateCamelMode) {
camel = !camel;
}
CharSequence text = editor.getDocument().getCharsSequence();
CaretModel caretModel = editor.getCaretModel();
int endOffset = caretModel.getOffset();
@@ -90,7 +99,7 @@ public class DeleteToWordStartAction extends TextComponentEditorAction {
}
countQuotes(myQuotesNumber, text, minOffset, endOffset);
EditorActionUtil.moveCaretToPreviousWord(editor, false);
EditorActionUtil.moveCaretToPreviousWord(editor, false, camel);
for (int offset = caretModel.getOffset(); offset > minOffset; offset = caretModel.getOffset()) {
char previous = text.charAt(offset - 1);
@@ -106,7 +115,7 @@ public class DeleteToWordStartAction extends TextComponentEditorAction {
}
if (myQuotesNumber.get(current) % 2 == 0) {
// Was 'one "two" [caret]', now 'one "two[caret]"', we want to get 'one [caret]"two"'
EditorActionUtil.moveCaretToPreviousWord(editor, false);
EditorActionUtil.moveCaretToPreviousWord(editor, false, camel);
continue;
}
break;
@@ -0,0 +1,27 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.editor.actions;
/**
* @author Denis Zhdanov
* @since 2/14/13 7:31 PM
*/
public class DeleteToWordStartInDifferentHumpsModeAction extends TextComponentEditorAction {
public DeleteToWordStartInDifferentHumpsModeAction() {
super(new DeleteToWordStartAction.Handler(true));
}
}
@@ -569,7 +569,7 @@ public class EditorActionUtil {
setupSelection(editor, isWithSelection, selectionStart, blockSelectionStart);
}
public static void moveCaretToNextWord(Editor editor, boolean isWithSelection) {
public static void moveCaretToNextWord(Editor editor, boolean isWithSelection, boolean camel) {
Document document = editor.getDocument();
SelectionModel selectionModel = editor.getSelectionModel();
int selectionStart = selectionModel.getLeadSelectionOffset();
@@ -593,7 +593,6 @@ public class EditorActionUtil {
}
maxOffset = document.getLineEndOffset(lineNumber + 1);
}
boolean camel = editor.getSettings().isCamelWords();
for (; newOffset < maxOffset; newOffset++) {
if (isWordStart(text, newOffset, camel)) {
break;
@@ -651,7 +650,7 @@ public class EditorActionUtil {
editor.putUserData(PREV_POS, pos);
}
public static void moveCaretToPreviousWord(Editor editor, boolean isWithSelection) {
public static void moveCaretToPreviousWord(Editor editor, boolean isWithSelection, boolean camel) {
Document document = editor.getDocument();
SelectionModel selectionModel = editor.getSelectionModel();
int selectionStart = selectionModel.getLeadSelectionOffset();
@@ -667,7 +666,6 @@ public class EditorActionUtil {
CharSequence text = document.getCharsSequence();
int newOffset = offset - 1;
int minOffset = lineNumber > 0 ? document.getLineEndOffset(lineNumber - 1) : 0;
boolean camel = editor.getSettings().isCamelWords();
for (; newOffset > minOffset; newOffset--) {
if (isWordStart(text, newOffset, camel)) break;
}
@@ -37,7 +37,7 @@ public class NextWordAction extends TextComponentEditorAction {
private static class Handler extends EditorActionHandler {
@Override
public void execute(Editor editor, DataContext dataContext) {
EditorActionUtil.moveCaretToNextWord(editor, false);
EditorActionUtil.moveCaretToNextWord(editor, false, editor.getSettings().isCamelWords());
}
}
}
@@ -0,0 +1,38 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.editor.actions;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
/**
* @author Denis Zhdanov
* @since 2/14/13 7:22 PM
*/
public class NextWordInDifferentHumpsModeAction extends TextComponentEditorAction {
public NextWordInDifferentHumpsModeAction() {
super(new Handler());
}
private static class Handler extends EditorActionHandler {
@Override
public void execute(Editor editor, DataContext dataContext) {
EditorActionUtil.moveCaretToNextWord(editor, false, !editor.getSettings().isCamelWords());
}
}
}
@@ -0,0 +1,38 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.editor.actions;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
/**
* @author Denis Zhdanov
* @since 2/14/13 7:23 PM
*/
public class NextWordInDifferentHumpsModeWithSelectionAction extends TextComponentEditorAction {
public NextWordInDifferentHumpsModeWithSelectionAction() {
super(new Handler());
}
private static class Handler extends EditorActionHandler {
@Override
public void execute(Editor editor, DataContext dataContext) {
EditorActionUtil.moveCaretToNextWord(editor, true, !editor.getSettings().isCamelWords());
}
}
}
@@ -37,7 +37,7 @@ public class NextWordWithSelectionAction extends TextComponentEditorAction {
private static class Handler extends EditorActionHandler {
@Override
public void execute(Editor editor, DataContext dataContext) {
EditorActionUtil.moveCaretToNextWord(editor, true);
EditorActionUtil.moveCaretToNextWord(editor, true, editor.getSettings().isCamelWords());
}
}
}
@@ -37,7 +37,7 @@ public class PreviousWordAction extends TextComponentEditorAction {
private static class Handler extends EditorActionHandler {
@Override
public void execute(Editor editor, DataContext dataContext) {
EditorActionUtil.moveCaretToPreviousWord(editor, false);
EditorActionUtil.moveCaretToPreviousWord(editor, false, editor.getSettings().isCamelWords());
}
}
}
@@ -0,0 +1,38 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.editor.actions;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
/**
* @author Denis Zhdanov
* @since 2/14/13 7:24 PM
*/
public class PreviousWordInDifferentHumpsModeAction extends TextComponentEditorAction {
public PreviousWordInDifferentHumpsModeAction() {
super(new Handler());
}
private static class Handler extends EditorActionHandler {
@Override
public void execute(Editor editor, DataContext dataContext) {
EditorActionUtil.moveCaretToPreviousWord(editor, false, !editor.getSettings().isCamelWords());
}
}
}
@@ -0,0 +1,38 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.editor.actions;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
/**
* @author Denis Zhdanov
* @since 2/14/13 7:27 PM
*/
public class PreviousWordInDifferentHumpsModeWithSelectionAction extends TextComponentEditorAction {
public PreviousWordInDifferentHumpsModeWithSelectionAction() {
super(new Handler());
}
private static class Handler extends EditorActionHandler {
@Override
public void execute(Editor editor, DataContext dataContext) {
EditorActionUtil.moveCaretToPreviousWord(editor, true, !editor.getSettings().isCamelWords());
}
}
}
@@ -38,7 +38,7 @@ public class PreviousWordWithSelectionAction extends TextComponentEditorAction {
private static class Handler extends EditorActionHandler {
@Override
public void execute(Editor editor, DataContext dataContext) {
EditorActionUtil.moveCaretToPreviousWord(editor, true);
EditorActionUtil.moveCaretToPreviousWord(editor, true, editor.getSettings().isCamelWords());
}
}
}
@@ -117,16 +117,22 @@ action.EditorLineEndWithSelection.text=Move Caret to Line End with Selection
action.EditorTextStartWithSelection.text=Move Caret to Text Start with Selection
action.EditorTextEndWithSelection.text=Move Caret to Text End with Selection
action.EditorNextWord.text=Move Caret to Next Word
action.EditorNextWordInDifferentHumpsMode.text=Move Caret to Next Word in Different "CamelHumps" Mode
action.EditorPreviousWord.text=Move Caret to Previous Word
action.EditorPreviousWordInDifferentHumpsMode.text=Move Caret to Previous Word in Different "CamelHumps" Mode
action.EditorNextWordWithSelection.text=Move Caret to Next Word with Selection
action.EditorNextWordInDifferentHumpsModeWithSelection.text=Move Caret to Next Word with Selection in Different "CamelHumps" Mode
action.EditorPreviousWordWithSelection.text=Move Caret to Previous Word with Selection
action.EditorPreviousWordInDifferentHumpsModeWithSelection.text=Move Caret to Previous Word with Selection in Different "CamelHumps" Mode
action.EditorCodeBlockStart.text=Move Caret to Code Block Start
action.EditorCodeBlockEnd.text=Move Caret to Code Block End
action.EditorCodeBlockStartWithSelection.text=Move Caret to Code Block Start with Selection
action.EditorCodeBlockEndWithSelection.text=Move Caret to Code Block End with Selection
action.EditorMatchBrace.text=Move Caret to Matched Brace
action.EditorDeleteToWordStart.text=Delete to Word Start
action.EditorDeleteToWordStartInDifferentHumpsMode.text=Delete to Word Start in Different "CamelHumps" Mode
action.EditorDeleteToWordEnd.text=Delete to Word End
action.EditorDeleteToWordEndInDifferentHumpsMode.text=Delete to Word End in Different "CamelHumps" Mode
action.EditorDeleteLine.text=Delete Line
action.EditorKillToWordStart.text=Kill to Word Start
action.EditorKillToWordEnd.text=Kill to Word End
@@ -86,11 +86,17 @@
<action id="EditorTextStartWithSelection" class="com.intellij.openapi.editor.actions.TextStartWithSelectionAction"/>
<action id="EditorTextEndWithSelection" class="com.intellij.openapi.editor.actions.TextEndWithSelectionAction"/>
<action id="EditorNextWord" class="com.intellij.openapi.editor.actions.NextWordAction"/>
<action id="EditorPreviousWord" class="com.intellij.openapi.editor.actions.PreviousWordAction"/>
<action id="EditorNextWordInDifferentHumpsMode" class="com.intellij.openapi.editor.actions.NextWordInDifferentHumpsModeAction"/>
<action id="EditorNextWordWithSelection" class="com.intellij.openapi.editor.actions.NextWordWithSelectionAction"/>
<action id="EditorNextWordInDifferentHumpsModeWithSelection" class="com.intellij.openapi.editor.actions.NextWordInDifferentHumpsModeWithSelectionAction"/>
<action id="EditorPreviousWord" class="com.intellij.openapi.editor.actions.PreviousWordAction"/>
<action id="EditorPreviousWordInDifferentHumpsMode" class="com.intellij.openapi.editor.actions.PreviousWordInDifferentHumpsModeAction"/>
<action id="EditorPreviousWordWithSelection" class="com.intellij.openapi.editor.actions.PreviousWordWithSelectionAction"/>
<action id="EditorPreviousWordInDifferentHumpsModeWithSelection" class="com.intellij.openapi.editor.actions.PreviousWordInDifferentHumpsModeWithSelectionAction"/>
<action id="EditorDeleteToWordStart" class="com.intellij.openapi.editor.actions.DeleteToWordStartAction"/>
<action id="EditorDeleteToWordStartInDifferentHumpsMode" class="com.intellij.openapi.editor.actions.DeleteToWordStartInDifferentHumpsModeAction"/>
<action id="EditorDeleteToWordEnd" class="com.intellij.openapi.editor.actions.DeleteToWordEndAction"/>
<action id="EditorDeleteToWordEndInDifferentHumpsMode" class="com.intellij.openapi.editor.actions.DeleteToWordEndInDifferentHumpsModeAction"/>
<action id="EditorDeleteLine" class="com.intellij.openapi.editor.actions.DeleteLineAction"/>
<action id="EditorKillToWordStart" class="com.intellij.openapi.editor.actions.KillToWordStartAction"/>
<action id="EditorKillToWordEnd" class="com.intellij.openapi.editor.actions.KillToWordEndAction"/>