IDEA-58625 Exception on paste

Defined prioritized document listeners order in one place
This commit is contained in:
Denis Zhdanov
2010-09-13 15:04:55 +04:00
parent 2e215cf251
commit 1e737c8d8b
9 changed files with 93 additions and 12 deletions
@@ -28,6 +28,7 @@ import com.intellij.openapi.editor.ex.PrioritizedDocumentListener;
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.editor.highlighter.HighlighterClient;
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
import com.intellij.openapi.editor.impl.EditorDocumentPriorities;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileTypes.PlainSyntaxHighlighter;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
@@ -264,7 +265,7 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc
}
public int getPriority() {
return 2;
return EditorDocumentPriorities.LEXER_EDITOR;
}
private static boolean segmentsEqual(SegmentArrayWithData a1, int idx1, SegmentArrayWithData a2, int idx2, final int offsetShift) {
@@ -512,7 +512,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
}
public int getPriority() {
return 3;
return EditorDocumentPriorities.CARET_MODEL;
}
private void setCurrentLogicalCaret(LogicalPosition position) {
@@ -0,0 +1,44 @@
/*
* Copyright 2000-2010 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.intellij.openapi.editor.impl;
import com.intellij.openapi.editor.ex.PrioritizedDocumentListener;
/**
* Holds values to use for common {@link PrioritizedDocumentListener prioritized document listeners} used within standard IntelliJ
* editor.
*
* @author Denis Zhdanov
* @since Sep 13, 2010 2:30:48 PM
*/
public class EditorDocumentPriorities {
public static final int SOFT_WRAP_MODEL = 40;
/**
* Assuming that range marker listeners work only with document offsets and don't perform document dimension mappings like
* {@code 'logical position -> visual position'}, {@code 'offset -> logical position'} etc.
*/
public static final int RANGE_MARKER = 60;
public static final int FOLD_MODEL = 80;
public static final int LEXER_EDITOR = 100;
public static final int CARET_MODEL = 120;
public static final int SELECTION_MODEL = 140;
public static final int EDITOR_DOCUMENT_ADAPTER = 160;
private EditorDocumentPriorities() {
}
}
@@ -4804,7 +4804,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
}
public int getPriority() {
return 5;
return EditorDocumentPriorities.EDITOR_DOCUMENT_ADAPTER;
}
}
@@ -437,7 +437,7 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedDocumentList
}
public int getPriority() {
return 1;
return EditorDocumentPriorities.FOLD_MODEL;
}
public FoldRegion createFoldRegion(int startOffset, int endOffset, @NotNull String placeholder, FoldingGroup group) {
@@ -55,7 +55,7 @@ public class RangeMarkerTree<T extends RangeMarkerEx> extends IntervalTreeImpl<T
document.addDocumentListener(new PrioritizedDocumentListener() {
public int getPriority() {
return 0; // Need to make sure we invalidate all the stuff before someone (like LineStatusTracker) starts to modify highlights.
return EditorDocumentPriorities.RANGE_MARKER; // Need to make sure we invalidate all the stuff before someone (like LineStatusTracker) starts to modify highlights.
}
public void beforeDocumentChange(DocumentEvent event) {}
@@ -120,7 +120,7 @@ public class SelectionModelImpl implements SelectionModel, PrioritizedDocumentLi
}
public int getPriority() {
return 4;
return EditorDocumentPriorities.SELECTION_MODEL;
}
public SelectionModelImpl(EditorImpl editor) {
@@ -45,7 +45,7 @@ import java.util.List;
* @author Denis Zhdanov
* @since Jun 8, 2010 12:47:32 PM
*/
public class SoftWrapModelImpl implements SoftWrapModelEx, DocumentListener {
public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentListener {
/** Upper boundary of time interval to check editor settings. */
private static final long EDITOR_SETTINGS_CHECK_PERIOD_MILLIS = 10000;
@@ -414,6 +414,11 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, DocumentListener {
return myStorage.addSoftWrapChangeListener(listener);
}
@Override
public int getPriority() {
return EditorDocumentPriorities.SOFT_WRAP_MODEL;
}
@Override
public void beforeDocumentChange(DocumentEvent event) {
if (!isSoftWrappingEnabled()) {
@@ -380,6 +380,34 @@ public class CachingSoftWrapDataMapper implements SoftWrapDataMapper, SoftWrapAw
entry.locked = false;
}
applyStateChange();
//Document document = myEditor.getDocument();
//CharSequence text = document.getCharsSequence();
//System.out.println("--------------------------------------------------");
//System.out.println("|");
//System.out.println("|");
//System.out.println(text);
//System.out.println("- - - - - - - - - - - - - - - - - -");
//System.out.println("text length: " + text.length() + ", soft wraps: " + myStorage.getSoftWraps());
//for (int i = 0; i < myCache.size(); i++) {
// CacheEntry entry = myCache.get(i);
// System.out.printf("line %d. %d-%d: '%s'%n", i, entry.startOffset, entry.endOffset,
// text.subSequence(entry.startOffset,Math.min(entry.endOffset, text.length())));
//}
//
//for (CacheEntry cacheEntry : myCache) {
// if (cacheEntry.startOffset > 0) {
// if (text.charAt(cacheEntry.startOffset - 1) != '\n' && myStorage.getSoftWrap(cacheEntry.startOffset) == null) {
// assert false;
// }
// }
// if (cacheEntry.endOffset < document.getTextLength()) {
// if (text.charAt(cacheEntry.endOffset) != '\n' && myStorage.getSoftWrap(cacheEntry.endOffset) == null) {
// assert false;
// }
// }
//}
}
/**
@@ -405,9 +433,11 @@ public class CachingSoftWrapDataMapper implements SoftWrapDataMapper, SoftWrapAw
int offsetsDiff = (myAfterChangeState.endOffset - myAfterChangeState.startOffset)
- (myBeforeChangeState.endOffset - myBeforeChangeState.startOffset);
int cacheIndex = myAfterChangeState.endCacheEntryIndex;
for (int i = cacheIndex + 1; i < myCache.size(); i++) {
CacheEntry cacheEntry = myCache.get(i);
if (myNotAffectedByUpdateTailCacheEntries.isEmpty()) {
return;
}
for (CacheEntry cacheEntry : myNotAffectedByUpdateTailCacheEntries) {
cacheEntry.visualLine += visualLinesDiff;
cacheEntry.startLogicalLine += logicalLinesDiff;
cacheEntry.endLogicalLine += logicalLinesDiff;
@@ -418,11 +448,12 @@ public class CachingSoftWrapDataMapper implements SoftWrapDataMapper, SoftWrapAw
cacheEntry.endFoldedLines += foldedLinesDiff;
}
if (offsetsDiff == 0) {
int offset = myNotAffectedByUpdateTailCacheEntries.get(0).startOffset + 1/* in order to exclude soft wrap from previous line if any*/;
if (offsetsDiff == 0 || offset >= myEditor.getDocument().getTextLength()) {
return;
}
int softWrapIndex = myStorage.getSoftWrapIndex(myCache.get(cacheIndex).startOffset);
int softWrapIndex = myStorage.getSoftWrapIndex(offset);
if (softWrapIndex < 0) {
softWrapIndex = -softWrapIndex - 1;
}