aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Editor.cxx
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2009-07-03 06:36:25 +0000
committernyamatongwe <devnull@localhost>2009-07-03 06:36:25 +0000
commit1d772be5dea42ff8cd8632806589bbc92effec35 (patch)
tree23fca327b0795859289d499439b4d6968810f2a8 /src/Editor.cxx
parent603237d7ed409ff08a0b92aa703be8c6e469795a (diff)
downloadscintilla-mirror-1d772be5dea42ff8cd8632806589bbc92effec35.tar.gz
Use screen point for caret that includes virtual spcace so that, for
example, the IME appears near the caret when the caret is in virtual space. Changed LocationFromPosition to work on a SelectionPosition and added convenience method for finding screen point of main caret.
Diffstat (limited to 'src/Editor.cxx')
-rw-r--r--src/Editor.cxx27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 7af0e7325..0958d8076 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -355,12 +355,12 @@ SelectionPosition Editor::ClampPositionIntoDocument(SelectionPosition sp) const
}
}
-Point Editor::LocationFromPosition(int pos) {
+Point Editor::LocationFromPosition(SelectionPosition pos) {
Point pt;
RefreshStyleData();
- if (pos == INVALID_POSITION)
+ if (pos.Position() == INVALID_POSITION)
return pt;
- int line = pdoc->LineFromPosition(pos);
+ int line = pdoc->LineFromPosition(pos.Position());
int lineVisible = cs.DisplayFromDoc(line);
//Platform::DebugPrintf("line=%d\n", line);
AutoSurface surface(this);
@@ -371,7 +371,7 @@ Point Editor::LocationFromPosition(int pos) {
pt.x = 0;
unsigned int posLineStart = pdoc->LineStart(line);
LayoutLine(line, surface, vs, ll, wrapWidth);
- int posInLine = pos - posLineStart;
+ 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)];
@@ -392,17 +392,22 @@ Point Editor::LocationFromPosition(int pos) {
}
pt.x += vs.fixedColumnWidth - xOffset;
}
+ pt.x += pos.VirtualSpace() * vs.spaceWidth;
return pt;
}
+Point Editor::LocationFromPosition(int pos) {
+ return LocationFromPosition(SelectionPosition(pos));
+}
+
int Editor::XFromPosition(int pos) {
Point pt = LocationFromPosition(pos);
return pt.x - vs.fixedColumnWidth + xOffset;
}
int Editor::XFromPosition(SelectionPosition sp) {
- Point pt = LocationFromPosition(sp.Position());
- return pt.x + sp.VirtualSpace() * vs.spaceWidth - vs.fixedColumnWidth + xOffset;
+ Point pt = LocationFromPosition(sp);
+ return pt.x - vs.fixedColumnWidth + xOffset;
}
int Editor::LineFromLocation(Point pt) {
@@ -896,12 +901,16 @@ SelectionPosition Editor::MovePositionSoVisible(int pos, int moveDir) {
return MovePositionSoVisible(SelectionPosition(pos), moveDir);
}
+Point Editor::PointMainCaret() {
+ return LocationFromPosition(sel.Range(sel.Main()).caret);
+}
+
/**
* Choose the x position that the caret will try to stick to
* as it moves up and down.
*/
void Editor::SetLastXChosen() {
- Point pt = LocationFromPosition(sel.MainCaret());
+ Point pt = PointMainCaret();
lastXChosen = pt.x;
}
@@ -946,7 +955,7 @@ void Editor::HorizontalScrollTo(int xPos) {
void Editor::MoveCaretInsideView(bool ensureVisible) {
PRectangle rcClient = GetTextRectangle();
- Point pt = LocationFromPosition(sel.MainCaret());
+ Point pt = PointMainCaret();
if (pt.y < rcClient.top) {
MovePositionTo(SPositionFromLocation(
Point(lastXChosen, rcClient.top)),
@@ -4521,7 +4530,7 @@ void Editor::NewLine() {
}
void Editor::CursorUpOrDown(int direction, Selection::selTypes selt) {
- Point pt = LocationFromPosition(sel.MainCaret());
+ Point pt = PointMainCaret();
int lineDoc = pdoc->LineFromPosition(sel.MainCaret());
Point ptStartLine = LocationFromPosition(pdoc->LineStart(lineDoc));
int subLine = (pt.y - ptStartLine.y) / vs.lineHeight;