summaryrefslogtreecommitdiffstats
path: root/scintilla/src
diff options
context:
space:
mode:
Diffstat (limited to 'scintilla/src')
-rw-r--r--scintilla/src/Catalogue.cxx1
-rw-r--r--scintilla/src/Editor.cxx115
-rw-r--r--scintilla/src/Editor.h6
-rw-r--r--scintilla/src/PerLine.cxx6
-rw-r--r--scintilla/src/PositionCache.cxx49
-rw-r--r--scintilla/src/PositionCache.h3
-rw-r--r--scintilla/src/ScintillaBase.cxx10
-rw-r--r--scintilla/src/ViewStyle.cxx9
-rw-r--r--scintilla/src/ViewStyle.h4
9 files changed, 102 insertions, 101 deletions
diff --git a/scintilla/src/Catalogue.cxx b/scintilla/src/Catalogue.cxx
index c6d7eb6..e4c5ad0 100644
--- a/scintilla/src/Catalogue.cxx
+++ b/scintilla/src/Catalogue.cxx
@@ -81,6 +81,7 @@ int Scintilla_LinkLexers() {
//LINK_LEXER(lmAda);
LINK_LEXER(lmAHK);
//LINK_LEXER(lmAPDL);
+ //LINK_LEXER(lmAs);
LINK_LEXER(lmAsm);
//LINK_LEXER(lmAsn1);
//LINK_LEXER(lmASY);
diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx
index 683ec19..5dab852 100644
--- a/scintilla/src/Editor.cxx
+++ b/scintilla/src/Editor.cxx
@@ -477,36 +477,17 @@ Point Editor::LocationFromPosition(SelectionPosition pos) {
RefreshStyleData();
if (pos.Position() == INVALID_POSITION)
return pt;
- int line = pdoc->LineFromPosition(pos.Position());
- int lineVisible = cs.DisplayFromDoc(line);
+ const int line = pdoc->LineFromPosition(pos.Position());
+ const int lineVisible = cs.DisplayFromDoc(line);
//Platform::DebugPrintf("line=%d\n", line);
AutoSurface surface(this);
AutoLineLayout ll(llc, RetrieveLineLayout(line));
if (surface && ll) {
- // -1 because of adding in for visible lines in following loop.
- pt.y = (lineVisible - topLine - 1) * vs.lineHeight;
- pt.x = 0;
- unsigned int posLineStart = pdoc->LineStart(line);
+ const int posLineStart = pdoc->LineStart(line);
LayoutLine(line, surface, vs, ll, wrapWidth);
- int posInLine = pos.Position() - posLineStart;
- // In case of very long line put x at arbitrary large position
- if (posInLine > ll->maxLineLength) {
- pt.x = ll->positions[ll->maxLineLength] - ll->positions[ll->LineStart(ll->lines)];
- }
-
- 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 (ll->wrapIndent != 0) {
- int lineStart = ll->LineStart(subLine);
- if (lineStart != 0) // Wrapped
- pt.x += ll->wrapIndent;
- }
- }
- if (posInLine >= ll->LineStart(subLine)) {
- pt.y += vs.lineHeight;
- }
- }
+ const int posInLine = pos.Position() - posLineStart;
+ pt = ll->PointFromPosition(posInLine, vs.lineHeight);
+ pt.y += (lineVisible - topLine) * vs.lineHeight;
pt.x += vs.textStart - xOffset;
}
pt.x += pos.VirtualSpace() * vs.styles[ll->EndLineStyle()].spaceWidth;
@@ -558,58 +539,44 @@ SelectionPosition Editor::SPositionFromLocation(Point pt, bool canReturnInvalid,
int visibleLine = floor(pt.y / vs.lineHeight);
if (!canReturnInvalid && (visibleLine < 0))
visibleLine = 0;
- int lineDoc = cs.DocFromDisplay(visibleLine);
+ const int lineDoc = cs.DocFromDisplay(visibleLine);
if (canReturnInvalid && (lineDoc < 0))
return SelectionPosition(INVALID_POSITION);
if (lineDoc >= pdoc->LinesTotal())
return SelectionPosition(canReturnInvalid ? INVALID_POSITION : pdoc->Length());
- unsigned int posLineStart = pdoc->LineStart(lineDoc);
- SelectionPosition retVal(canReturnInvalid ? INVALID_POSITION : static_cast<int>(posLineStart));
+ const int posLineStart = pdoc->LineStart(lineDoc);
AutoSurface surface(this);
AutoLineLayout ll(llc, RetrieveLineLayout(lineDoc));
if (surface && ll) {
LayoutLine(lineDoc, surface, vs, ll, wrapWidth);
- int lineStartSet = cs.DisplayFromDoc(lineDoc);
- int subLine = visibleLine - lineStartSet;
+ const int lineStartSet = cs.DisplayFromDoc(lineDoc);
+ const int subLine = visibleLine - lineStartSet;
if (subLine < ll->lines) {
- int lineStart = ll->LineStart(subLine);
- int lineEnd = ll->LineLastVisible(subLine);
- XYPOSITION subLineStart = ll->positions[lineStart];
-
- if (ll->wrapIndent != 0) {
- if (lineStart != 0) // Wrapped
- pt.x -= ll->wrapIndent;
- }
- int i = ll->FindBefore(pt.x + subLineStart, lineStart, lineEnd);
- while (i < lineEnd) {
- if (charPosition) {
- if ((pt.x + subLineStart) < (ll->positions[i + 1])) {
- return SelectionPosition(pdoc->MovePositionOutsideChar(i + posLineStart, 1));
- }
- } else {
- if ((pt.x + subLineStart) < ((ll->positions[i] + ll->positions[i + 1]) / 2)) {
- return SelectionPosition(pdoc->MovePositionOutsideChar(i + posLineStart, 1));
- }
- }
- i++;
+ const Range rangeSubLine = ll->SubLineRange(subLine);
+ const XYPOSITION subLineStart = ll->positions[rangeSubLine.start];
+ if (subLine > 0) // Wrapped
+ pt.x -= ll->wrapIndent;
+ const int positionInLine = ll->FindPositionFromX(pt.x + subLineStart, rangeSubLine, charPosition);
+ if (positionInLine < rangeSubLine.end) {
+ return SelectionPosition(pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1));
}
if (virtualSpace) {
const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth;
- int spaceOffset = (pt.x + subLineStart - ll->positions[lineEnd] + spaceWidth / 2) /
+ const int spaceOffset = (pt.x + subLineStart - ll->positions[rangeSubLine.end] + spaceWidth / 2) /
spaceWidth;
- return SelectionPosition(lineEnd + posLineStart, spaceOffset);
+ return SelectionPosition(rangeSubLine.end + posLineStart, spaceOffset);
} else if (canReturnInvalid) {
- if (pt.x < (ll->positions[lineEnd] - subLineStart)) {
- return SelectionPosition(pdoc->MovePositionOutsideChar(lineEnd + posLineStart, 1));
+ if (pt.x < (ll->positions[rangeSubLine.end] - subLineStart)) {
+ return SelectionPosition(pdoc->MovePositionOutsideChar(rangeSubLine.end + posLineStart, 1));
}
} else {
- return SelectionPosition(lineEnd + posLineStart);
+ return SelectionPosition(rangeSubLine.end + posLineStart);
}
}
if (!canReturnInvalid)
return SelectionPosition(ll->numCharsInLine + posLineStart);
}
- return retVal;
+ return SelectionPosition(canReturnInvalid ? INVALID_POSITION : posLineStart);
}
int Editor::PositionFromLocation(Point pt, bool canReturnInvalid, bool charPosition) {
@@ -619,6 +586,7 @@ 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.
+ * This method is used for rectangular selections and does not work on wrapped lines.
*/
SelectionPosition Editor::SPositionFromLineX(int lineDoc, int x) {
RefreshStyleData();
@@ -627,33 +595,20 @@ SelectionPosition Editor::SPositionFromLineX(int lineDoc, int x) {
//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);
+ const int posLineStart = pdoc->LineStart(lineDoc);
LayoutLine(lineDoc, surface, vs, ll, wrapWidth);
- int subLine = 0;
- int lineStart = ll->LineStart(subLine);
- int lineEnd = ll->LineLastVisible(subLine);
- XYPOSITION subLineStart = ll->positions[lineStart];
- XYPOSITION newX = x;
-
- if (ll->wrapIndent != 0) {
- if (lineStart != 0) // Wrapped
- newX -= ll->wrapIndent;
- }
- int i = ll->FindBefore(newX + subLineStart, lineStart, lineEnd);
- while (i < lineEnd) {
- if ((newX + subLineStart) < ((ll->positions[i] + ll->positions[i + 1]) / 2)) {
- retVal = pdoc->MovePositionOutsideChar(i + posLineStart, 1);
- return SelectionPosition(retVal);
- }
- i++;
+ const Range rangeSubLine = ll->SubLineRange(0);
+ const XYPOSITION subLineStart = ll->positions[rangeSubLine.start];
+ const int positionInLine = ll->FindPositionFromX(x + subLineStart, rangeSubLine, false);
+ if (positionInLine < rangeSubLine.end) {
+ return SelectionPosition(pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1));
}
const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth;
- int spaceOffset = (newX + subLineStart - ll->positions[lineEnd] + spaceWidth / 2) / spaceWidth;
- return SelectionPosition(lineEnd + posLineStart, spaceOffset);
+ const int spaceOffset = (x + subLineStart - ll->positions[rangeSubLine.end] + spaceWidth / 2) / spaceWidth;
+ return SelectionPosition(rangeSubLine.end + posLineStart, spaceOffset);
}
- return SelectionPosition(retVal);
+ return SelectionPosition(0);
}
int Editor::PositionFromLineX(int lineDoc, int x) {
@@ -1279,7 +1234,7 @@ slop | strict | jumps | even | Caret can go to the margin | When
1 | 1 | 1 | 1 | No, kept out of UZ | moved to put caret at 3UZ of the margin
*/
-Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange range, const XYScrollOptions options) {
+Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &range, const XYScrollOptions options) {
PRectangle rcClient = GetTextRectangle();
Point pt = LocationFromPosition(range.caret);
Point ptAnchor = LocationFromPosition(range.anchor);
@@ -2400,7 +2355,7 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou
- posLineStart;
p = pdoc->MovePositionOutsideChar(p + 1 + posLineStart, 1) - posLineStart;
continue;
- } else if (ll->styles[p] != ll->styles[p - 1]) {
+ } else if ((vstyle.wrapState == eWrapWord) && (ll->styles[p] != ll->styles[p - 1])) {
lastGoodBreak = p;
} else if (IsSpaceOrTab(ll->chars[p - 1]) && !IsSpaceOrTab(ll->chars[p])) {
lastGoodBreak = p;
diff --git a/scintilla/src/Editor.h b/scintilla/src/Editor.h
index 6c25c3b..98327dc 100644
--- a/scintilla/src/Editor.h
+++ b/scintilla/src/Editor.h
@@ -412,7 +412,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
xysVertical=0x2,
xysHorizontal=0x4,
xysDefault=xysUseMargin|xysVertical|xysHorizontal};
- XYScrollPosition XYScrollToMakeVisible(const SelectionRange range, const XYScrollOptions options);
+ XYScrollPosition XYScrollToMakeVisible(const SelectionRange &range, const XYScrollOptions options);
void SetXYScroll(XYScrollPosition newXY);
void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);
void ScrollRange(SelectionRange range);
@@ -437,12 +437,12 @@ protected: // ScintillaBase subclass needs access to much of Editor
ColourDesired SelectionBackground(ViewStyle &vsDraw, bool main) const;
ColourDesired TextBackground(ViewStyle &vsDraw, bool overrideBackground, ColourDesired background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll) const;
void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight);
- void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourDesired wrapColour);
+ static void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourDesired wrapColour);
void DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll,
int line, int lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart,
bool overrideBackground, ColourDesired background,
bool drawWrapMark, ColourDesired wrapColour);
- void DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, ViewStyle &vsDraw,
+ static void DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, ViewStyle &vsDraw,
int xStart, PRectangle rcLine, LineLayout *ll, int subLine);
void DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under);
diff --git a/scintilla/src/PerLine.cxx b/scintilla/src/PerLine.cxx
index 8db14aa..27257cd 100644
--- a/scintilla/src/PerLine.cxx
+++ b/scintilla/src/PerLine.cxx
@@ -370,9 +370,9 @@ void LineAnnotation::InsertLine(int line) {
}
void LineAnnotation::RemoveLine(int line) {
- if (annotations.Length() && (line < annotations.Length())) {
- delete []annotations[line];
- annotations.Delete(line);
+ if (annotations.Length() && (line > 0) && (line <= annotations.Length())) {
+ delete []annotations[line-1];
+ annotations.Delete(line-1);
}
}
diff --git a/scintilla/src/PositionCache.cxx b/scintilla/src/PositionCache.cxx
index 3db5a56..5326987 100644
--- a/scintilla/src/PositionCache.cxx
+++ b/scintilla/src/PositionCache.cxx
@@ -43,11 +43,6 @@
using namespace Scintilla;
#endif
-static inline bool IsControlCharacter(int ch) {
- // iscntrl returns true for lots of chars > 127 which are displayable
- return ch >= 0 && ch < ' ';
-}
-
LineLayout::LineLayout(int maxLineLength_) :
lineStarts(0),
lenLineStarts(0),
@@ -132,6 +127,10 @@ int LineLayout::LineLastVisible(int line) const {
}
}
+Range LineLayout::SubLineRange(int subLine) const {
+ return Range(LineStart(subLine), LineLastVisible(subLine));
+}
+
bool LineLayout::InLine(int offset, int line) const {
return ((offset >= LineStart(line)) && (offset < LineStart(line + 1))) ||
((offset == numCharsInLine) && (line == (lines-1)));
@@ -205,6 +204,46 @@ int LineLayout::FindBefore(XYPOSITION x, int lower, int upper) const {
return lower;
}
+
+int LineLayout::FindPositionFromX(XYPOSITION x, Range range, bool charPosition) const {
+ int pos = FindBefore(x, range.start, range.end);
+ while (pos < range.end) {
+ if (charPosition) {
+ if (x < (positions[pos + 1])) {
+ return pos;
+ }
+ } else {
+ if (x < ((positions[pos] + positions[pos + 1]) / 2)) {
+ return pos;
+ }
+ }
+ pos++;
+ }
+ return range.end;
+}
+
+Point LineLayout::PointFromPosition(int posInLine, int lineHeight) const {
+ Point pt;
+ // In case of very long line put x at arbitrary large position
+ if (posInLine > maxLineLength) {
+ pt.x = positions[maxLineLength] - positions[LineStart(lines)];
+ }
+
+ for (int subLine = 0; subLine < lines; subLine++) {
+ const Range rangeSubLine = SubLineRange(subLine);
+ if (posInLine >= rangeSubLine.start) {
+ pt.y = subLine*lineHeight;
+ if (posInLine <= rangeSubLine.end) {
+ pt.x = positions[posInLine] - positions[rangeSubLine.start];
+ if (rangeSubLine.start != 0) // Wrapped lines may be indented
+ pt.x += wrapIndent;
+ break;
+ }
+ }
+ }
+ return pt;
+}
+
int LineLayout::EndLineStyle() const {
return styles[numCharsBeforeEOL > 0 ? numCharsBeforeEOL-1 : 0];
}
diff --git a/scintilla/src/PositionCache.h b/scintilla/src/PositionCache.h
index 9d42229..5739d45 100644
--- a/scintilla/src/PositionCache.h
+++ b/scintilla/src/PositionCache.h
@@ -60,12 +60,15 @@ public:
void Invalidate(validLevel validity_);
int LineStart(int line) const;
int LineLastVisible(int line) const;
+ Range SubLineRange(int line) const;
bool InLine(int offset, int line) const;
void SetLineStart(int line, int start);
void SetBracesHighlight(Range rangeLine, Position braces[],
char bracesMatchStyle, int xHighlight, bool ignoreStyle);
void RestoreBracesHighlight(Range rangeLine, Position braces[], bool ignoreStyle);
int FindBefore(XYPOSITION x, int lower, int upper) const;
+ int FindPositionFromX(XYPOSITION x, Range range, bool charPosition) const;
+ Point PointFromPosition(int posInLine, int lineHeight) const;
int EndLineStyle() const;
};
diff --git a/scintilla/src/ScintillaBase.cxx b/scintilla/src/ScintillaBase.cxx
index d05a6ee..da0bb58 100644
--- a/scintilla/src/ScintillaBase.cxx
+++ b/scintilla/src/ScintillaBase.cxx
@@ -417,16 +417,16 @@ void ScintillaBase::CallTipShow(Point pt, const char *defn) {
// space
PRectangle rcClient = GetClientRectangle();
int offset = vs.lineHeight + rc.Height();
- // adjust so it displays below the text.
- if (rc.top < rcClient.top) {
- rc.top += offset;
- rc.bottom += offset;
- }
// adjust so it displays above the text.
if (rc.bottom > rcClient.bottom) {
rc.top -= offset;
rc.bottom -= offset;
}
+ // adjust so it displays below the text.
+ if (rc.top < rcClient.top) {
+ rc.top += offset;
+ rc.bottom += offset;
+ }
// Now display the window.
CreateCallTipWindow(rc);
ct.wCallTip.SetPositionRelative(rc, wMain);
diff --git a/scintilla/src/ViewStyle.cxx b/scintilla/src/ViewStyle.cxx
index 7571d42..8dfa614 100644
--- a/scintilla/src/ViewStyle.cxx
+++ b/scintilla/src/ViewStyle.cxx
@@ -310,9 +310,9 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) {
styles[i].extraFontFlag = extraFontFlag;
}
- CreateFont(styles[STYLE_DEFAULT]);
+ CreateAndAddFont(styles[STYLE_DEFAULT]);
for (unsigned int j=0; j<styles.size(); j++) {
- CreateFont(styles[j]);
+ CreateAndAddFont(styles[j]);
}
for (FontMap::iterator it = fonts.begin(); it != fonts.end(); ++it) {
@@ -450,6 +450,9 @@ bool ViewStyle::SetWrapState(int wrapState_) {
case SC_WRAP_CHAR:
wrapStateWanted = eWrapChar;
break;
+ case SC_WRAP_WHITESPACE:
+ wrapStateWanted = eWrapWhitespace;
+ break;
default:
wrapStateWanted = eWrapNone;
break;
@@ -495,7 +498,7 @@ void ViewStyle::AllocStyles(size_t sizeNew) {
}
}
-void ViewStyle::CreateFont(const FontSpecification &fs) {
+void ViewStyle::CreateAndAddFont(const FontSpecification &fs) {
if (fs.fontName) {
FontMap::iterator it = fonts.find(fs);
if (it == fonts.end()) {
diff --git a/scintilla/src/ViewStyle.h b/scintilla/src/ViewStyle.h
index 3384f11..21d10b7 100644
--- a/scintilla/src/ViewStyle.h
+++ b/scintilla/src/ViewStyle.h
@@ -56,7 +56,7 @@ enum WhiteSpaceVisibility {wsInvisible=0, wsVisibleAlways=1, wsVisibleAfterInden
typedef std::map<FontSpecification, FontRealised *> FontMap;
-enum WrapMode { eWrapNone, eWrapWord, eWrapChar };
+enum WrapMode { eWrapNone, eWrapWord, eWrapChar, eWrapWhitespace };
class ColourOptional : public ColourDesired {
public:
@@ -178,7 +178,7 @@ public:
private:
void AllocStyles(size_t sizeNew);
- void CreateFont(const FontSpecification &fs);
+ void CreateAndAddFont(const FontSpecification &fs);
FontRealised *Find(const FontSpecification &fs);
void FindMaxAscentDescent();
// Private so can only be copied through copy constructor which ensures font names initialised correctly