aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <unknown>2002-04-12 07:16:37 +0000
committernyamatongwe <unknown>2002-04-12 07:16:37 +0000
commitef382da486d078384a8702f8000dfe30289d0158 (patch)
treec1589b7f4137339b0b304eeb1598d3200edf6fc3 /src
parent360f015654b229a8e92d4ea9bae8520ab48363c9 (diff)
downloadscintilla-mirror-ef382da486d078384a8702f8000dfe30289d0158.tar.gz
Fixed problem where caret would not move to previous line due to wrapping.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx30
-rw-r--r--src/Editor.h1
2 files changed, 22 insertions, 9 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 00bdfcf57..db5fe54b5 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -2887,29 +2887,41 @@ void Editor::NewLine() {
EnsureCaretVisible();
}
-int Editor::KeyCommand(unsigned int iMessage) {
+void Editor::CursorUpOrDown(int direction, bool extend) {
Point pt = LocationFromPosition(currentPos);
+ int posNew = PositionFromLocation(
+ Point(lastXChosen, pt.y + direction * vs.lineHeight));
+ if (direction < 0) {
+ // Line wrapping may lead to a location on the same line, so
+ // seek back if that is the case.
+ // There is an equivalent case when moving down which skips
+ // over a line but as that does not trap the user it is fine.
+ Point ptNew = LocationFromPosition(posNew);
+ while ((posNew > 0) && (pt.y == ptNew.y)) {
+ posNew--;
+ ptNew = LocationFromPosition(posNew);
+ }
+ }
+ MovePositionTo(posNew, extend);
+}
+int Editor::KeyCommand(unsigned int iMessage) {
switch (iMessage) {
case SCI_LINEDOWN:
- MovePositionTo(PositionFromLocation(
- Point(lastXChosen, pt.y + vs.lineHeight)));
+ CursorUpOrDown(1);
break;
case SCI_LINEDOWNEXTEND:
- MovePositionTo(PositionFromLocation(
- Point(lastXChosen, pt.y + vs.lineHeight)), true);
+ CursorUpOrDown(1, true);
break;
case SCI_LINESCROLLDOWN:
ScrollTo(topLine + 1);
MoveCaretInsideView();
break;
case SCI_LINEUP:
- MovePositionTo(PositionFromLocation(
- Point(lastXChosen, pt.y - vs.lineHeight)));
+ CursorUpOrDown(-1);
break;
case SCI_LINEUPEXTEND:
- MovePositionTo(PositionFromLocation(
- Point(lastXChosen, pt.y - vs.lineHeight)), true);
+ CursorUpOrDown(-1, true);
break;
case SCI_LINESCROLLUP:
ScrollTo(topLine - 1);
diff --git a/src/Editor.h b/src/Editor.h
index 5a82f32ff..353e4ee9f 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -400,6 +400,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
void LineTranspose();
virtual void CancelModes();
void NewLine();
+ void CursorUpOrDown(int direction, bool extend=false);
virtual int KeyCommand(unsigned int iMessage);
virtual int KeyDefault(int /* key */, int /*modifiers*/);
int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0);