From 1d772be5dea42ff8cd8632806589bbc92effec35 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Fri, 3 Jul 2009 06:36:25 +0000 Subject: 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. --- src/Editor.cxx | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/Editor.cxx') 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; -- cgit v1.2.3