-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af8edae
commit ddb159e
Showing
4 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/com/maddyhome/idea/vim/ex/handler/BufferCloseHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform | ||
* Copyright (C) 2003-2021 The IdeaVim authors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.maddyhome.idea.vim.ex.handler | ||
|
||
import com.intellij.openapi.actionSystem.DataContext | ||
import com.intellij.openapi.editor.Editor | ||
import com.maddyhome.idea.vim.VimPlugin | ||
import com.maddyhome.idea.vim.ex.CommandHandler | ||
import com.maddyhome.idea.vim.ex.ExCommand | ||
import com.maddyhome.idea.vim.ex.flags | ||
|
||
class BufferCloseHandler : CommandHandler.SingleExecution() { | ||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY) | ||
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean { | ||
val arg = cmd.argument.trim() | ||
if (arg.isNotEmpty() && arg.matches(Regex("^\\d+$"))) { | ||
val bufNum = arg.toInt() - 1 | ||
VimPlugin.getFile().closeFile(bufNum, editor, context) | ||
} else { | ||
VimPlugin.getFile().closeFile(editor, context) | ||
} | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
test/org/jetbrains/plugins/ideavim/ex/handler/BufferCloseHandlerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform | ||
* Copyright (C) 2003-2021 The IdeaVim authors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jetbrains.plugins.ideavim.ex.handler | ||
|
||
import org.jetbrains.plugins.ideavim.VimTestCase | ||
|
||
/** | ||
* @author Michal Placek | ||
*/ | ||
class BufferCloseHandlerTest : VimTestCase() { | ||
fun `test close file by bd command`() { | ||
|
||
val psiFile1 = myFixture.configureByText("A_Discovery1", "I found it in a legendary land") | ||
val psiFile2 = myFixture.configureByText("A_Discovery2", "all rocks and lavender and tufted grass,") | ||
|
||
fileManager.openFile(psiFile1.virtualFile, false) | ||
fileManager.openFile(psiFile2.virtualFile, true) | ||
assertPluginError(false) | ||
|
||
typeText(commandToKeys("bd")) | ||
|
||
assertPluginError(false) | ||
} | ||
} |