mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Markdown][IJPL-253568] Make the Markdown preview layout setting govern every editor
(cherry picked from commit 445bb72854646ef5db413fdf019402d1fe8f3fe8) IJ-CR-220760 GitOrigin-RevId: 399603c2abd08b7ae62b59cdfa6d6c9c598a3798
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a14c079dc6
commit
c1bb7e99e8
+21
@@ -6,9 +6,11 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.event.VisibleAreaEvent;
|
||||
import com.intellij.openapi.editor.event.VisibleAreaListener;
|
||||
import com.intellij.openapi.editor.impl.EditorImpl;
|
||||
import com.intellij.openapi.fileEditor.FileEditorState;
|
||||
import com.intellij.openapi.fileEditor.TextEditor;
|
||||
import com.intellij.openapi.fileEditor.TextEditorWithPreview;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.ui.JBSplitter;
|
||||
import org.intellij.plugins.markdown.MarkdownBundle;
|
||||
import org.intellij.plugins.markdown.settings.MarkdownSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -16,6 +18,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.awt.Point;
|
||||
|
||||
public final class MarkdownEditorWithPreview extends TextEditorWithPreview {
|
||||
private final MarkdownSettings settings;
|
||||
private boolean autoScrollPreview;
|
||||
|
||||
/**
|
||||
@@ -38,6 +41,8 @@ public final class MarkdownEditorWithPreview extends TextEditorWithPreview {
|
||||
!settings.isVerticalSplit()
|
||||
);
|
||||
|
||||
this.settings = settings;
|
||||
|
||||
// allow launching actions while in preview mode;
|
||||
// FIXME: better solution IDEA-354102
|
||||
editor.getEditor().getContentComponent().putClientProperty(ActionUtil.ALLOW_ACTION_PERFORM_WHEN_HIDDEN, true);
|
||||
@@ -64,6 +69,22 @@ public final class MarkdownEditorWithPreview extends TextEditorWithPreview {
|
||||
editor.getEditor().getScrollingModel().addVisibleAreaListener(new MyVisibleAreaListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull JBSplitter createSplitter() {
|
||||
JBSplitter splitter = super.createSplitter();
|
||||
// "Preview layout" must apply to a freshly created editor, not just to an already open one.
|
||||
splitter.setOrientation(!settings.isVerticalSplit());
|
||||
return splitter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(@NotNull FileEditorState state) {
|
||||
super.setState(state);
|
||||
// "Preview layout" is a global default, so it must win over the per-file orientation
|
||||
// that super.setState() restores from the editor state. See IJPL-253568.
|
||||
handleLayoutChange(!settings.isVerticalSplit());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayoutChange(Layout oldValue, Layout newValue) {
|
||||
super.onLayoutChange(oldValue, newValue);
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.intellij.plugins.markdown.ui.preview
|
||||
|
||||
import com.intellij.openapi.fileEditor.TextEditorWithPreview
|
||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.testFramework.fixtures.BasePlatformTestCase
|
||||
import com.intellij.ui.JBSplitter
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.intellij.plugins.markdown.settings.MarkdownSettings
|
||||
|
||||
/**
|
||||
* see IJPL-253568
|
||||
*/
|
||||
class MarkdownPreviewLayoutSettingTest : BasePlatformTestCase() {
|
||||
fun testSplitHorizontallySurvivesRestoredPerFileOrientation() {
|
||||
val settings = MarkdownSettings.getInstance(project)
|
||||
settings.update { it.isVerticalSplit = false }
|
||||
|
||||
val splitter = splitterOf(settings)
|
||||
assertTrue("setting must be applied to a freshly created editor", splitter.orientation)
|
||||
}
|
||||
|
||||
fun testRestoredStateDoesNotOverrideSetting() {
|
||||
val settings = MarkdownSettings.getInstance(project)
|
||||
settings.update { it.isVerticalSplit = false }
|
||||
|
||||
val editorWithPreview = createEditor(settings)
|
||||
val splitter = UIUtil.findComponentOfType(editorWithPreview.component, JBSplitter::class.java)!!
|
||||
|
||||
editorWithPreview.setState(
|
||||
TextEditorWithPreview.MyFileEditorState(TextEditorWithPreview.Layout.SHOW_EDITOR_AND_PREVIEW, null, null, false)
|
||||
)
|
||||
|
||||
assertTrue("global setting must win over restored per-file orientation", splitter.orientation)
|
||||
}
|
||||
|
||||
private fun splitterOf(settings: MarkdownSettings): JBSplitter =
|
||||
UIUtil.findComponentOfType(createEditor(settings).component, JBSplitter::class.java)!!
|
||||
|
||||
private fun createEditor(settings: MarkdownSettings): MarkdownEditorWithPreview {
|
||||
myFixture.configureByText("test.md", "# Heading\n\ntext\n")
|
||||
val file = myFixture.file.virtualFile
|
||||
val textEditor = TextEditorProvider.getInstance().getTextEditor(myFixture.editor)
|
||||
val preview = MarkdownPreviewFileEditor(project, file, myFixture.editor.document)
|
||||
val editorWithPreview = MarkdownEditorWithPreview(textEditor, preview, project, settings)
|
||||
Disposer.register(testRootDisposable, editorWithPreview)
|
||||
return editorWithPreview
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user