diff options
Diffstat (limited to 'src/Editor.cxx')
| -rw-r--r-- | src/Editor.cxx | 69 | 
1 files changed, 48 insertions, 21 deletions
| diff --git a/src/Editor.cxx b/src/Editor.cxx index d54bbe36c..f7f5cb2bb 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -184,7 +184,8 @@ Editor::Editor() {  	wrapVisualFlags = 0;  	wrapVisualFlagsLocation = 0;  	wrapVisualStartIndent = 0; -	actualWrapVisualStartIndent = 0; +	wrapIndentMode = SC_WRAPINDENT_FIXED; +	wrapAddIndent = 0;  	convertPastes = true; @@ -252,6 +253,15 @@ void Editor::RefreshStyleData() {  			palette.Allocate(wMain);  			RefreshColourPalette(palette, false);  		} +		if (wrapIndentMode == SC_WRAPINDENT_INDENT) { +			wrapAddIndent = pdoc->IndentSize() * vs.spaceWidth; +		} else if (wrapIndentMode == SC_WRAPINDENT_SAME) { +			wrapAddIndent = 0; +		} else { //SC_WRAPINDENT_FIXED +			wrapAddIndent = wrapVisualStartIndent * vs.aveCharWidth; +			if ((wrapVisualFlags & SC_WRAPVISUALFLAG_START) && (wrapAddIndent <= 0)) +				wrapAddIndent = vs.aveCharWidth; // must indent to show start visual +		}  		SetScrollBars();  	}  } @@ -448,10 +458,10 @@ Point Editor::LocationFromPosition(int pos) {  		for (int subLine = 0; subLine < ll->lines; subLine++) {  			if ((posInLine >= ll->LineStart(subLine)) && (posInLine <= ll->LineStart(subLine + 1))) {  				pt.x = ll->positions[posInLine] - ll->positions[ll->LineStart(subLine)]; -				if (actualWrapVisualStartIndent != 0) { +				if (ll->wrapIndent != 0) {  					int lineStart = ll->LineStart(subLine);  					if (lineStart != 0)	// Wrapped -						pt.x += actualWrapVisualStartIndent * vs.aveCharWidth; +						pt.x += ll->wrapIndent;  				}  			}  			if (posInLine >= ll->LineStart(subLine)) { @@ -513,9 +523,9 @@ int Editor::PositionFromLocation(Point pt, bool canReturnInvalid, bool charPosit  			int lineEnd = ll->LineLastVisible(subLine);  			int subLineStart = ll->positions[lineStart]; -			if (actualWrapVisualStartIndent != 0) { +			if (ll->wrapIndent != 0) {  				if (lineStart != 0)	// Wrapped -					pt.x -= actualWrapVisualStartIndent * vs.aveCharWidth; +					pt.x -= ll->wrapIndent;  			}  			int i = ll->FindBefore(pt.x + subLineStart, lineStart, lineEnd);  			while (i < lineEnd) { @@ -565,9 +575,9 @@ int Editor::PositionFromLineX(int lineDoc, int x) {  		int lineEnd = ll->LineLastVisible(subLine);  		int subLineStart = ll->positions[lineStart]; -		if (actualWrapVisualStartIndent != 0) { +		if (ll->wrapIndent != 0) {  			if (lineStart != 0)	// Wrapped -				x -= actualWrapVisualStartIndent * vs.aveCharWidth; +				x -= ll->wrapIndent;  		}  		int i = ll->FindBefore(x + subLineStart, lineStart, lineEnd);  		while (i < lineEnd) { @@ -1999,6 +2009,20 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou  			if (wrapVisualFlags & SC_WRAPVISUALFLAG_END) {  				width -= vstyle.aveCharWidth; // take into account the space for end wrap mark  			} +			ll->wrapIndent = wrapAddIndent; +			if (wrapIndentMode != SC_WRAPINDENT_FIXED) +				for (int i = 0; i < ll->numCharsInLine; i++) { +					if (!IsSpaceOrTab(ll->chars[i])) { +						ll->wrapIndent += ll->positions[i]; // Add line indent +						break; +					} +				} +			// Check for text width minimum +			if (ll->wrapIndent > width - static_cast<int>(vstyle.aveCharWidth) * 15) +				ll->wrapIndent = wrapAddIndent; +			// Check for wrapIndent minimum +			if ((wrapVisualFlags & SC_WRAPVISUALFLAG_START) && (ll->wrapIndent < static_cast<int>(vstyle.aveCharWidth))) +				ll->wrapIndent = vstyle.aveCharWidth; // Indent to show start visual  			ll->lines = 0;  			// Calculate line start positions based upon width.  			int lastGoodBreak = 0; @@ -2024,7 +2048,7 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou  					ll->SetLineStart(ll->lines, lastGoodBreak);  					startOffset = ll->positions[lastGoodBreak];  					// take into account the space for start wrap mark and indent -					startOffset -= actualWrapVisualStartIndent * vstyle.aveCharWidth; +					startOffset -= ll->wrapIndent;  					p = lastGoodBreak + 1;  					continue;  				} @@ -2417,7 +2441,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis  		}  	} -	if (actualWrapVisualStartIndent != 0) { +	if (ll->wrapIndent != 0) {  		bool continuedWrapLine = false;  		if (subLine < ll->lines) { @@ -2429,7 +2453,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis  			PRectangle rcPlace = rcSegment;  			rcPlace.left = ll->positions[startseg] + xStart - subLineStart; -			rcPlace.right = rcPlace.left + actualWrapVisualStartIndent * vsDraw.aveCharWidth; +			rcPlace.right = rcPlace.left + ll->wrapIndent;  			// default bgnd here..  			surface->FillRectangle(rcSegment, overrideBackground ? background : @@ -2450,7 +2474,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis  				DrawWrapMarker(surface, rcPlace, false, wrapColour);  			} -			xStart += actualWrapVisualStartIndent * vsDraw.aveCharWidth; +			xStart += ll->wrapIndent;  		}  	} @@ -2832,8 +2856,8 @@ void Editor::DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll,  	rcCaret.right = ll->positions[offsetFirstChar+numCharsToDraw] - ll->positions[lineStart] + xStart;  	// Adjust caret position to take into account any word wrapping symbols. -	if ((actualWrapVisualStartIndent != 0) && (lineStart != 0)) { -		int wordWrapCharWidth = actualWrapVisualStartIndent * vs.aveCharWidth; +	if ((ll->wrapIndent != 0) && (lineStart != 0)) { +		int wordWrapCharWidth = ll->wrapIndent;  		rcCaret.left += wordWrapCharWidth;  		rcCaret.right += wordWrapCharWidth;  	} @@ -3114,10 +3138,10 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) {  					if (ll->InLine(offset, subLine)) {  						int xposCaret = ll->positions[offset] - ll->positions[ll->LineStart(subLine)] + xStart; -						if (actualWrapVisualStartIndent != 0) { +						if (ll->wrapIndent != 0) {  							int lineStart = ll->LineStart(subLine);  							if (lineStart != 0)	// Wrapped -								xposCaret += actualWrapVisualStartIndent * vs.aveCharWidth; +								xposCaret += ll->wrapIndent;  						}  						if ((xposCaret >= 0) && (vs.caretWidth > 0) && (vs.caretStyle != CARETSTYLE_INVISIBLE) &&  						        ((posDrag >= 0) || (caret.active && caret.on))) { @@ -6786,9 +6810,6 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {  	case SCI_SETWRAPVISUALFLAGS:  		wrapVisualFlags = wParam; -		actualWrapVisualStartIndent = wrapVisualStartIndent; -		if ((wrapVisualFlags & SC_WRAPVISUALFLAG_START) && (actualWrapVisualStartIndent == 0)) -			actualWrapVisualStartIndent = 1; // must indent to show start visual  		InvalidateStyleRedraw();  		ReconfigureScrollBars();  		break; @@ -6806,9 +6827,6 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {  	case SCI_SETWRAPSTARTINDENT:  		wrapVisualStartIndent = wParam; -		actualWrapVisualStartIndent = wrapVisualStartIndent; -		if ((wrapVisualFlags & SC_WRAPVISUALFLAG_START) && (actualWrapVisualStartIndent == 0)) -			actualWrapVisualStartIndent = 1; // must indent to show start visual  		InvalidateStyleRedraw();  		ReconfigureScrollBars();  		break; @@ -6816,6 +6834,15 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {  	case SCI_GETWRAPSTARTINDENT:  		return wrapVisualStartIndent; +	case SCI_SETWRAPINDENTMODE: +		wrapIndentMode = wParam; +		InvalidateStyleRedraw(); +		ReconfigureScrollBars(); +		break; + +	case SCI_GETWRAPINDENTMODE: +		return wrapIndentMode; +  	case SCI_SETLAYOUTCACHE:  		llc.SetLevel(wParam);  		break; | 
