diff options
Diffstat (limited to 'src/Editor.cxx')
-rw-r--r-- | src/Editor.cxx | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 5b33f7b2d..f4f4a1b14 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -647,6 +647,25 @@ void Editor::MoveCaretInsideView() { } } +int Editor::DisplayFromPosition(int pos) { + int lineDoc = pdoc->LineFromPosition(pos); + int lineDisplay = cs.DisplayFromDoc(lineDoc); + AutoSurface surface(IsUnicodeMode()); + if (surface) { + unsigned int posLineStart = pdoc->LineStart(lineDoc); + int posInLine = pos - posLineStart; + lineDisplay--; // To make up for first increment ahead. + LineLayout ll; + LayoutLine(lineDoc, surface, vs, ll, wrapWidth); + for (int subLine=0; subLine<ll.lines; subLine++) { + if (posInLine >= ll.lineStarts[subLine]) { + lineDisplay++; + } + } + } + return lineDisplay; +} + void Editor::EnsureCaretVisible(bool useMargin, bool vert, bool horiz) { //Platform::DebugPrintf("EnsureCaretVisible %d %s\n", xOffset, useMargin ? " margin" : " "); PRectangle rcClient = GetTextRectangle(); @@ -657,7 +676,7 @@ void Editor::EnsureCaretVisible(bool useMargin, bool vert, bool horiz) { Point pt = LocationFromPosition(posCaret); Point ptEOL = LocationFromPosition(pdoc->LineEndPosition(posCaret)); Point ptBottomCaret = pt; - int lineCaret = cs.DisplayFromDoc(pdoc->LineFromPosition(posCaret)); + int lineCaret = DisplayFromPosition(posCaret); ptBottomCaret.y += vs.lineHeight - 1; // Ensure the caret is reasonably visible in context: |