diff options
Diffstat (limited to 'src/EditView.cxx')
| -rw-r--r-- | src/EditView.cxx | 61 | 
1 files changed, 35 insertions, 26 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx index 3ad33f2d6..762aa8187 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -564,46 +564,55 @@ void EditView::LayoutLine(const EditModel &model, Surface *surface, const ViewSt  				ll->wrapIndent = vstyle.aveCharWidth; // Indent to show start visual  			ll->lines = 0;  			// Calculate line start positions based upon width. -			Sci::Position lastGoodBreak = 0;  			Sci::Position lastLineStart = 0; -			XYACCUMULATOR startOffset = 0; +			XYACCUMULATOR startOffset = width;  			Sci::Position p = 0; -			while (p < ll->numCharsInLine) { -				if ((ll->positions[p + 1] - startOffset) >= width) { +			const Wrap wrapState = vstyle.wrap.state; +			const Sci::Position numCharsInLine = ll->numCharsInLine; +			while (p < numCharsInLine) { +				while (p < numCharsInLine && ll->positions[p + 1] < startOffset) { +					p++; +				} +				if (p < numCharsInLine) { +					// backtrack to find lastGoodBreak +					Sci::Position lastGoodBreak = p; +					if (p > 0) { +						lastGoodBreak = model.pdoc->MovePositionOutsideChar(p + posLineStart, -1) - posLineStart; +					} +					if (wrapState != Wrap::Char) { +						Sci::Position pos = lastGoodBreak; +						while (pos > lastLineStart) { +							// style boundary and space +							if (wrapState != Wrap::WhiteSpace && (ll->styles[pos - 1] != ll->styles[pos])) { +								break; +							} +							if (IsBreakSpace(ll->chars[pos - 1]) && !IsBreakSpace(ll->chars[pos])) { +								break; +							} +							pos = model.pdoc->MovePositionOutsideChar(pos + posLineStart - 1, -1) - posLineStart; +						} +						if (pos > lastLineStart) { +							lastGoodBreak = pos; +						} +					}  					if (lastGoodBreak == lastLineStart) {  						// Try moving to start of last character  						if (p > 0) { -							lastGoodBreak = model.pdoc->MovePositionOutsideChar(p + posLineStart, -1) -								- posLineStart; +							lastGoodBreak = model.pdoc->MovePositionOutsideChar(p + posLineStart, -1) - posLineStart;  						}  						if (lastGoodBreak == lastLineStart) {  							// Ensure at least one character on line. -							lastGoodBreak = model.pdoc->MovePositionOutsideChar(lastGoodBreak + posLineStart + 1, 1) -								- posLineStart; +							lastGoodBreak = model.pdoc->MovePositionOutsideChar(lastGoodBreak + posLineStart + 1, 1) - posLineStart;  						}  					}  					lastLineStart = lastGoodBreak;  					ll->lines++; -					ll->SetLineStart(ll->lines, static_cast<int>(lastGoodBreak)); -					startOffset = ll->positions[lastGoodBreak]; +					ll->SetLineStart(ll->lines, static_cast<int>(lastLineStart)); +					startOffset = ll->positions[lastLineStart];  					// take into account the space for start wrap mark and indent -					startOffset -= ll->wrapIndent; -					p = lastGoodBreak + 1; -					continue; -				} -				if (p > 0) { -					if (vstyle.wrap.state == Wrap::Char) { -						lastGoodBreak = model.pdoc->MovePositionOutsideChar(p + posLineStart, -1) -							- posLineStart; -						p = model.pdoc->MovePositionOutsideChar(p + 1 + posLineStart, 1) - posLineStart; -						continue; -					} else if ((vstyle.wrap.state == Wrap::Word) && (ll->styles[p] != ll->styles[p - 1])) { -						lastGoodBreak = p; -					} else if (IsSpaceOrTab(ll->chars[p - 1]) && !IsSpaceOrTab(ll->chars[p])) { -						lastGoodBreak = p; -					} +					startOffset += width - ll->wrapIndent; +					p = lastLineStart + 1;  				} -				p++;  			}  			ll->lines++;  		}  | 
