aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2010-10-20 16:03:21 +1100
committernyamatongwe <devnull@localhost>2010-10-20 16:03:21 +1100
commit1d801fba7580276f1a91af5019d5d2ac59372a37 (patch)
tree45f8662892a932b7cd329fddb97302f66ac2c60a
parentfbc89848986b94a84e1011b11d16d83f5a09c881 (diff)
downloadscintilla-mirror-1d801fba7580276f1a91af5019d5d2ac59372a37.tar.gz
Feature request #3064696 SCI_VERTICALCENTRECARET: center current line in window.
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface5
-rw-r--r--src/Editor.cxx17
-rw-r--r--src/Editor.h3
4 files changed, 23 insertions, 3 deletions
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 331216979..0e1159b53 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -787,6 +787,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_SWAPMAINANCHORCARET 2607
#define SCI_CHANGELEXERSTATE 2617
#define SCI_CONTRACTEDFOLDNEXT 2618
+#define SCI_VERTICALCENTRECARET 2619
#define SCI_STARTRECORD 3001
#define SCI_STOPRECORD 3002
#define SCI_SETLEXER 4001
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index a8ef722a0..61031398c 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -259,7 +259,7 @@ val SC_MARK_CIRCLEPLUSCONNECTED=19
val SC_MARK_CIRCLEMINUS=20
val SC_MARK_CIRCLEMINUSCONNECTED=21
-# Invisible mark that only sets the line background color.
+# Invisible mark that only sets the line background colour.
val SC_MARK_BACKGROUND=22
val SC_MARK_DOTDOTDOT=23
val SC_MARK_ARROWS=24
@@ -2095,6 +2095,9 @@ fun int ChangeLexerState=2617(position start, position end)
# Return -1 when no more lines.
fun int ContractedFoldNext=2618(int lineStart,)
+# Centre current line in window.
+fun void VerticalCentreCaret=2619(,)
+
# Start notifying the container of all key presses and commands.
fun void StartRecord=3001(,)
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 681cb12cd..c03ff8f31 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -995,6 +995,16 @@ void Editor::HorizontalScrollTo(int xPos) {
}
}
+void Editor::VerticalCentreCaret() {
+ int lineDoc = pdoc->LineFromPosition(sel.IsRectangular() ? sel.Rectangular().caret.Position() : sel.MainCaret());
+ int lineDisplay = cs.DisplayFromDoc(lineDoc);
+ int newTop = lineDisplay - (LinesOnScreen() / 2);
+ if (topLine != newTop) {
+ SetTopLine(newTop > 0 ? newTop : 0);
+ RedrawRect(GetClientRectangle());
+ }
+}
+
void Editor::MoveCaretInsideView(bool ensureVisible) {
PRectangle rcClient = GetTextRectangle();
Point pt = PointMainCaret();
@@ -4589,6 +4599,7 @@ void Editor::NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lPar
case SCI_PAGEDOWNRECTEXTEND:
case SCI_SELECTIONDUPLICATE:
case SCI_COPYALLOWLINE:
+ case SCI_VERTICALCENTRECARET:
break;
// Filter out all others like display changes. Also, newlines are redundant
@@ -6319,7 +6330,7 @@ void Editor::StyleToPositionInView(Position pos) {
int styleAtEnd = pdoc->StyleAt(pos-1);
pdoc->EnsureStyledTo(pos);
if ((endWindow > pos) && (styleAtEnd != pdoc->StyleAt(pos-1))) {
- // Style at end of line changed so is multi-line change like starting a comment
+ // Style at end of line changed so is multi-line change like starting a comment
// so require rest of window to be styled.
pdoc->EnsureStyledTo(endWindow);
}
@@ -6794,6 +6805,10 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
CopyAllowLine();
break;
+ case SCI_VERTICALCENTRECARET:
+ VerticalCentreCaret();
+ break;
+
case SCI_COPYRANGE:
CopyRangeToClipboard(wParam, lParam);
break;
diff --git a/src/Editor.h b/src/Editor.h
index 17683c63a..50948e2e3 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -219,7 +219,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
PRectangle rcPaint;
bool paintingAllText;
StyleNeeded styleNeeded;
-
+
int modEventMask;
SelectionText drag;
@@ -328,6 +328,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
void ScrollTo(int line, bool moveThumb=true);
virtual void ScrollText(int linesToMove);
void HorizontalScrollTo(int xPos);
+ void VerticalCentreCaret();
void MoveCaretInsideView(bool ensureVisible=true);
int DisplayFromPosition(int pos);