aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2000-04-27 14:33:08 +0000
committernyamatongwe <unknown>2000-04-27 14:33:08 +0000
commit1f73a5a6b589ecb8ce375f3c3313d98d7f007ce9 (patch)
treef55b125b60eb6dc353bd0c6bce6f39f2f37e3876
parent7639831370cc8881f906bfe359dd004c7d4bd303 (diff)
downloadscintilla-mirror-1f73a5a6b589ecb8ce375f3c3313d98d7f007ce9.tar.gz
Ctrl+Up and Ctrl+Down now keep the caret visible.
-rw-r--r--src/Editor.cxx20
-rw-r--r--src/Editor.h1
2 files changed, 19 insertions, 2 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index e8e0f755c..bccddf160 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -503,6 +503,19 @@ void Editor::HorizontalScrollTo(int xPos) {
Redraw();
}
+void Editor::MoveCaretInsideView() {
+ PRectangle rcClient = GetTextRectangle();
+ Point pt = LocationFromPosition(currentPos);
+ if (pt.y < rcClient.top) {
+ MovePositionTo(PositionFromLocation(
+ Point(lastXChosen, rcClient.top)));
+ } else if ((pt.y + vs.lineHeight - 1) > rcClient.bottom) {
+ int yOfLastLineFullyDisplayed = rcClient.top + (LinesOnScreen()-1) * vs.lineHeight;
+ MovePositionTo(PositionFromLocation(
+ Point(lastXChosen, rcClient.top + yOfLastLineFullyDisplayed)));
+ }
+}
+
void Editor::EnsureCaretVisible(bool useMargin) {
//Platform::DebugPrintf("EnsureCaretVisible %d\n", xOffset);
PRectangle rcClient = GetTextRectangle();
@@ -1090,9 +1103,10 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) {
// Draw the Caret
if (line == lineCaret) {
- int xposCaret = ll.positions[posCaret - posLineStart] + xStart;
+ int offset = Platform::Minimum(posCaret - posLineStart, LineLayout::maxLineLength);
+ int xposCaret = ll.positions[offset] + xStart;
int widthOverstrikeCaret =
- ll.positions[posCaret - posLineStart + 1] - ll.positions[posCaret - posLineStart];
+ ll.positions[offset + 1] - ll.positions[offset];
if (posCaret == pdoc->Length()) // At end of document
widthOverstrikeCaret = vs.aveCharWidth;
if ((posCaret - posLineStart) >= ll.numCharsInLine) // At end of line
@@ -1829,6 +1843,7 @@ int Editor::KeyCommand(UINT iMessage) {
break;
case SCI_LINESCROLLDOWN:
ScrollTo(topLine + 1);
+ MoveCaretInsideView();
break;
case SCI_LINEUP:
MovePositionTo(PositionFromLocation(
@@ -1840,6 +1855,7 @@ int Editor::KeyCommand(UINT iMessage) {
break;
case SCI_LINESCROLLUP:
ScrollTo(topLine - 1);
+ MoveCaretInsideView();
break;
case SCI_CHARLEFT:
if (SelectionEmpty()) {
diff --git a/src/Editor.h b/src/Editor.h
index f4a9e12cd..808a656be 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -175,6 +175,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
void ScrollTo(int line);
virtual void ScrollText(int linesToMove);
void HorizontalScrollTo(int xPos);
+ void MoveCaretInsideView();
void EnsureCaretVisible(bool useMargin=true);
void ShowCaretAtCurrentPosition();
void DropCaret();