mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-07-31 03:59:07 +02:00
Remove TODO: use tabs as needed
This commit is contained in:
parent
0bf217ef36
commit
a046f2975f
src/com/maddyhome/idea/vim
@ -537,7 +537,7 @@ public class ChangeGroup {
|
||||
if (repeatAppend &&
|
||||
repeatColumn < MotionGroup.LAST_COLUMN &&
|
||||
EditorHelper.getVisualLineLength(editor, visualLine + i) < repeatColumn) {
|
||||
final String pad = EditorHelper.pad(editor, logicalLine + i, repeatColumn);
|
||||
final String pad = EditorHelper.pad(editor, context, logicalLine + i, repeatColumn);
|
||||
if (pad.length() > 0) {
|
||||
final int offset = editor.getDocument().getLineEndOffset(logicalLine + i);
|
||||
caret.moveToOffset(offset);
|
||||
@ -1313,7 +1313,7 @@ public class ChangeGroup {
|
||||
|
||||
final int lineLength = EditorHelper.getLineLength(editor, line);
|
||||
if (column < MotionGroup.LAST_COLUMN && lineLength < column) {
|
||||
final String pad = EditorHelper.pad(editor, line, column);
|
||||
final String pad = EditorHelper.pad(editor, context, line, column);
|
||||
final int offset = editor.getDocument().getLineEndOffset(line);
|
||||
caret.moveToOffset(offset);
|
||||
insertText(editor, caret, pad);
|
||||
|
@ -316,7 +316,7 @@ public class CopyGroup {
|
||||
boolean indent) {
|
||||
final int endOffset = type != SelectionType.BLOCK_WISE
|
||||
? putTextInternal(editor, caret, text, startOffset, count)
|
||||
: putTextInternal(editor, caret, text, mode, startOffset, count);
|
||||
: putTextInternal(editor, caret, context, text, mode, startOffset, count);
|
||||
|
||||
if (indent) return doIndent(editor, caret, context, startOffset, endOffset);
|
||||
|
||||
@ -325,6 +325,7 @@ public class CopyGroup {
|
||||
|
||||
private int putTextInternal(@NotNull Editor editor,
|
||||
@NotNull Caret caret,
|
||||
@NotNull DataContext context,
|
||||
@NotNull String text,
|
||||
@NotNull CommandState.SubMode mode,
|
||||
int startOffset,
|
||||
@ -361,7 +362,7 @@ public class CopyGroup {
|
||||
}
|
||||
}
|
||||
|
||||
final String pad = EditorHelper.pad(editor, currentLine, currentColumn);
|
||||
final String pad = EditorHelper.pad(editor, context, currentLine, currentColumn);
|
||||
|
||||
final int insertOffset = editor.logicalPositionToOffset(new LogicalPosition(currentLine, currentColumn));
|
||||
MotionGroup.moveCaret(editor, caret, insertOffset);
|
||||
|
@ -18,12 +18,19 @@
|
||||
|
||||
package com.maddyhome.idea.vim.helper;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.maddyhome.idea.vim.common.CharacterPosition;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.handler.CaretOrder;
|
||||
@ -543,23 +550,38 @@ public class EditorHelper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String pad(@NotNull final Editor editor, int line, final int to) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
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 "";
|
||||
|
||||
int len = getLineLength(editor, line);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("line=" + line);
|
||||
logger.debug("len=" + len);
|
||||
logger.debug("to=" + to);
|
||||
final VirtualFile virtualFile = EditorData.getVirtualFile(editor);
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(context);
|
||||
final int tabSize;
|
||||
final boolean useTabs;
|
||||
if (virtualFile != null && project != null) {
|
||||
final FileType fileType = FileTypeManager.getInstance().getFileTypeByFile(virtualFile);
|
||||
final CodeStyleSettings settings = CodeStyle.getSettings(project);
|
||||
useTabs = settings.useTabCharacter(fileType);
|
||||
tabSize = settings.getTabSize(fileType);
|
||||
}
|
||||
if (len < to) {
|
||||
// TODO - use tabs as needed
|
||||
for (int i = len; i < to; i++) {
|
||||
res.append(' ');
|
||||
}
|
||||
else {
|
||||
tabSize = 8;
|
||||
useTabs = false;
|
||||
}
|
||||
|
||||
return res.toString();
|
||||
final int limit = to - len;
|
||||
final int tabsCnt;
|
||||
final int spacesCnt;
|
||||
if (useTabs) {
|
||||
tabsCnt = (limit) / tabSize;
|
||||
spacesCnt = (limit) % tabSize;
|
||||
}
|
||||
else {
|
||||
tabsCnt = 0;
|
||||
spacesCnt = limit;
|
||||
}
|
||||
|
||||
return StringUtil.repeat("\t", tabsCnt) + StringUtil.repeat(" ", spacesCnt);
|
||||
}
|
||||
|
||||
public static boolean canEdit(@NotNull final Project project, @NotNull final Editor editor) {
|
||||
|
Loading…
Reference in New Issue
Block a user