mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
selection refactoring
This commit is contained in:
parent
95d78d3c6d
commit
4a98faa9b5
9 changed files with 213 additions and 129 deletions
|
@ -49,4 +49,13 @@ final class ZLTextElementArea extends ZLTextFixedPosition {
|
||||||
boolean contains(int x, int y) {
|
boolean contains(int x, int y) {
|
||||||
return (y >= YStart) && (y <= YEnd) && (x >= XStart) && (x <= XEnd);
|
return (y >= YStart) && (y <= YEnd) && (x >= XStart) && (x <= XEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isFirstInElement() {
|
||||||
|
return CharIndex == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isLastInElement() {
|
||||||
|
// TODO: support multi-part (> 2 part) words
|
||||||
|
return !(Element instanceof ZLTextWord) || CharIndex > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,11 +43,11 @@ final class ZLTextElementAreaVector extends ArrayList<ZLTextElementArea> {
|
||||||
ZLTextRegion.Soul soul = null;
|
ZLTextRegion.Soul soul = null;
|
||||||
final ZLTextHyperlink hyperlink = area.Style.Hyperlink;
|
final ZLTextHyperlink hyperlink = area.Style.Hyperlink;
|
||||||
if (hyperlink.Id != null) {
|
if (hyperlink.Id != null) {
|
||||||
soul = new ZLTextHyperlinkRegionSoul(hyperlink);
|
soul = new ZLTextHyperlinkRegionSoul(area, hyperlink);
|
||||||
} else if (area.Element instanceof ZLTextImageElement) {
|
} else if (area.Element instanceof ZLTextImageElement) {
|
||||||
soul = new ZLTextImageRegionSoul((ZLTextImageElement)area.Element);
|
soul = new ZLTextImageRegionSoul(area, (ZLTextImageElement)area.Element);
|
||||||
} else if (area.Element instanceof ZLTextWord && ((ZLTextWord)area.Element).isAWord()) {
|
} else if (area.Element instanceof ZLTextWord && ((ZLTextWord)area.Element).isAWord()) {
|
||||||
soul = new ZLTextWordRegionSoul((ZLTextWord)area.Element);
|
soul = new ZLTextWordRegionSoul(area, (ZLTextWord)area.Element);
|
||||||
}
|
}
|
||||||
if (soul != null) {
|
if (soul != null) {
|
||||||
myCurrentElementRegion = new ZLTextRegion(soul, this, size());
|
myCurrentElementRegion = new ZLTextRegion(soul, this, size());
|
||||||
|
|
|
@ -22,20 +22,9 @@ package org.geometerplus.zlibrary.text.view;
|
||||||
public class ZLTextHyperlinkRegionSoul extends ZLTextRegion.Soul {
|
public class ZLTextHyperlinkRegionSoul extends ZLTextRegion.Soul {
|
||||||
public final ZLTextHyperlink Hyperlink;
|
public final ZLTextHyperlink Hyperlink;
|
||||||
|
|
||||||
ZLTextHyperlinkRegionSoul(ZLTextHyperlink hyperlink) {
|
ZLTextHyperlinkRegionSoul(ZLTextPosition position, ZLTextHyperlink hyperlink) {
|
||||||
|
// TODO: fix this call
|
||||||
|
super(position.getParagraphIndex(), position.getElementIndex(), position.getElementIndex());
|
||||||
Hyperlink = hyperlink;
|
Hyperlink = hyperlink;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
boolean accepts(ZLTextElementArea area) {
|
|
||||||
return Hyperlink == area.Style.Hyperlink;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
if (!(other instanceof ZLTextHyperlinkRegionSoul)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return Hyperlink == ((ZLTextHyperlinkRegionSoul)other).Hyperlink;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,20 +22,8 @@ package org.geometerplus.zlibrary.text.view;
|
||||||
public class ZLTextImageRegionSoul extends ZLTextRegion.Soul {
|
public class ZLTextImageRegionSoul extends ZLTextRegion.Soul {
|
||||||
public final ZLTextImageElement ImageElement;
|
public final ZLTextImageElement ImageElement;
|
||||||
|
|
||||||
ZLTextImageRegionSoul(ZLTextImageElement imageElement) {
|
ZLTextImageRegionSoul(ZLTextPosition position, ZLTextImageElement imageElement) {
|
||||||
|
super(position.getParagraphIndex(), position.getElementIndex(), position.getElementIndex());
|
||||||
ImageElement = imageElement;
|
ImageElement = imageElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
boolean accepts(ZLTextElementArea area) {
|
|
||||||
return ImageElement == area.Element;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
if (!(other instanceof ZLTextImageRegionSoul)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return ImageElement == ((ZLTextImageRegionSoul)other).ImageElement;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,23 +53,6 @@ public abstract class ZLTextPosition implements Comparable<ZLTextPosition> {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignores character index
|
|
||||||
int weakCompareTo(ZLTextPosition position) {
|
|
||||||
final int p0 = getParagraphIndex();
|
|
||||||
final int p1 = position.getParagraphIndex();
|
|
||||||
if (p0 != p1) {
|
|
||||||
return p0 < p1 ? -1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int e0 = getElementIndex();
|
|
||||||
final int e1 = position.getElementIndex();
|
|
||||||
if (e0 != e1) {
|
|
||||||
return e0 < e1 ? -1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (getParagraphIndex() << 16) + (getElementIndex() << 8) + getCharIndex();
|
return (getParagraphIndex() << 16) + (getElementIndex() << 8) + getCharIndex();
|
||||||
|
|
|
@ -23,12 +23,62 @@ import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||||
|
|
||||||
public final class ZLTextRegion implements Comparable<ZLTextRegion> {
|
public final class ZLTextRegion /*implements Comparable<ZLTextRegion>*/ {
|
||||||
public static abstract class Soul {
|
public static abstract class Soul implements Comparable<Soul> {
|
||||||
abstract boolean accepts(ZLTextElementArea area);
|
final int ParagraphIndex;
|
||||||
|
final int StartElementIndex;
|
||||||
|
final int EndElementIndex;
|
||||||
|
|
||||||
|
protected Soul(int paragraphIndex, int startElementIndex, int endElementIndex) {
|
||||||
|
ParagraphIndex = paragraphIndex;
|
||||||
|
StartElementIndex = startElementIndex;
|
||||||
|
EndElementIndex = endElementIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean accepts(ZLTextElementArea area) {
|
||||||
|
return compareTo(area) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean equals(Object other);
|
public final boolean equals(Object other) {
|
||||||
|
if (other == this) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(other instanceof Soul)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final Soul soul = (Soul)other;
|
||||||
|
return
|
||||||
|
ParagraphIndex == soul.ParagraphIndex &&
|
||||||
|
StartElementIndex == soul.StartElementIndex &&
|
||||||
|
EndElementIndex == soul.EndElementIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int compareTo(Soul soul) {
|
||||||
|
if (ParagraphIndex != soul.ParagraphIndex) {
|
||||||
|
return ParagraphIndex < soul.ParagraphIndex ? -1 : 1;
|
||||||
|
}
|
||||||
|
if (EndElementIndex < soul.StartElementIndex) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (StartElementIndex > soul.EndElementIndex) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int compareTo(ZLTextElementArea area) {
|
||||||
|
if (ParagraphIndex != area.ParagraphIndex) {
|
||||||
|
return ParagraphIndex < area.ParagraphIndex ? -1 : 1;
|
||||||
|
}
|
||||||
|
if (EndElementIndex < area.ElementIndex) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (StartElementIndex > area.ElementIndex) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface Filter {
|
public static interface Filter {
|
||||||
|
@ -155,6 +205,7 @@ public final class ZLTextRegion implements Comparable<ZLTextRegion> {
|
||||||
return other == null || other.isExactlyUnder(this);
|
return other == null || other.isExactlyUnder(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public int compareTo(ZLTextRegion other) {
|
public int compareTo(ZLTextRegion other) {
|
||||||
if (myFromIndex != other.myFromIndex) {
|
if (myFromIndex != other.myFromIndex) {
|
||||||
return myFromIndex < other.myFromIndex ? -1 : 1;
|
return myFromIndex < other.myFromIndex ? -1 : 1;
|
||||||
|
@ -164,4 +215,5 @@ public final class ZLTextRegion implements Comparable<ZLTextRegion> {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ package org.geometerplus.zlibrary.text.view;
|
||||||
public class ZLTextSelection {
|
public class ZLTextSelection {
|
||||||
private final ZLTextView myView;
|
private final ZLTextView myView;
|
||||||
|
|
||||||
private ZLTextRegion myLeftMostRegion;
|
private ZLTextRegion.Soul myLeftMostRegionSoul;
|
||||||
private ZLTextRegion myRightMostRegion;
|
private ZLTextRegion.Soul myRightMostRegionSoul;
|
||||||
|
|
||||||
private Scroller myScroller;
|
private Scroller myScroller;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class ZLTextSelection {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isEmpty() {
|
boolean isEmpty() {
|
||||||
return myLeftMostRegion == null;
|
return myLeftMostRegionSoul == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean clear() {
|
boolean clear() {
|
||||||
|
@ -41,22 +41,22 @@ public class ZLTextSelection {
|
||||||
}
|
}
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
myLeftMostRegion = null;
|
myLeftMostRegionSoul = null;
|
||||||
myRightMostRegion = null;
|
myRightMostRegionSoul = null;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean start(int x, int y) {
|
boolean start(int x, int y) {
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
myLeftMostRegion = myView.findRegion(
|
final ZLTextRegion region = myView.findRegion(
|
||||||
x, y, ZLTextView.MAX_SELECTION_DISTANCE, ZLTextRegion.AnyRegionFilter
|
x, y, ZLTextView.MAX_SELECTION_DISTANCE, ZLTextRegion.AnyRegionFilter
|
||||||
);
|
);
|
||||||
if (myLeftMostRegion == null) {
|
if (region == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
myRightMostRegion = myLeftMostRegion;
|
myRightMostRegionSoul = myLeftMostRegionSoul = region.getSoul();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,22 +111,23 @@ public class ZLTextSelection {
|
||||||
return cursorToMove;
|
return cursorToMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ZLTextRegion.Soul soul = region.getSoul();
|
||||||
if (cursorToMove == ZLTextSelectionCursor.Right) {
|
if (cursorToMove == ZLTextSelectionCursor.Right) {
|
||||||
if (myLeftMostRegion.compareTo(region) <= 0) {
|
if (myLeftMostRegionSoul.compareTo(soul) <= 0) {
|
||||||
myRightMostRegion = region;
|
myRightMostRegionSoul = soul;
|
||||||
return cursorToMove;
|
return cursorToMove;
|
||||||
} else {
|
} else {
|
||||||
myRightMostRegion = myLeftMostRegion;
|
myRightMostRegionSoul = myLeftMostRegionSoul;
|
||||||
myLeftMostRegion = region;
|
myLeftMostRegionSoul = soul;
|
||||||
return ZLTextSelectionCursor.Left;
|
return ZLTextSelectionCursor.Left;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (myRightMostRegion.compareTo(region) >= 0) {
|
if (myRightMostRegionSoul.compareTo(soul) >= 0) {
|
||||||
myLeftMostRegion = region;
|
myLeftMostRegionSoul = soul;
|
||||||
return cursorToMove;
|
return cursorToMove;
|
||||||
} else {
|
} else {
|
||||||
myLeftMostRegion = myRightMostRegion;
|
myLeftMostRegionSoul = myRightMostRegionSoul;
|
||||||
myRightMostRegion = region;
|
myRightMostRegionSoul = soul;
|
||||||
return ZLTextSelectionCursor.Right;
|
return ZLTextSelectionCursor.Right;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,16 +136,92 @@ public class ZLTextSelection {
|
||||||
boolean isAreaSelected(ZLTextElementArea area) {
|
boolean isAreaSelected(ZLTextElementArea area) {
|
||||||
return
|
return
|
||||||
!isEmpty()
|
!isEmpty()
|
||||||
&& myLeftMostRegion.getFirstArea().weakCompareTo(area) <= 0
|
&& myLeftMostRegionSoul.compareTo(area) <= 0
|
||||||
&& myRightMostRegion.getLastArea().weakCompareTo(area) >= 0;
|
&& myRightMostRegionSoul.compareTo(area) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZLTextElementArea getStartArea() {
|
ZLTextPosition getStartPosition() {
|
||||||
return myLeftMostRegion.getFirstArea();
|
if (isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ZLTextFixedPosition(
|
||||||
|
myLeftMostRegionSoul.ParagraphIndex,
|
||||||
|
myLeftMostRegionSoul.StartElementIndex,
|
||||||
|
0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZLTextElementArea getEndArea() {
|
ZLTextPosition getEndPosition() {
|
||||||
return myRightMostRegion.getLastArea();
|
if (isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ZLTextFixedPosition(
|
||||||
|
myRightMostRegionSoul.ParagraphIndex,
|
||||||
|
myRightMostRegionSoul.EndElementIndex,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLTextElementArea getStartArea(ZLTextPage page) {
|
||||||
|
if (isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final ZLTextElementAreaVector vector = page.TextElementMap;
|
||||||
|
if (vector.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final ZLTextRegion region = vector.getRegion(myLeftMostRegionSoul);
|
||||||
|
if (region != null) {
|
||||||
|
return region.getFirstArea();
|
||||||
|
}
|
||||||
|
if (myRightMostRegionSoul.compareTo(vector.get(0)) >= 0) {
|
||||||
|
return vector.get(0);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLTextElementArea getEndArea(ZLTextPage page) {
|
||||||
|
if (isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final ZLTextElementAreaVector vector = page.TextElementMap;
|
||||||
|
if (vector.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final ZLTextRegion region = vector.getRegion(myRightMostRegionSoul);
|
||||||
|
if (region != null) {
|
||||||
|
return region.getLastArea();
|
||||||
|
}
|
||||||
|
if (myRightMostRegionSoul.compareTo(vector.get(vector.size() - 1)) >= 0) {
|
||||||
|
return vector.get(vector.size() - 1);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasAPartBeforePage(ZLTextPage page) {
|
||||||
|
if (isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final ZLTextElementAreaVector vector = page.TextElementMap;
|
||||||
|
if (vector.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final ZLTextElementArea firstPageArea = vector.get(0);
|
||||||
|
final int cmp = myLeftMostRegionSoul.compareTo(firstPageArea);
|
||||||
|
return cmp < 0 || (cmp == 0 && !firstPageArea.isFirstInElement());
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasAPartAfterPage(ZLTextPage page) {
|
||||||
|
if (isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final ZLTextElementAreaVector vector = page.TextElementMap;
|
||||||
|
if (vector.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final ZLTextElementArea lastPageArea = vector.get(vector.size() - 1);
|
||||||
|
final int cmp = myRightMostRegionSoul.compareTo(lastPageArea);
|
||||||
|
return cmp > 0 || (cmp == 0 && !lastPageArea.isLastInElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Scroller implements Runnable {
|
private class Scroller implements Runnable {
|
||||||
|
|
|
@ -272,8 +272,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point getSelectionCursorPoint(ZLTextPage page, ZLTextSelectionCursor cursor) {
|
private Point getSelectionCursorPoint(ZLTextPage page, ZLTextSelectionCursor cursor) {
|
||||||
final ZLTextElementAreaVector vector = page.TextElementMap;
|
if (cursor == ZLTextSelectionCursor.None) {
|
||||||
if (cursor == ZLTextSelectionCursor.None || mySelection.isEmpty() || vector.isEmpty()) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,19 +280,20 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
return myMovedSelectionCursorPoint;
|
return myMovedSelectionCursorPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ZLTextElementArea firstArea = vector.get(0);
|
|
||||||
final ZLTextElementArea lastArea = vector.get(vector.size() - 1);
|
|
||||||
|
|
||||||
if (cursor == ZLTextSelectionCursor.Left) {
|
if (cursor == ZLTextSelectionCursor.Left) {
|
||||||
final ZLTextElementArea selectionStartArea = mySelection.getStartArea();
|
if (mySelection.hasAPartBeforePage(page)) {
|
||||||
if (selectionStartArea.compareTo(firstArea) >= 0
|
return null;
|
||||||
&& selectionStartArea.compareTo(lastArea) <= 0) {
|
}
|
||||||
|
final ZLTextElementArea selectionStartArea = mySelection.getStartArea(page);
|
||||||
|
if (selectionStartArea != null) {
|
||||||
return new Point(selectionStartArea.XStart, selectionStartArea.YEnd);
|
return new Point(selectionStartArea.XStart, selectionStartArea.YEnd);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final ZLTextElementArea selectionEndArea = mySelection.getEndArea();
|
if (mySelection.hasAPartAfterPage(page)) {
|
||||||
if (selectionEndArea.compareTo(firstArea) >= 0
|
return null;
|
||||||
&& selectionEndArea.compareTo(lastArea) <= 0) {
|
}
|
||||||
|
final ZLTextElementArea selectionEndArea = mySelection.getEndArea(page);
|
||||||
|
if (selectionEndArea != null) {
|
||||||
return new Point(selectionEndArea.XEnd, selectionEndArea.YEnd);
|
return new Point(selectionEndArea.XEnd, selectionEndArea.YEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -669,10 +669,12 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
if (!mySelection.isEmpty() && from != to) {
|
if (!mySelection.isEmpty() && from != to) {
|
||||||
final ZLTextElementArea fromArea = page.TextElementMap.get(from);
|
final ZLTextElementArea fromArea = page.TextElementMap.get(from);
|
||||||
final ZLTextElementArea toArea = page.TextElementMap.get(to - 1);
|
final ZLTextElementArea toArea = page.TextElementMap.get(to - 1);
|
||||||
final ZLTextElementArea selectionStartArea = mySelection.getStartArea();
|
final ZLTextElementArea selectionStartArea = mySelection.getStartArea(page);
|
||||||
final ZLTextElementArea selectionEndArea = mySelection.getEndArea();
|
final ZLTextElementArea selectionEndArea = mySelection.getEndArea(page);
|
||||||
if (fromArea.compareTo(selectionEndArea) <= 0
|
if (selectionStartArea != null
|
||||||
&& toArea.compareTo(selectionStartArea) >= 0) {
|
&& selectionEndArea != null
|
||||||
|
&& selectionStartArea.compareTo(toArea) <= 0
|
||||||
|
&& selectionEndArea.compareTo(fromArea) >= 0) {
|
||||||
final int top = y + 1;
|
final int top = y + 1;
|
||||||
int left, right, bottom = y + info.Height + info.Descent;
|
int left, right, bottom = y + info.Height + info.Descent;
|
||||||
if (selectionStartArea.compareTo(fromArea) < 0) {
|
if (selectionStartArea.compareTo(fromArea) < 0) {
|
||||||
|
@ -1416,16 +1418,15 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
if (mySelection.isEmpty() || vector.isEmpty()) {
|
if (mySelection.isEmpty() || vector.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
final ZLTextElementArea selectionStartArea = mySelection.getStartArea();
|
final ZLTextElementArea selectionStartArea = mySelection.getStartArea(myCurrentPage);
|
||||||
final int index = vector.indexOf(selectionStartArea);
|
if (selectionStartArea != null) {
|
||||||
if (index != -1) {
|
return selectionStartArea.YStart;
|
||||||
return vector.get(index).YStart;
|
|
||||||
}
|
}
|
||||||
final ZLTextElementArea endArea = vector.get(vector.size() - 1);
|
if (mySelection.hasAPartBeforePage(myCurrentPage)) {
|
||||||
if (selectionStartArea.compareTo(endArea) > 0) {
|
return vector.get(0).YStart;
|
||||||
return endArea.YEnd;
|
} else {
|
||||||
|
return vector.get(vector.size() - 1).YEnd;
|
||||||
}
|
}
|
||||||
return vector.get(0).YStart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSelectionEndY() {
|
public int getSelectionEndY() {
|
||||||
|
@ -1433,26 +1434,23 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
if (mySelection.isEmpty() || vector.isEmpty()) {
|
if (mySelection.isEmpty() || vector.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
final ZLTextElementArea selectionEndArea = mySelection.getEndArea();
|
final ZLTextElementArea selectionEndArea = mySelection.getEndArea(myCurrentPage);
|
||||||
final int index = vector.indexOf(selectionEndArea);
|
if (selectionEndArea != null) {
|
||||||
if (index != -1) {
|
return selectionEndArea.YEnd;
|
||||||
return vector.get(index).YEnd;
|
|
||||||
}
|
}
|
||||||
final ZLTextElementArea endArea = vector.get(vector.size() - 1);
|
if (mySelection.hasAPartAfterPage(myCurrentPage)) {
|
||||||
if (selectionEndArea.compareTo(endArea) > 0) {
|
return vector.get(vector.size() - 1).YEnd;
|
||||||
return endArea.YEnd;
|
} else {
|
||||||
|
return vector.get(0).YStart;
|
||||||
}
|
}
|
||||||
return vector.get(0).YStart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLTextPosition getSelectionStartPosition() {
|
public ZLTextPosition getSelectionStartPosition() {
|
||||||
final ZLTextPosition start = mySelection.getStartArea();
|
return mySelection.getStartPosition();
|
||||||
return new ZLTextFixedPosition(start.getParagraphIndex(), start.getElementIndex(), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLTextPosition getSelectionEndPosition() {
|
public ZLTextPosition getSelectionEndPosition() {
|
||||||
final ZLTextPosition end = mySelection.getEndArea();
|
return mySelection.getEndPosition();
|
||||||
return new ZLTextFixedPosition(end.getParagraphIndex(), end.getElementIndex(), Integer.MAX_VALUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSelectionEmpty() {
|
public boolean isSelectionEmpty() {
|
||||||
|
|
|
@ -22,20 +22,8 @@ package org.geometerplus.zlibrary.text.view;
|
||||||
public class ZLTextWordRegionSoul extends ZLTextRegion.Soul {
|
public class ZLTextWordRegionSoul extends ZLTextRegion.Soul {
|
||||||
public final ZLTextWord Word;
|
public final ZLTextWord Word;
|
||||||
|
|
||||||
ZLTextWordRegionSoul(ZLTextWord word) {
|
ZLTextWordRegionSoul(ZLTextPosition position, ZLTextWord word) {
|
||||||
|
super(position.getParagraphIndex(), position.getElementIndex(), position.getElementIndex());
|
||||||
Word = word;
|
Word = word;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
boolean accepts(ZLTextElementArea area) {
|
|
||||||
return Word == area.Element;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
if (!(other instanceof ZLTextWordRegionSoul)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return Word == ((ZLTextWordRegionSoul)other).Word;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue