IDEA-181188, IDEA-206087 Freeze on pasting a very long line

GitOrigin-RevId: 7c57fa565acd1375b29f30a2a662686cf2a41e01
This commit is contained in:
Dmitry Batrak
2020-06-03 19:01:43 +03:00
committed by intellij-monorepo-bot
parent 233ac79ccc
commit 4f41d47558
3 changed files with 55 additions and 20 deletions
@@ -129,7 +129,7 @@ public class SetEditorSettingsAction extends ActionGroup implements DumbAware {
public void applyDefaults(@NotNull List<? extends Editor> editors) {
if (!myTextSettings.isUseSoftWraps()) {
for (Editor editor : editors) {
myForcedSoftWrap = myForcedSoftWrap || ((EditorImpl)editor).shouldSoftWrapsBeForced();
myForcedSoftWrap = myForcedSoftWrap || ((EditorImpl)editor).getSoftWrapModel().shouldSoftWrapsBeForced();
}
}
super.applyDefaults(editors);
@@ -350,10 +350,6 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
myIsViewer = viewer;
myKind = kind;
mySettings = new SettingsImpl(this, kind);
if (!mySettings.isUseSoftWraps() && shouldSoftWrapsBeForced()) {
mySettings.setUseSoftWrapsQuiet();
putUserData(FORCED_SOFT_WRAPS, Boolean.TRUE);
}
MarkupModelEx documentMarkup = (MarkupModelEx)DocumentMarkupModel.forDocument(myDocument, myProject, true);
@@ -731,20 +727,6 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
return !myBackgroundImageSet && !Registry.is("editor.transparent.scrollbar");
}
public boolean shouldSoftWrapsBeForced() {
if (myProject != null && PsiDocumentManager.getInstance(myProject).isDocumentBlockedByPsi(myDocument)) {
// Disable checking for files in intermediate states - e.g. for files during refactoring.
return false;
}
int lineWidthLimit = Registry.intValue("editor.soft.wrap.force.limit");
for (int i = 0; i < myDocument.getLineCount(); i++) {
if (myDocument.getLineEndOffset(i) - myDocument.getLineStartOffset(i) > lineWidthLimit) {
return true;
}
}
return false;
}
@NotNull
static Color adjustThumbColor(@NotNull Color base, boolean dark) {
return dark ? ColorUtil.withAlpha(ColorUtil.shift(base, 1.35), 0.5)
@@ -15,8 +15,13 @@ import com.intellij.openapi.editor.impl.softwrap.*;
import com.intellij.openapi.editor.impl.softwrap.mapping.CachingSoftWrapDataMapper;
import com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapApplianceManager;
import com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapAwareDocumentParsingListenerAdapter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Segment;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.ui.EditorNotifications;
import com.intellij.util.DocumentEventUtil;
import com.intellij.util.DocumentUtil;
import com.intellij.util.containers.ContainerUtil;
@@ -118,6 +123,11 @@ public class SoftWrapModelImpl extends InlayModel.SimpleAdapter
}
}
});
if (!editor.getSettings().isUseSoftWraps() && shouldSoftWrapsBeForced()) {
forceSoftWraps();
}
myUseSoftWraps = areSoftWrapsEnabledInEditor();
myEditor.getColorsScheme().getFontPreferences().copyTo(myFontPreferences);
@@ -127,6 +137,39 @@ public class SoftWrapModelImpl extends InlayModel.SimpleAdapter
myEditor.getInlayModel().addListener(this, this);
}
private void forceSoftWraps() {
((SettingsImpl)myEditor.getSettings()).setUseSoftWrapsQuiet();
myEditor.putUserData(EditorImpl.FORCED_SOFT_WRAPS, Boolean.TRUE);
myUseSoftWraps = areSoftWrapsEnabledInEditor();
Project project = myEditor.getProject();
VirtualFile file = myEditor.getVirtualFile();
if (project != null && file != null) {
EditorNotifications.getInstance(project).updateNotifications(file);
}
}
public boolean shouldSoftWrapsBeForced() {
return shouldSoftWrapsBeForced(null);
}
private boolean shouldSoftWrapsBeForced(@Nullable DocumentEvent event) {
Project project = myEditor.getProject();
Document document = myEditor.getDocument();
if (project != null && PsiDocumentManager.getInstance(project).isDocumentBlockedByPsi(document)) {
// Disable checking for files in intermediate states - e.g. for files during refactoring.
return false;
}
int lineWidthLimit = Registry.intValue("editor.soft.wrap.force.limit");
int startLine = event == null ? 0 : document.getLineNumber(event.getOffset());
int endLine = event == null ? document.getLineCount() - 1 : document.getLineNumber(event.getOffset() + event.getNewLength());
for (int i = startLine; i <= endLine; i++) {
if (document.getLineEndOffset(i) - document.getLineStartOffset(i) > lineWidthLimit) {
return true;
}
}
return false;
}
private boolean areSoftWrapsEnabledInEditor() {
return myEditor.getSettings().isUseSoftWraps() && !myEditor.isOneLineMode();
}
@@ -418,7 +461,13 @@ public class SoftWrapModelImpl extends InlayModel.SimpleAdapter
}
myUpdateInProgress = false;
if (!isSoftWrappingEnabled()) {
myDirty = true;
if (shouldSoftWrapsBeForced(event)) {
forceSoftWraps();
recalculate();
}
else {
myDirty = true;
}
return;
}
myApplianceManager.documentChanged(event, myAfterLineEndInlayUpdated);
@@ -438,6 +487,9 @@ public class SoftWrapModelImpl extends InlayModel.SimpleAdapter
void onBulkDocumentUpdateFinished() {
myBulkUpdateInProgress = false;
if (!myUseSoftWraps && shouldSoftWrapsBeForced()) {
forceSoftWraps();
}
recalculate();
}
@@ -532,6 +584,7 @@ public class SoftWrapModelImpl extends InlayModel.SimpleAdapter
myDirty = true;
return;
}
myDirty = false;
myApplianceManager.reset();
myStorage.removeAll();
myDeferredFoldRegions.clear();