Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIM-2113 Increase tag range only in visual mode #249

Merged
merged 1 commit into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/com/maddyhome/idea/vim/helper/SearchHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.common.TextRange;
import com.maddyhome.idea.vim.option.ListOption;
import com.maddyhome.idea.vim.option.OptionsManager;
Expand Down Expand Up @@ -541,16 +542,19 @@ else if (isInHTMLTag(sequence, searchStartPosition, true)) {
selectionEndWithoutNewline++;
}

if (closingTagTextRange.getStartOffset() == selectionEndWithoutNewline &&
final CommandState.Mode mode = CommandState.getInstance(editor).getMode();
if (mode == CommandState.Mode.VISUAL) {
if (closingTagTextRange.getStartOffset() == selectionEndWithoutNewline &&
openingTag.getEndOffset() == selectionStart) {
// Special case: if the inner tag is already selected we should like isOuter is active
// Note that we need to ignore newlines, because their selection is lost between multiple "it" invocations
isOuter = true;
}
else if (openingTag.getEndOffset() == closingTagTextRange.getStartOffset() &&
selectionStart == openingTag.getEndOffset()) {
// Special case: for an empty tag pair (e.g. <a></a>) the whole tag is selected if the caret is in the middle.
isOuter = true;
// Special case: if the inner tag is already selected we should like isOuter is active
// Note that we need to ignore newlines, because their selection is lost between multiple "it" invocations
isOuter = true;
}
else if (openingTag.getEndOffset() == closingTagTextRange.getStartOffset() &&
selectionStart == openingTag.getEndOffset()) {
// Special case: for an empty tag pair (e.g. <a></a>) the whole tag is selected if the caret is in the middle.
isOuter = true;
}
}

if (isOuter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ public void testDeleteOuterTagWithCount() {
myFixture.checkResult("<a></a>");
}

// VIM-2113
public void testReplaceEmptyTagContent() {
typeTextInFile(parseKeys("cit"),"<a><c><caret></c></a>");
myFixture.checkResult("<a><c></c></a>");
}

// |[(|
public void testUnmatchedOpenParenthesis() {
typeTextInFile(parseKeys("[("),
Expand Down