Skip to content

Commit

Permalink
Add support for custom digraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
citizenmatt authored and AlexPl292 committed Sep 5, 2024
1 parent cc53b59 commit 10283ce
Show file tree
Hide file tree
Showing 7 changed files with 789 additions and 60 deletions.
2 changes: 2 additions & 0 deletions src/main/resources/messages/IdeaVimBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ E20=E20: Mark not set
e_nopresub=E33: No previous substitute regular expression
e_noprev=E34: No previous command
e_noprevre=E35: No previous regular expression
E39=E39: Number expected
e_re_damg=E43: Damaged match string
e_re_corr=E44: Currupted regexp program
E50=E50: Too many \\z(
Expand Down Expand Up @@ -84,6 +85,7 @@ E549=E549: Illegal percentage: {0}
E774=E774: 'operatorfunc' is empty
e841.reserved.name.cannot.be.used.for.user.defined.command=E841: Reserved name, cannot be used for user defined command
E939=E939: Positive count required
E1214=E1214: Digraph must be just two characters: {0}

message.search.hit.bottom=search hit BOTTOM, continuing at TOP
message.search.hit.top=search hit TOP, continuing at BOTTOM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,33 @@ class InsertCompletedDigraphActionTest : VimTestCase() {
fun `test insert same character with different digraphs`() {
doTest(listOf("i", "<C-K>Ct", "<C-K>c|", "<Esc>"), "", "¢¢")
}

@Test
fun `test insert custom digraph`() {
doTest(listOf("i", "<C-K>(0", "<Esc>"), "", "") {
enterCommand("digraph (0 9450")
}
}

@Test
fun `test insert custom digraph with reversed characters`() {
doTest(listOf("i", "<C-K>0(", "<Esc>"), "", "") {
enterCommand("digraph (0 9450")
}
}

@Test
fun `test insert custom digraph overriding existing custom digraph`() {
doTest(listOf("i", "<C-K>(0", "<Esc>"), "", "") {
enterCommand("digraph (0 9450")
enterCommand("digraph (0 10003")
}
}

@Test
fun `test insert custom digraph overriding existing default digraph`() {
doTest(listOf("i", "<C-K>OK", "<Esc>"), "", "") {
enterCommand("digraph OK 9450")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,12 @@ class AsciiCommandTest : VimTestCase() {
enterCommand("ascii")
assertEquals("<¢> 162, Hex a2, Oct 242, Digr Ct", VimPlugin.getMessage())
}

@Test
fun `test shows custom digraph`() {
configureByText("")
enterCommand("digraph (0 9450")
enterCommand("ascii")
assertEquals("<⓪> 9450, Hex 24ea, Oct 22352, Digr (0", VimPlugin.getMessage())
}
}

Large diffs are not rendered by default.

36 changes: 32 additions & 4 deletions src/test/java/org/jetbrains/plugins/ideavim/option/DigraphTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,40 @@ class DigraphTest : VimTestCase() {
Sed in orci mauris.
Cras id tellus in ex imperdiet egestas.
""".trimIndent(),
Mode.INSERT,
Mode.INSERT,
) {
enterCommand("set digraph")
}
}

@TestWithoutNeovim(SkipNeovimReason.UNCLEAR, "backspace works strange")
@Test
fun `test digraph with custom digraph`() {
doTest(
"i (<BS>0",
"""
Lorem Ipsum
I found it$c in a legendary land
consectetur adipiscing elit
Sed in orci mauris.
Cras id tellus in ex imperdiet egestas.
""".trimIndent(),
"""
Lorem Ipsum
I found it ⓪$c in a legendary land
consectetur adipiscing elit
Sed in orci mauris.
Cras id tellus in ex imperdiet egestas.
""".trimIndent(),
Mode.INSERT,
) {
enterCommand("digraph (0 9450")
enterCommand("set digraph")
}
}

@TestWithoutNeovim(SkipNeovimReason.UNCLEAR, "backspace works strange")
@Test
fun `test digraph stops`() {
Expand All @@ -67,7 +95,7 @@ Mode.INSERT,
Sed in orci mauris.
Cras id tellus in ex imperdiet egestas.
""".trimIndent(),
Mode.INSERT,
Mode.INSERT,
) {
enterCommand("set digraph")
}
Expand All @@ -94,7 +122,7 @@ Mode.INSERT,
Sed in orci mauris.
Cras id tellus in ex imperdiet egestas.
""".trimIndent(),
Mode.INSERT,
Mode.INSERT,
) {
enterCommand("set digraph")
}
Expand All @@ -121,7 +149,7 @@ Mode.INSERT,
Sed in orci mauris.
Cras id tellus in ex imperdiet egestas.
""".trimIndent(),
Mode.INSERT,
Mode.INSERT,
) {
enterCommand("set digraph")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.maddyhome.idea.vim.action.VimShortcutKeyAction
import com.maddyhome.idea.vim.api.EffectiveOptions
import com.maddyhome.idea.vim.api.GlobalOptions
import com.maddyhome.idea.vim.api.Options
import com.maddyhome.idea.vim.api.VimDigraphGroupBase
import com.maddyhome.idea.vim.api.VimOptionGroup
import com.maddyhome.idea.vim.api.globalOptions
import com.maddyhome.idea.vim.api.injector
Expand Down Expand Up @@ -223,6 +224,7 @@ abstract class VimTestCase {
assertTrue(KeyHandler.getInstance().keyStack.isEmpty())
injector.outputPanel.getCurrentOutputPanel()?.close()
injector.modalInput.getCurrentModalInput()?.deactivate(refocusOwningEditor = false, resetCaret = false)
(injector.digraphGroup as VimDigraphGroupBase).clearCustomDigraphs()

// Tear down neovim
NeovimTesting.tearDown(testInfo)
Expand Down
Loading

0 comments on commit 10283ce

Please sign in to comment.