[terminal] IJPL-198429 Do not show read-only hint in the terminal

GitOrigin-RevId: 3d9133cf08a2ff266a96646167854ceef0342e63
This commit is contained in:
Konstantin Hudyakov
2025-07-24 11:31:46 +00:00
committed by intellij-monorepo-bot
parent e917045993
commit 05c98fc8d6
3 changed files with 17 additions and 4 deletions
+2
View File
@@ -232,6 +232,8 @@ com.intellij.openapi.actionSystem.ex.TooltipLinkProvider
- a:getTooltipLink(javax.swing.JComponent):com.intellij.openapi.actionSystem.ex.TooltipLinkProvider$TooltipLink
com.intellij.openapi.components.SettingsSavingComponent
- a:save():V
f:com.intellij.openapi.editor.EditorModificationUtil
- s:setShowReadOnlyHint(com.intellij.openapi.editor.Editor,Z):V
com.intellij.openapi.editor.actionSystem.ActionPlan
- a:getCaretOffset():I
- a:getText():com.intellij.util.text.ImmutableCharSequence
@@ -24,6 +24,7 @@ import java.util.Objects;
public final class EditorModificationUtil extends EditorModificationUtilEx {
private static final Key<ReadOnlyHint> READ_ONLY_VIEW_HINT_KEY = Key.create("READ_ONLY_VIEW_HINT_KEY");
private static final Key<Boolean> IGNORE_READ_ONLY_HINT_KEY = Key.create("IGNORE_READ_ONLY_HINT_KEY");
private EditorModificationUtil() { }
@@ -141,6 +142,9 @@ public final class EditorModificationUtil extends EditorModificationUtilEx {
if (!editor.isViewer()) return true;
if (ApplicationManager.getApplication().isHeadlessEnvironment() || editor instanceof TextComponentEditor) return false;
Boolean ignoreHint = IGNORE_READ_ONLY_HINT_KEY.get(editor);
if (ignoreHint == Boolean.TRUE) return false;
ReadOnlyHint hint = ObjectUtils.chooseNotNull(READ_ONLY_VIEW_HINT_KEY.get(editor), new ReadOnlyHint(EditorBundle.message("editing.viewer.hint"), null));
HintManager.getInstance().showInformationHint(editor, hint.message, hint.linkListener);
return false;
@@ -163,6 +167,14 @@ public final class EditorModificationUtil extends EditorModificationUtilEx {
editor.putUserData(READ_ONLY_VIEW_HINT_KEY, message != null ? new ReadOnlyHint(message, linkListener) : null);
}
/**
* @param shouldShow whether the read-only hint should be shown in the provided editor if it is in a view mode.
* By default, the hint is showing.
*/
public static void setShowReadOnlyHint(@NotNull Editor editor, boolean shouldShow) {
editor.putUserData(IGNORE_READ_ONLY_HINT_KEY, shouldShow ? null : true);
}
private record ReadOnlyHint(@NotNull @NlsContexts.HintText String message, @Nullable HyperlinkListener linkListener) {
}
}
@@ -15,10 +15,7 @@ import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.command.undo.UndoUtil
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.EditorKind
import com.intellij.openapi.editor.*
import com.intellij.openapi.editor.colors.EditorColorsListener
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.editor.colors.EditorFontType
@@ -105,6 +102,8 @@ object TerminalUiUtils {
val editor = EditorFactory.getInstance().createEditor(document, project, EditorKind.CONSOLE) as EditorImpl
editor.isScrollToCaret = false
editor.isRendererMode = true
EditorModificationUtil.setShowReadOnlyHint(editor, false)
editor.scrollPane.border = JBUI.Borders.empty()
editor.scrollPane.horizontalScrollBarPolicy = JScrollPane.HORIZONTAL_SCROLLBAR_NEVER
editor.gutterComponentEx.isPaintBackground = false