Skip to content

Commit

Permalink
Center caret line in editor window when ensure selection is visible, …
Browse files Browse the repository at this point in the history
…issue #876.
  • Loading branch information
zufuliu committed Oct 13, 2024
1 parent 81b5c06 commit 08020fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4332,19 +4332,20 @@ void EditJumpTo(Sci_Line iNewLine, Sci_Position iNewCol) noexcept {
//
void EditSelectEx(Sci_Position iAnchorPos, Sci_Position iCurrentPos) noexcept {
const Sci_Line iNewLine = SciCall_LineFromPosition(iCurrentPos);
const Sci_Line iAnchorLine = (iAnchorPos == iCurrentPos)? iNewLine : SciCall_LineFromPosition(iAnchorPos);

SciCall_EnsureVisible(iAnchorLine);
if (iAnchorLine == iNewLine) {
// TODO: center current line on screen when it's not visible
} else {
if (iAnchorPos != iCurrentPos) {
const Sci_Line iAnchorLine = SciCall_LineFromPosition(iAnchorPos);
// Ensure that the first and last lines of a selection are always unfolded
// This needs to be done *before* the SciCall_SetSel() message
SciCall_EnsureVisible(iNewLine);
if (iAnchorLine != iNewLine) {
SciCall_EnsureVisible(iAnchorLine);
}
}

SciCall_SetXCaretPolicy(CARET_SLOP | CARET_STRICT | CARET_EVEN, 50);
SciCall_SetYCaretPolicy(CARET_SLOP | CARET_STRICT | CARET_EVEN, 5);
// center current line on screen when it's not visible
SciCall_EnsureVisibleEnforcePolicy(iNewLine);
if (iAnchorPos == iCurrentPos) {
SciCall_GotoPos(iAnchorPos);
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/SciCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,10 @@ inline void SciCall_EnsureVisible(Sci_Line line) noexcept {
SciCall(SCI_ENSUREVISIBLE, line, 0);
}

inline void SciCall_EnsureVisibleEnforcePolicy(Sci_Line line) noexcept {
SciCall(SCI_ENSUREVISIBLEENFORCEPOLICY, line, 0);
}

// Line wrapping

inline void SciCall_SetWrapMode(int wrapMode) noexcept {
Expand Down

0 comments on commit 08020fe

Please sign in to comment.