Ensure read only status when failing to change document text

GitOrigin-RevId: dccc9f59b04fcfa463c724ec348ad1a996de769c
This commit is contained in:
Bart van Helvert
2023-10-03 15:26:03 +02:00
committed by intellij-monorepo-bot
parent 4a821f078d
commit c3562acee9
4 changed files with 27 additions and 12 deletions

View File

@@ -124,8 +124,11 @@ public final class DocumentFragmentContent extends DiffContentBase implements Do
protected void onDocumentChanged1(@NotNull DocumentEvent event) {
if (!myRangeMarker.isValid()) {
myDocument2.setReadOnly(false);
replaceString(myDocument2, 0, myDocument2.getTextLength(), DiffBundle.message("synchronize.document.and.its.fragment.range.error"));
myDocument2.setReadOnly(true);
try {
replaceString(myDocument2, 0, myDocument2.getTextLength(), DiffBundle.message("synchronize.document.and.its.fragment.range.error"));
} finally {
myDocument2.setReadOnly(true);
}
return;
}
CharSequence newText = myDocument1.getCharsSequence().subSequence(myRangeMarker.getStartOffset(), myRangeMarker.getEndOffset());
@@ -156,8 +159,11 @@ public final class DocumentFragmentContent extends DiffContentBase implements Do
}
else {
myDocument2.setReadOnly(false);
myDocument2.setText(DiffBundle.message("synchronize.document.and.its.fragment.range.error"));
myDocument2.setReadOnly(true);
try {
myDocument2.setText(DiffBundle.message("synchronize.document.and.its.fragment.range.error"));
} finally {
myDocument2.setReadOnly(true);
}
}
});
});

View File

@@ -460,9 +460,11 @@ public final class ImplementationViewComponent extends JPanel {
DocumentUtil.writeInRunUndoTransparentAction(() -> {
Document fragmentDoc = myEditor.getDocument();
fragmentDoc.setReadOnly(false);
fragmentDoc.replaceString(0, fragmentDoc.getTextLength(), newText);
fragmentDoc.setReadOnly(true);
try {
fragmentDoc.replaceString(0, fragmentDoc.getTextLength(), newText);
} finally {
fragmentDoc.setReadOnly(true);
}
PsiElement element = elt.getElementForShowUsages();
PsiFile file = element == null ? null : element.getContainingFile();

View File

@@ -119,8 +119,12 @@ public class ByteCodeViewerComponent extends JPanel implements Disposable {
DocumentUtil.writeInRunUndoTransparentAction(() -> {
Document fragmentDoc = myEditor.getDocument();
fragmentDoc.setReadOnly(false);
fragmentDoc.replaceString(0, fragmentDoc.getTextLength(), bytecode);
fragmentDoc.setReadOnly(true);
try {
fragmentDoc.replaceString(0, fragmentDoc.getTextLength(), bytecode);
} finally {
fragmentDoc.setReadOnly(true);
}
myEditor.getCaretModel().moveToOffset(offset);
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
});

View File

@@ -181,10 +181,13 @@ class PsiViewerDebugPanel(
DebuggerUIUtil.invokeLater {
expressionRange = psiRangeInFile
editor.document.setReadOnly(false)
runWriteAction {
editor.document.setText(fileText)
try {
runWriteAction {
editor.document.setText(fileText)
}
} finally {
editor.document.setReadOnly(true)
}
editor.document.setReadOnly(true)
editor.selectAndScroll(psiRangeInFile)
}
}