aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <unknown>2009-07-07 11:52:09 +0000
committernyamatongwe <unknown>2009-07-07 11:52:09 +0000
commita8253c4498fe0ca70458d03b86315b728988d08e (patch)
tree58a8ee44a804dd0415f9389c06bf3289509c5aae /src
parent599253475568259ee4ad8bdc5399cf67357c663d (diff)
downloadscintilla-mirror-a8253c4498fe0ca70458d03b86315b728988d08e.tar.gz
Using the last style on a line to determine the width of a virtual space
rather than use the default style. This adapts better for comments which use a different font.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx30
-rw-r--r--src/Editor.h3
-rw-r--r--src/PositionCache.cxx4
-rw-r--r--src/PositionCache.h1
4 files changed, 26 insertions, 12 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index a2abba607..eeee752a8 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -473,7 +473,7 @@ SelectionPosition Editor::SPositionFromLocation(Point pt, bool canReturnInvalid,
i++;
}
if (virtualSpace) {
- const int spaceWidth = static_cast<int>(vs.spaceWidth);
+ const int spaceWidth = static_cast<int>(vs.styles[ll->EndLineStyle()].spaceWidth);
int spaceOffset = (pt.x + subLineStart - ll->positions[lineEnd] + spaceWidth / 2) /
spaceWidth;
return SelectionPosition(lineEnd + posLineStart, spaceOffset);
@@ -564,7 +564,7 @@ SelectionPosition Editor::SPositionFromLineX(int lineDoc, int x) {
}
i++;
}
- const int spaceWidth = static_cast<int>(vs.spaceWidth);
+ const int spaceWidth = static_cast<int>(vs.styles[ll->EndLineStyle()].spaceWidth);
int spaceOffset = (x + subLineStart - ll->positions[lineEnd] + spaceWidth / 2) / spaceWidth;
return SelectionPosition(lineEnd + posLineStart, spaceOffset);
}
@@ -2238,8 +2238,10 @@ void Editor::DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, Lin
PRectangle rcSegment = rcLine;
int virtualSpace = 0;
- if (subLine == (ll->lines - 1))
- virtualSpace = sel.VirtualSpaceFor(pdoc->LineEnd(line)) * vsDraw.spaceWidth;
+ if (subLine == (ll->lines - 1)) {
+ const int spaceWidth = static_cast<int>(vsDraw.styles[ll->EndLineStyle()].spaceWidth);
+ virtualSpace = sel.VirtualSpaceFor(pdoc->LineEnd(line)) * spaceWidth;
+ }
// Fill in a PRectangle representing the end of line characters
int xEol = ll->positions[lineEnd] - subLineStart;
@@ -2863,8 +2865,9 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis
SelectionPosition spEnd;
if (sel.Range(r).Intersect(posLineStart, posLineStart + lineEnd, spStart, spEnd)) {
if (!(spStart == spEnd)) {
- rcSegment.left = xStart + ll->positions[spStart.Position() - posLineStart] - subLineStart + spStart.VirtualSpace() * vsDraw.spaceWidth;
- rcSegment.right = xStart + ll->positions[spEnd.Position() - posLineStart] - subLineStart + spEnd.VirtualSpace() * vsDraw.spaceWidth;
+ const int spaceWidth = static_cast<int>(vsDraw.styles[ll->EndLineStyle()].spaceWidth);
+ rcSegment.left = xStart + ll->positions[spStart.Position() - posLineStart] - subLineStart + spStart.VirtualSpace() * spaceWidth;
+ rcSegment.right = xStart + ll->positions[spEnd.Position() - posLineStart] - subLineStart + spEnd.VirtualSpace() * spaceWidth;
rcSegment.left = Platform::Maximum(rcSegment.left, rcLine.left);
rcSegment.right = Platform::Minimum(rcSegment.right, rcLine.right);
SimpleAlphaRectangle(surface, rcSegment, SelectionBackground(vsDraw),
@@ -3044,7 +3047,8 @@ void Editor::DrawCarets(Surface *surface, ViewStyle &vsDraw, int lineDoc, int xS
const bool mainCaret = r == sel.Main();
const SelectionPosition posCaret = (drawDrag ? posDrag : sel.Range(r).caret);
const int offset = posCaret.Position() - rangeLine.start;
- const int virtualOffset = posCaret.VirtualSpace() * vsDraw.spaceWidth;
+ const int spaceWidth = static_cast<int>(vsDraw.styles[ll->EndLineStyle()].spaceWidth);
+ const int virtualOffset = posCaret.VirtualSpace() * spaceWidth;
if (ll->InLine(offset, subLine) && offset <= ll->numCharsInLine) {
int xposCaret = ll->positions[offset] + virtualOffset - ll->positions[ll->LineStart(subLine)] + xStart;
if (ll->wrapIndent != 0) {
@@ -3777,10 +3781,12 @@ void Editor::PasteRectangular(SelectionPosition pos, const char *ptr, int len) {
}
sel.Clear();
sel.RangeMain() = SelectionRange(pos, pos);
- int xInsert = XFromPosition(sel.RangeMain().caret);
int line = pdoc->LineFromPosition(sel.MainCaret());
- bool prevCr = false;
pdoc->BeginUndoAction();
+ sel.RangeMain().caret = SelectionPosition(
+ InsertSpace(sel.RangeMain().caret.Position(), sel.RangeMain().caret.VirtualSpace()));
+ int xInsert = XFromPosition(sel.RangeMain().caret);
+ bool prevCr = false;
for (int i = 0; i < len; i++) {
if (IsEOLChar(ptr[i])) {
if ((ptr[i] == '\r') || (!prevCr))
@@ -4508,10 +4514,10 @@ void Editor::CursorUpOrDown(int direction, Selection::selTypes selt) {
int subLine = (pt.y - ptStartLine.y) / vs.lineHeight;
int commentLines = vs.annotationVisible ? pdoc->AnnotationLines(lineDoc) : 0;
SelectionPosition posNew = SPositionFromLocation(
- Point(lastXChosen, pt.y + direction * vs.lineHeight));
+ Point(lastXChosen, pt.y + direction * vs.lineHeight), false, false, UserVirtualSpace());
if ((direction > 0) && (subLine >= (cs.GetHeight(lineDoc) - 1 - commentLines))) {
posNew = SPositionFromLocation(
- Point(lastXChosen, pt.y + (commentLines + 1) * vs.lineHeight));
+ Point(lastXChosen, pt.y + (commentLines + 1) * vs.lineHeight), false, false, UserVirtualSpace());
}
if (direction < 0) {
// Line wrapping may lead to a location on the same line, so
@@ -5407,7 +5413,7 @@ void Editor::DropAt(SelectionPosition position, const char *value, bool moving,
position = positionAfterDeletion;
if (rectangular) {
- PasteRectangular(SelectionPosition(position), value, istrlen(value));
+ PasteRectangular(position, value, istrlen(value));
pdoc->EndUndoAction();
// Should try to select new rectangle but it may not be a rectangle now so just select the drop position
SetEmptySelection(position);
diff --git a/src/Editor.h b/src/Editor.h
index 687d963eb..051eb9329 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -276,6 +276,9 @@ protected: // ScintillaBase subclass needs access to much of Editor
PRectangle RectangleFromRange(int start, int end);
void InvalidateRange(int start, int end);
+ bool UserVirtualSpace() const {
+ return ((virtualSpaceOptions & SCVS_USERACCESSIBLE) != 0);
+ }
int CurrentPosition();
bool SelectionEmpty();
SelectionPosition SelectionStart();
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx
index 258a14860..b727ec465 100644
--- a/src/PositionCache.cxx
+++ b/src/PositionCache.cxx
@@ -197,6 +197,10 @@ int LineLayout::FindBefore(int x, int lower, int upper) const {
return lower;
}
+int LineLayout::EndLineStyle() const {
+ return styles[numCharsBeforeEOL > 0 ? numCharsBeforeEOL-1 : 0];
+}
+
LineLayoutCache::LineLayoutCache() :
level(0), length(0), size(0), cache(0),
allInvalidated(false), styleClock(-1), useCount(0) {
diff --git a/src/PositionCache.h b/src/PositionCache.h
index bd984d40b..a86881070 100644
--- a/src/PositionCache.h
+++ b/src/PositionCache.h
@@ -66,6 +66,7 @@ public:
char bracesMatchStyle, int xHighlight);
void RestoreBracesHighlight(Range rangeLine, Position braces[]);
int FindBefore(int x, int lower, int upper) const;
+ int EndLineStyle() const;
};
/**