-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VIM-2074 Backspace behaviour is incorrect in Replace mode
- Loading branch information
Showing
14 changed files
with
133 additions
and
7 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
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
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
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
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
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
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
...gine/src/main/kotlin/com/maddyhome/idea/vim/action/change/insert/InsertBackspaceAction.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 @@ | ||
/* | ||
* Copyright 2003-2024 The IdeaVim authors | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE.txt file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
package com.maddyhome.idea.vim.action.change.insert | ||
|
||
import com.intellij.vim.annotations.CommandOrMotion | ||
import com.intellij.vim.annotations.Mode | ||
import com.maddyhome.idea.vim.api.ExecutionContext | ||
import com.maddyhome.idea.vim.api.VimEditor | ||
import com.maddyhome.idea.vim.api.getLineStartForOffset | ||
import com.maddyhome.idea.vim.api.injector | ||
import com.maddyhome.idea.vim.command.Command | ||
import com.maddyhome.idea.vim.command.OperatorArguments | ||
import com.maddyhome.idea.vim.handler.VimActionHandler | ||
|
||
@CommandOrMotion(keys = ["<C-H>", "<BS>"], modes = [Mode.INSERT]) | ||
internal class InsertBackspaceAction : VimActionHandler.SingleExecution() { | ||
override val type: Command.Type = Command.Type.OTHER_WRITABLE | ||
|
||
override fun execute( editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments, ): Boolean { | ||
if (editor.insertMode) { | ||
injector.changeGroup.processBackspace(editor, context) | ||
} else { | ||
for (caret in editor.carets()) { | ||
val offset = (caret.offset - 1).takeIf { it > 0 } ?: continue | ||
val oldChar = editor.replaceMask?.popChange(editor, offset) | ||
if (oldChar != null) { | ||
injector.changeGroup.replaceText(editor, caret, offset, offset + 1, oldChar.toString()) | ||
} | ||
caret.moveToOffset(offset) | ||
} | ||
} | ||
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
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
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
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
35 changes: 35 additions & 0 deletions
35
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/common/VimEditorReplaceMask.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,35 @@ | ||
/* | ||
* Copyright 2003-2024 The IdeaVim authors | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE.txt file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
package com.maddyhome.idea.vim.common | ||
|
||
import com.maddyhome.idea.vim.api.VimEditor | ||
import com.maddyhome.idea.vim.api.injector | ||
|
||
class VimEditorReplaceMask { | ||
private val changedChars = mutableMapOf<LiveRange, Char>() | ||
|
||
fun recordChangeAtCaret(editor: VimEditor) { | ||
for (caret in editor.carets()) { | ||
val offset = caret.offset | ||
val marker = editor.createLiveMarker(offset, offset) | ||
changedChars[marker] = editor.charAt(offset) | ||
} | ||
} | ||
|
||
fun popChange(editor: VimEditor, offset: Int): Char? { | ||
val marker = editor.createLiveMarker(offset, offset) | ||
val change = changedChars[marker] | ||
changedChars.remove(marker) | ||
return change | ||
} | ||
} | ||
|
||
fun forgetAllReplaceMasks() { | ||
injector.editorGroup.getEditors().forEach { it.replaceMask = null } | ||
} |
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