use of com.maddyhome.idea.vim.common.CharacterPosition in project ideavim by JetBrains.
the class SearchGroup method searchAndReplace.
public boolean searchAndReplace(@NotNull Editor editor, @NotNull LineRange range, @NotNull String excmd, String exarg) {
// Explicitly exit visual mode here, so that visual mode marks don't change when we move the cursor to a match.
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
VimPlugin.getMotion().exitVisual(editor);
}
CharPointer cmd = new CharPointer(new StringBuffer(exarg));
//sub_nsubs = 0;
//sub_nlines = 0;
int which_pat;
if (excmd.equals("~")) {
which_pat = RE_LAST;
/* use last used regexp */
} else {
which_pat = RE_SUBST;
/* use last substitute regexp */
}
CharPointer pat;
CharPointer sub;
char delimiter;
/* new pattern and substitution */
if (excmd.charAt(0) == 's' && !cmd.isNul() && !Character.isWhitespace(cmd.charAt()) && "0123456789cegriIp|\"".indexOf(cmd.charAt()) == -1) {
/* don't accept alphanumeric for separator */
if (CharacterClasses.isAlpha(cmd.charAt())) {
VimPlugin.showMessage(MessageHelper.message(Msg.E146));
return false;
}
/*
* undocumented vi feature:
* "\/sub/" and "\?sub?" use last used search pattern (almost like
* //sub/r). "\&sub&" use last substitute pattern (like //sub/).
*/
if (cmd.charAt() == '\\') {
cmd.inc();
if ("/?&".indexOf(cmd.charAt()) == -1) {
VimPlugin.showMessage(MessageHelper.message(Msg.e_backslash));
return false;
}
if (cmd.charAt() != '&') {
which_pat = RE_SEARCH;
/* use last '/' pattern */
}
pat = new CharPointer("");
/* empty search pattern */
delimiter = cmd.charAt();
/* remember delimiter character */
cmd.inc();
} else /* find the end of the regexp */
{
which_pat = RE_LAST;
/* use last used regexp */
delimiter = cmd.charAt();
/* remember delimiter character */
cmd.inc();
pat = cmd.ref(0);
/* remember start of search pat */
cmd = RegExp.skip_regexp(cmd, delimiter, true);
if (cmd.charAt() == delimiter) /* end delimiter found */
{
cmd.set('