Skip to content

Commit

Permalink
Merge pull request #240 from rieonke/VIM-2059
Browse files Browse the repository at this point in the history
add support for putting & editing macros
  • Loading branch information
AlexPl292 authored Jul 22, 2020
2 parents db8fa31 + e57d6f3 commit 3edd95d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/com/maddyhome/idea/vim/action/copy/PutTextAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.group.copy.PutData
import com.maddyhome.idea.vim.group.copy.PutData.TextData
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
import com.maddyhome.idea.vim.helper.StringHelper

sealed class PutTextBaseAction(
private val insertTextBeforeCaret: Boolean,
Expand All @@ -35,7 +36,7 @@ sealed class PutTextBaseAction(

override fun execute(editor: Editor, context: DataContext, count: Int, rawCount: Int, argument: Argument?): Boolean {
val lastRegister = VimPlugin.getRegister().lastRegister
val textData = if (lastRegister != null) TextData(lastRegister.text, lastRegister.type, lastRegister.transferableData) else null
val textData = if (lastRegister != null) TextData(lastRegister.text ?: StringHelper.toKeyNotation(lastRegister.keys), lastRegister.type, lastRegister.transferableData) else null
val putData = PutData(textData, null, count, insertTextBeforeCaret, indent, caretAfterInsertedText, -1)
return VimPlugin.getPut().putText(editor, context, putData)
}
Expand Down
8 changes: 5 additions & 3 deletions src/com/maddyhome/idea/vim/ex/handler/PutLinesHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.maddyhome.idea.vim.ex.CommandHandler
import com.maddyhome.idea.vim.ex.ExCommand
import com.maddyhome.idea.vim.ex.flags
import com.maddyhome.idea.vim.group.copy.PutData
import com.maddyhome.idea.vim.helper.StringHelper

class PutLinesHandler : CommandHandler.SingleExecution() {
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY)
Expand All @@ -35,14 +36,15 @@ class PutLinesHandler : CommandHandler.SingleExecution() {

val registerGroup = VimPlugin.getRegister()
val arg = cmd.argument
if (arg.isNotEmpty() && !registerGroup.selectRegister(arg[0])) {
return false
if (arg.isNotEmpty()) {
if(!registerGroup.selectRegister(arg[0]))
return false
} else {
registerGroup.selectRegister(registerGroup.defaultRegister)
}

val line = if (cmd.ranges.size() == 0) -1 else cmd.getLine(editor)
val textData = registerGroup.lastRegister?.let { PutData.TextData(it.text, SelectionType.LINE_WISE, it.transferableData) }
val textData = registerGroup.lastRegister?.let { PutData.TextData(it.text ?: StringHelper.toKeyNotation(it.keys), SelectionType.LINE_WISE, it.transferableData) }
val putData = PutData(textData, null, 1, insertTextBeforeCaret = false, _indent = false, caretAfterInsertedText = false, putToLine = line)
return VimPlugin.getPut().putText(editor, context, putData)
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/maddyhome/idea/vim/ex/handler/RegistersHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RegistersHandler : CommandHandler.SingleExecution() {
SelectionType.CHARACTER_WISE -> "c"
SelectionType.BLOCK_WISE -> "b"
}
" $type \"${reg.name} ${StringHelper.toPrintableCharacters(reg.keys).take(200)}"
" $type \"${reg.name} ${StringHelper.toKeyNotation(reg.keys).take(200)}"
}

ExOutputModel.getInstance(editor).output(regs)
Expand Down
10 changes: 8 additions & 2 deletions src/com/maddyhome/idea/vim/group/MacroGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.maddyhome.idea.vim.KeyHandler;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.common.Register;
import com.maddyhome.idea.vim.helper.StringHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -57,8 +58,13 @@ public boolean playbackRegister(@NotNull Editor editor, @NotNull DataContext con
if (register == null) {
return false;
}

List<KeyStroke> keys = register.getKeys();
List<KeyStroke> keys;
if (register.getRawText() == null) {
keys = register.getKeys();
}
else {
keys = StringHelper.parseKeys(register.getRawText());
}
playbackKeys(editor, context, project, keys, 0, 0, count);

lastRegister = reg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class RegistersHandlerTest : VimTestCase() {

enterCommand("registers")
assertExOutput("""Type Name Content
| c "a ^IHello World^J^[
| c "a <Tab>Hello World<CR><Esc>
""".trimMargin())
}

Expand Down

0 comments on commit 3edd95d

Please sign in to comment.