mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-96747 Database console history does not work as expected
This commit is contained in:
+13
-20
@@ -30,6 +30,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.actions.ContentChooser;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
|
||||
@@ -39,7 +40,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ex.ProjectEx;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.CharFilter;
|
||||
import com.intellij.openapi.util.text.StringHash;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
@@ -195,6 +195,7 @@ public class ConsoleHistoryController {
|
||||
}
|
||||
|
||||
protected void setConsoleText(final String command, final boolean storeUserText, final boolean regularMode) {
|
||||
if (regularMode && myMultiline && StringUtil.isEmptyOrSpaces(command)) return;
|
||||
final Editor editor = myConsole.getCurrentEditor();
|
||||
final Document document = editor.getDocument();
|
||||
new WriteCommandAction.Simple(myConsole.getProject()) {
|
||||
@@ -207,25 +208,7 @@ public class ConsoleHistoryController {
|
||||
int offset;
|
||||
if (regularMode) {
|
||||
if (myMultiline) {
|
||||
if (text.isEmpty()) return;
|
||||
int selectionStart = editor.getSelectionModel().getSelectionStart();
|
||||
int selectionEnd = editor.getSelectionModel().getSelectionEnd();
|
||||
int caretOffset = editor.getCaretModel().getOffset();
|
||||
int line = document.getLineNumber(caretOffset);
|
||||
int lineStartOffset = document.getLineStartOffset(line);
|
||||
if (selectionStart == lineStartOffset) document.deleteString(selectionStart, selectionEnd);
|
||||
String trimmedLine = document.getText(new TextRange(lineStartOffset, document.getLineEndOffset(line))).trim();
|
||||
if (StringUtil.findFirst(trimmedLine, new CharFilter() {
|
||||
@Override
|
||||
public boolean accept(char ch) {
|
||||
return ch == '\'' || ch == '\"' || ch == '_' || Character.isLetterOrDigit(ch);
|
||||
}
|
||||
}) > -1) {
|
||||
text += "\n";
|
||||
}
|
||||
document.insertString(lineStartOffset, text);
|
||||
offset = lineStartOffset;
|
||||
editor.getSelectionModel().setSelection(lineStartOffset, lineStartOffset + text.length());
|
||||
offset = insertTextMultiline(text, editor, document);
|
||||
}
|
||||
else {
|
||||
document.setText(text);
|
||||
@@ -248,6 +231,16 @@ public class ConsoleHistoryController {
|
||||
}.execute();
|
||||
}
|
||||
|
||||
protected int insertTextMultiline(String text, Editor editor, Document document) {
|
||||
TextRange selection = EditorUtil.getSelectionInAnyMode(editor);
|
||||
|
||||
int start = document.getLineStartOffset(document.getLineNumber(selection.getStartOffset()));
|
||||
int end = document.getLineEndOffset(document.getLineNumber(selection.getEndOffset()));
|
||||
|
||||
document.replaceString(start, end, text);
|
||||
editor.getSelectionModel().setSelection(start, start + text.length());
|
||||
return start;
|
||||
}
|
||||
|
||||
private class MyAction extends AnAction {
|
||||
private boolean myNext;
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.intellij.openapi.editor.impl.FontInfo;
|
||||
import com.intellij.openapi.editor.impl.IterationState;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.intellij.lang.annotations.JdkConstants;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -768,6 +769,16 @@ public class EditorUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TextRange getSelectionInAnyMode(Editor editor) {
|
||||
SelectionModel selection = editor.getSelectionModel();
|
||||
int[] starts = selection.getBlockSelectionStarts();
|
||||
int[] ends = selection.getBlockSelectionEnds();
|
||||
int start = starts.length > 0 ? starts[0] : selection.getSelectionStart();
|
||||
int end = ends.length > 0 ? ends[ends.length - 1] : selection.getSelectionEnd();
|
||||
return TextRange.create(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user