(search) Remove stray spaces in bang commands

This commit is contained in:
Viktor Lofgren 2024-02-08 14:46:12 +01:00
parent 06997ff255
commit ef261cbbd7
2 changed files with 21 additions and 6 deletions

View File

@ -53,14 +53,13 @@ public class BangCommand implements SearchCommandInterface {
if (!bm.isRelativeSpaceOrInvalid(bangKey.length())) if (!bm.isRelativeSpaceOrInvalid(bangKey.length()))
continue; continue;
StringBuilder ret = new StringBuilder(bm.prefix().trim()); String prefix = bm.prefix().trim();
String suffix = bm.suffix(bangKey.length()).trim();
if (!ret.isEmpty()) String ret = STR."\{prefix} \{suffix}".trim();
ret.append(" ");
ret.append(bm.suffix(bangKey.length()).trim()); return Optional.of(ret)
.filter(s -> !s.isBlank());
return Optional.of(ret.toString());
} }
return Optional.empty(); return Optional.empty();

View File

@ -34,4 +34,20 @@ class BangCommandTest {
assertEquals(match.get(), "test"); assertEquals(match.get(), "test");
} }
@Test
public void testMatchPattern2() {
var match = bangCommand.matchBangPattern("test !g", "!g");
assertTrue(match.isPresent());
assertEquals(match.get(), "test");
}
@Test
public void testMatchPattern3() {
var match = bangCommand.matchBangPattern("hello !g world", "!g");
assertTrue(match.isPresent());
assertEquals(match.get(), "hello world");
}
} }