move ConsoleHistoryCopyHandler to platform

GitOrigin-RevId: 357ba3ca7444ae97f91c83585680c0f32ac9b877
This commit is contained in:
Vladimir Koshelev
2019-07-04 01:31:35 +03:00
committed by intellij-monorepo-bot
parent dbc05e8224
commit 021f76c90a
3 changed files with 29 additions and 29 deletions
@@ -1,19 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.python.console
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.console
import com.intellij.execution.impl.ConsoleViewUtil
import com.intellij.openapi.actionSystem.DataContext
@@ -27,11 +13,13 @@ import com.intellij.openapi.util.Key
import com.intellij.openapi.util.Ref
import com.intellij.openapi.util.TextRange
import java.awt.datatransfer.StringSelection
import kotlin.math.max
import kotlin.math.min
/**
* Created by Yuli Fiterman on 9/17/2016.
*/
class PyConsoleCopyHandler(val originalHandler: EditorActionHandler) : EditorActionHandler() {
class ConsoleHistoryCopyHandler(val originalHandler: EditorActionHandler) : EditorActionHandler() {
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext) {
if (!RichCopySettings.getInstance().isEnabled) {
@@ -62,8 +50,8 @@ class PyConsoleCopyHandler(val originalHandler: EditorActionHandler) : EditorAct
if (!r.isNull) {
lineStart += r.get()
}
val rangeStart = Math.max(lineStart, start)
val rangeEnd = Math.min(document.getLineEndOffset(i), end)
val rangeStart = max(lineStart, start)
val rangeEnd = min(document.getLineEndOffset(i), end)
if (rangeStart < rangeEnd) {
sb.append(document.getText(TextRange(rangeStart, rangeEnd)))
if (rangeEnd < end) {
@@ -71,14 +59,13 @@ class PyConsoleCopyHandler(val originalHandler: EditorActionHandler) : EditorAct
}
}
}
if (!sb.isEmpty()) {
if (sb.isNotEmpty()) {
CopyPasteManager.getInstance().setContents(StringSelection(sb.toString()))
}
}
companion object {
@JvmField
val PROMPT_LENGTH_MARKER: Key<Int?> = Key.create<Int>("PROMPT_LENGTH_MARKER");
val PROMPT_LENGTH_MARKER: Key<Int?> = Key.create<Int>("PROMPT_LENGTH_MARKER")
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.console;
import com.intellij.execution.impl.ConsoleViewImpl;
@@ -17,11 +17,14 @@ import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.event.DocumentListener;
import com.intellij.openapi.editor.ex.DocumentEx;
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.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.editor.impl.EditorFactoryImpl;
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
@@ -311,10 +314,10 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons
LanguageConsoleImpl consoleImpl = (LanguageConsoleImpl)console;
consoleImpl.doAddPromptToHistory();
if (syntax != null) {
String identPrompt = consoleImpl.myConsoleExecutionEditor.getConsolePromptDecorator().getIndentPrompt();
ConsoleViewUtil.printWithHighlighting(console, text, syntax, () -> {
String identPrompt = consoleImpl.myConsoleExecutionEditor.getConsolePromptDecorator().getIndentPrompt();
if (StringUtil.isNotEmpty(identPrompt)) {
consoleImpl.print(identPrompt, consoleImpl.myConsoleExecutionEditor.getPromptAttributes());
consoleImpl.addPromptToHistoryImpl(identPrompt);
}
});
}
@@ -338,12 +341,12 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons
}
protected void doAddPromptToHistory() {
if (myConsoleExecutionEditor.getPrompt() != null) {
print(myConsoleExecutionEditor.getPrompt(), myConsoleExecutionEditor.getPromptAttributes());
String prompt = myConsoleExecutionEditor.getPrompt();
if (prompt != null) {
addPromptToHistoryImpl(prompt);
}
}
//private static void duplicateHighlighters(@NotNull MarkupModel to, @NotNull MarkupModel from, int offset, @NotNull TextRange textRange) {
// for (RangeHighlighter rangeHighlighter : from.getAllHighlighters()) {
// if (!rangeHighlighter.isValid()) {
@@ -433,6 +436,15 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons
return 2;
}
private void addPromptToHistoryImpl(@NotNull String prompt) {
DocumentEx document = getHistoryViewer().getDocument();
RangeHighlighter highlighter =
this.getHistoryViewer().getMarkupModel().addRangeHighlighter(document.getTextLength(), document.getTextLength(), 0,
null, HighlighterTargetArea.EXACT_RANGE);
print(prompt, myConsoleExecutionEditor.getPromptAttributes());
highlighter.putUserData(ConsoleHistoryCopyHandler.PROMPT_LENGTH_MARKER, prompt.length());
}
public static class Helper {
public final Project project;
public final VirtualFile virtualFile;
+2 -1
View File
@@ -52,7 +52,8 @@
<enterHandlerDelegate implementation="com.jetbrains.python.editor.PythonEnterHandler"/>
<enterHandlerDelegate implementation="com.jetbrains.python.editor.PyEnterAtIndentHandler" order="first"/>
<enterBetweenBracesDelegate language="Python" implementationClass="com.intellij.codeInsight.editorActions.enter.EnterBetweenBracesAndBracketsDelegate"/>
<editorActionHandler action="EditorCopy" implementationClass="com.jetbrains.python.console.PyConsoleCopyHandler"/>
<!--suppress PluginXmlValidity -->
<editorActionHandler action="EditorCopy" implementationClass="com.intellij.execution.console.ConsoleHistoryCopyHandler"/>
<editor.backspaceModeOverride language="Python" implementationClass="com.intellij.codeInsight.editorActions.SmartBackspaceDisabler"/>
<sdkType implementation="com.jetbrains.python.sdk.PythonSdkType"/>