changedUpdate exception
[fedora-idea.git] / platform / platform-impl / src / com / intellij / openapi / editor / impl / PersistentRangeMarker.java
blob4ced1bef5de8757fa66f4efd573d299ae19ec94f
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.editor.impl;
18 import com.intellij.openapi.editor.event.DocumentEvent;
19 import com.intellij.openapi.editor.ex.DocumentEx;
20 import com.intellij.openapi.editor.impl.event.DocumentEventImpl;
22 /**
23 * @author max
25 public class PersistentRangeMarker extends RangeMarkerImpl {
26 private int myStartLine;
27 private int myStartColumn;
28 private int myEndLine;
29 private int myEndColumn;
31 public PersistentRangeMarker(DocumentEx document, int startOffset, int endOffset) {
32 super(document, startOffset, endOffset);
33 storeLinesAndCols();
36 private void storeLinesAndCols() {
37 // document might have been changed already
38 if (getStartOffset() < myDocument.getTextLength()) {
39 myStartLine = myDocument.getLineNumber(getStartOffset());
40 myStartColumn = getStartOffset() - myDocument.getLineStartOffset(myStartLine);
41 if (myStartColumn < 0) {
42 invalidate();
45 if (getEndOffset() < myDocument.getTextLength()) {
46 myEndLine = myDocument.getLineNumber(getEndOffset());
47 myEndColumn = getEndOffset() - myDocument.getLineStartOffset(myEndLine);
48 if (myEndColumn < 0) {
49 invalidate();
54 @Override
55 protected void changedUpdateImpl(DocumentEvent e) {
56 DocumentEventImpl event = (DocumentEventImpl)e;
57 if (event.isWholeTextReplaced()){
58 myStartLine = event.translateLineViaDiffStrict(myStartLine);
59 if (myStartLine < 0 || myStartLine >= getDocument().getLineCount()){
60 invalidate();
62 else{
63 myStart = getDocument().getLineStartOffset(myStartLine) + myStartColumn;
66 myEndLine = event.translateLineViaDiffStrict(myEndLine);
67 if (myEndLine < 0 || myEndLine >= getDocument().getLineCount()){
68 invalidate();
70 else{
71 myEnd = getDocument().getLineStartOffset(myEndLine) + myEndColumn;
74 else {
75 super.changedUpdateImpl(e);
76 if (isValid()){
77 storeLinesAndCols();
80 if (myEnd < myStart || myEnd > getDocument().getTextLength()) {
81 invalidate();