aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarko Njezic <unknown>2012-01-18 21:29:08 +0100
committerMarko Njezic <unknown>2012-01-18 21:29:08 +0100
commitf68be5f8dda0925786c1130f1ed2da9f7bbc2e6c (patch)
tree36c1772db583454f7b8f487bc14be676fdf883a5
parentda3082f8138af088adf8190b9255b9ea27c0e914 (diff)
downloadscintilla-mirror-f68be5f8dda0925786c1130f1ed2da9f7bbc2e6c.tar.gz
Add fractional positioning support in wrapped lines to certain methods.
This fixes off by one errors that can happen in some cases. Simplify Editor::PositionFromLineX() method.
-rw-r--r--src/Editor.cxx47
1 files changed, 7 insertions, 40 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 35a21c36c..6919d91d7 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -506,7 +506,7 @@ SelectionPosition Editor::SPositionFromLocation(Point pt, bool canReturnInvalid,
if (subLine < ll->lines) {
int lineStart = ll->LineStart(subLine);
int lineEnd = ll->LineLastVisible(subLine);
- int subLineStart = ll->positions[lineStart];
+ XYPOSITION subLineStart = ll->positions[lineStart];
if (ll->wrapIndent != 0) {
if (lineStart != 0) // Wrapped
@@ -552,43 +552,6 @@ int Editor::PositionFromLocation(Point pt, bool canReturnInvalid, bool charPosit
* Find the document position corresponding to an x coordinate on a particular document line.
* Ensure is between whole characters when document is in multi-byte or UTF-8 mode.
*/
-int Editor::PositionFromLineX(int lineDoc, int x) {
- RefreshStyleData();
- if (lineDoc >= pdoc->LinesTotal())
- return pdoc->Length();
- //Platform::DebugPrintf("Position of (%d,%d) line = %d top=%d\n", pt.x, pt.y, line, topLine);
- AutoSurface surface(this);
- AutoLineLayout ll(llc, RetrieveLineLayout(lineDoc));
- int retVal = 0;
- if (surface && ll) {
- unsigned int posLineStart = pdoc->LineStart(lineDoc);
- LayoutLine(lineDoc, surface, vs, ll, wrapWidth);
- retVal = ll->numCharsBeforeEOL + posLineStart;
- int subLine = 0;
- int lineStart = ll->LineStart(subLine);
- int lineEnd = ll->LineLastVisible(subLine);
- int subLineStart = ll->positions[lineStart];
-
- if (ll->wrapIndent != 0) {
- if (lineStart != 0) // Wrapped
- x -= ll->wrapIndent;
- }
- int i = ll->FindBefore(x + subLineStart, lineStart, lineEnd);
- while (i < lineEnd) {
- if ((x + subLineStart) < ((ll->positions[i] + ll->positions[i + 1]) / 2)) {
- retVal = pdoc->MovePositionOutsideChar(i + posLineStart, 1);
- break;
- }
- i++;
- }
- }
- return retVal;
-}
-
-/**
- * Find the document position corresponding to an x coordinate on a particular document line.
- * Ensure is between whole characters when document is in multi-byte or UTF-8 mode.
- */
SelectionPosition Editor::SPositionFromLineX(int lineDoc, int x) {
RefreshStyleData();
if (lineDoc >= pdoc->LinesTotal())
@@ -603,7 +566,7 @@ SelectionPosition Editor::SPositionFromLineX(int lineDoc, int x) {
int subLine = 0;
int lineStart = ll->LineStart(subLine);
int lineEnd = ll->LineLastVisible(subLine);
- int subLineStart = ll->positions[lineStart];
+ XYPOSITION subLineStart = ll->positions[lineStart];
if (ll->wrapIndent != 0) {
if (lineStart != 0) // Wrapped
@@ -624,6 +587,10 @@ SelectionPosition Editor::SPositionFromLineX(int lineDoc, int x) {
return SelectionPosition(retVal);
}
+int Editor::PositionFromLineX(int lineDoc, int x) {
+ return SPositionFromLineX(lineDoc, x).Position();
+}
+
/**
* If painting then abandon the painting because a wider redraw is needed.
* @return true if calling code should stop drawing.
@@ -2357,7 +2324,7 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou
// Calculate line start positions based upon width.
int lastGoodBreak = 0;
int lastLineStart = 0;
- int startOffset = 0;
+ XYACCUMULATOR startOffset = 0;
int p = 0;
while (p < ll->numCharsInLine) {
if ((ll->positions[p + 1] - startOffset) >= width) {