private int putTextCharacterwise(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, @NotNull String text, @NotNull SelectionType type, @NotNull CommandState.SubMode mode, int startOffset, int count, boolean indent, boolean cursorAfter) { MotionGroup.moveCaret(editor, caret, startOffset); final String insertedText = StringUtil.repeat(text, count); VimPlugin.getChange().insertText(editor, caret, insertedText); final int endOffset = indent ? doIndent(editor, caret, context, startOffset, startOffset + insertedText.length()) : startOffset + insertedText.length(); moveCaret(editor, caret, type, mode, startOffset, endOffset, cursorAfter); return endOffset; }
@NotNull public static String pad(@NotNull final Editor editor, @NotNull DataContext context, int line, final int to) { final int len = getLineLength(editor, line); if(len >= to) return ""; final VirtualFile virtualFile = EditorData.getVirtualFile(editor); final Project project = PlatformDataKeys.PROJECT.getData(context); final int limit = to - len; if (virtualFile != null) { final FileType fileType = FileTypeManager.getInstance().getFileTypeByFile(virtualFile); final CodeStyleSettings settings = project == null ? CodeStyle.getDefaultSettings() : CodeStyle.getSettings(project); if (settings.useTabCharacter(fileType)) { final int tabSize = settings.getTabSize(fileType); final int tabsCnt = limit / tabSize; final int spacesCnt = limit % tabSize; return StringUtil.repeat("\t", tabsCnt) + StringUtil.repeat(" ", spacesCnt); } } return StringUtil.repeat(" ", limit); }
/** * Inserts a new line below the caret position * * @param editor The editor to insert into * @param caret The caret to insert after * @param col The column to indent to */ private void insertNewLineBelow(@NotNull Editor editor, @NotNull Caret caret, int col) { if (editor.isOneLineMode()) return; MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLineEnd(editor, caret)); EditorData.setChangeSwitchMode(editor, CommandState.Mode.INSERT); insertText(editor, caret, "\n" + StringUtil.repeat(" ", col)); }
/** * Inserts a new line above the caret position * * @param editor The editor to insert into * @param caret The caret to insert above * @param col The column to indent to */ private void insertNewLineAbove(@NotNull Editor editor, @NotNull Caret caret, int col) { if (editor.isOneLineMode()) return; if (caret.getVisualPosition().line == 0) { MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLineStart(editor, caret)); CaretData.setWasInFirstLine(caret, true); } else { MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretVertical(editor, caret, -1)); MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretToLineEnd(editor, caret)); } EditorData.setChangeSwitchMode(editor, CommandState.Mode.INSERT); insertText(editor, caret, "\n" + StringUtil.repeat(" ", col)); if (CaretData.wasInFirstLine(caret)) { MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretVertical(editor, caret, -1)); CaretData.setWasInFirstLine(caret, false); } }
int lineDiff = endLine - startLine; if (lineDiff < 2) { document.insertString(lbraceEndOffset, StringUtil.repeat("\n", 2 - lineDiff));
int previous = 0; while (m.find()) { String replacement = "<br/>" + StringUtil.repeat(" ", m.group().length()); builder.append(preformated.substring(previous, m.start())); builder.append(replacement);
myOut.print(StringUtil.repeat(" ", newStatement ? myOffset : myOffset + 1));
@NotNull private static String getIndenter(@NotNull Project project, int indentSize) { CommonCodeStyleSettings.IndentOptions indentOptions = CodeStyle.getSettings(project).getCommonSettings(PerlLanguage.INSTANCE).getIndentOptions(); return StringUtil.repeat(indentOptions != null && indentOptions.USE_TAB_CHARACTER ? "\t" : " ", indentSize); }
private static LookupElement createKeywordLookupItem(String keyword) { LookupElementBuilder builder = LookupElementBuilder.create(keyword.toLowerCase()).withCaseSensitivity(false).bold(); boolean braces = keyword.endsWith("{") || keyword.endsWith("}"); if (!braces) { return keyword.startsWith("%") ? TailTypeDecorator.withTail(builder, TailType.SPACE) : builder; } else { final String closing = keyword.endsWith("{") ? keyword.substring(0, keyword.length()-1) + "}" : null; return PrioritizedLookupElement.withPriority(builder.withInsertHandler((context, item) -> { int caret = context.getTailOffset(); Document document = context.getDocument(); StringBuilder sb = new StringBuilder("\n"); caret += sb.length(); if (closing != null) { int indentSize = CodeStyleSettingsManager.getInstance(context.getProject()). getCurrentSettings().getIndentSize(JFlexFileType.INSTANCE); sb.append(StringUtil.repeat(" ", indentSize)); caret += indentSize; sb.append("\n").append(closing).append("\n"); } document.insertString(context.getTailOffset(), sb); context.getEditor().getCaretModel().moveToOffset(caret); }), 1.d / keyword.length()); } } }
myFixture.testAction(new ExpandLiveTemplateByTabAction()); if (!StringUtil.equals(document.getText(), textBeforeAction)) { sb.append(StringUtil.repeat("-", 80)).append("\n") .append("Caret offset: ") .append(offset) .append("\n") .append(StringUtil.repeat("-", 80)).append("\n") .append(getEditorTextWithCaretsAndSelections());