Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NETBEANS-977] Improve text layout in word wrap mode.
This squashed commit combines the following commits that were seen in the original pull request: 1) Improve text layout in word wrap mode. 2) Refactor EditorCaret to avoid repeated code for getting the JViewport. 3) Fix scrollRectToVisible behavior for the improved text wrap layout. 4) Modify the word wrapping policy slightly to allow at most one whitespace character to trail the preferred wrap width. This avoids having to paint the caret outside the wrapped editor viewport. 5) Improve text caret behavior when typing at the end of a wrapped paragraph. Manually fixed merge conflict in DocumentViewOp (due to combination of rename and another bugfix in the same file).
- Loading branch information
1 parent
acd11c8
commit 7364449
Showing
7 changed files
with
608 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/CharSequenceCharacterIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.netbeans.modules.editor.lib2.view; | ||
|
||
import java.text.CharacterIterator; | ||
|
||
/* This class was written from scratch. I considered using org.apache.pivot.text.CharacterIterator | ||
from the Apache Pivot project, but it had bugs in the next() and previous() methods (trying to use | ||
CharacterIterator.DONE = 65535 as an index). */ | ||
/** | ||
* Adapter class for providing a {@link CharacterIterator} over a {@link CharSequence} without | ||
* making a copy of the entire underlying string. | ||
* | ||
* @author Eirik Bakke (ebakke@ultorg.com) | ||
*/ | ||
class CharSequenceCharacterIterator implements CharacterIterator { | ||
private final CharSequence charSequence; | ||
private int index; | ||
|
||
public CharSequenceCharacterIterator(CharSequence charSequence) { | ||
if (charSequence == null) | ||
throw new NullPointerException(); | ||
this.charSequence = charSequence; | ||
} | ||
|
||
@Override | ||
public int getIndex() { | ||
return index; | ||
} | ||
|
||
@Override | ||
public char setIndex(int position) { | ||
if (position < getBeginIndex() || position > getEndIndex()) | ||
throw new IllegalArgumentException(); | ||
this.index = position; | ||
return current(); | ||
} | ||
|
||
@Override | ||
public char current() { | ||
return index == getEndIndex() ? CharacterIterator.DONE : charSequence.charAt(index); | ||
} | ||
|
||
@Override | ||
public char first() { | ||
return setIndex(getBeginIndex()); | ||
} | ||
|
||
@Override | ||
public char last() { | ||
final int endIndex = getEndIndex(); | ||
return setIndex(charSequence.length() == 0 ? endIndex : (endIndex - 1)); | ||
} | ||
|
||
@Override | ||
public char next() { | ||
if (index < getEndIndex()) | ||
index++; | ||
return current(); | ||
} | ||
|
||
@Override | ||
public char previous() { | ||
if (index > getBeginIndex()) { | ||
index--; | ||
return current(); | ||
} else { | ||
return CharacterIterator.DONE; | ||
} | ||
} | ||
|
||
@Override | ||
public int getBeginIndex() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getEndIndex() { | ||
return charSequence.length(); | ||
} | ||
|
||
@Override | ||
public Object clone() { | ||
CharacterIterator ret = new CharSequenceCharacterIterator(charSequence); | ||
ret.setIndex(index); | ||
return ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.