aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gtk/ScintillaGTK.cxx4
-rw-r--r--src/Editor.cxx27
-rw-r--r--src/Editor.h2
-rw-r--r--src/ScintillaBase.cxx4
-rw-r--r--win32/ScintillaWin.cxx8
5 files changed, 28 insertions, 17 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index 9d7cc02ee..11b466fef 100644
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -2224,7 +2224,7 @@ void ScintillaGTK::PreeditChangedThis() {
gint x, y;
gdk_window_get_origin((PWidget(wText))->window, &x, &y);
- Point pt = LocationFromPosition(sel.MainCaret());
+ Point pt = PointMainCaret();
if (pt.x < 0)
pt.x = 0;
if (pt.y < 0)
@@ -2311,7 +2311,7 @@ void ScintillaGTK::Draw(GtkWidget *widget, GdkRectangle *area) {
}
#ifdef INTERNATIONAL_INPUT
- Point pt = sciThis->LocationFromPosition(sciThis->sel.MainCaret());
+ Point pt = sciThis->PointMainCaret();
pt.y += sciThis->vs.lineHeight - 2;
if (pt.x < 0) pt.x = 0;
if (pt.y < 0) pt.y = 0;
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 7af0e7325..0958d8076 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -355,12 +355,12 @@ SelectionPosition Editor::ClampPositionIntoDocument(SelectionPosition sp) const
}
}
-Point Editor::LocationFromPosition(int pos) {
+Point Editor::LocationFromPosition(SelectionPosition pos) {
Point pt;
RefreshStyleData();
- if (pos == INVALID_POSITION)
+ if (pos.Position() == INVALID_POSITION)
return pt;
- int line = pdoc->LineFromPosition(pos);
+ int line = pdoc->LineFromPosition(pos.Position());
int lineVisible = cs.DisplayFromDoc(line);
//Platform::DebugPrintf("line=%d\n", line);
AutoSurface surface(this);
@@ -371,7 +371,7 @@ Point Editor::LocationFromPosition(int pos) {
pt.x = 0;
unsigned int posLineStart = pdoc->LineStart(line);
LayoutLine(line, surface, vs, ll, wrapWidth);
- int posInLine = pos - posLineStart;
+ int posInLine = pos.Position() - posLineStart;
// In case of very long line put x at arbitrary large position
if (posInLine > ll->maxLineLength) {
pt.x = ll->positions[ll->maxLineLength] - ll->positions[ll->LineStart(ll->lines)];
@@ -392,17 +392,22 @@ Point Editor::LocationFromPosition(int pos) {
}
pt.x += vs.fixedColumnWidth - xOffset;
}
+ pt.x += pos.VirtualSpace() * vs.spaceWidth;
return pt;
}
+Point Editor::LocationFromPosition(int pos) {
+ return LocationFromPosition(SelectionPosition(pos));
+}
+
int Editor::XFromPosition(int pos) {
Point pt = LocationFromPosition(pos);
return pt.x - vs.fixedColumnWidth + xOffset;
}
int Editor::XFromPosition(SelectionPosition sp) {
- Point pt = LocationFromPosition(sp.Position());
- return pt.x + sp.VirtualSpace() * vs.spaceWidth - vs.fixedColumnWidth + xOffset;
+ Point pt = LocationFromPosition(sp);
+ return pt.x - vs.fixedColumnWidth + xOffset;
}
int Editor::LineFromLocation(Point pt) {
@@ -896,12 +901,16 @@ SelectionPosition Editor::MovePositionSoVisible(int pos, int moveDir) {
return MovePositionSoVisible(SelectionPosition(pos), moveDir);
}
+Point Editor::PointMainCaret() {
+ return LocationFromPosition(sel.Range(sel.Main()).caret);
+}
+
/**
* Choose the x position that the caret will try to stick to
* as it moves up and down.
*/
void Editor::SetLastXChosen() {
- Point pt = LocationFromPosition(sel.MainCaret());
+ Point pt = PointMainCaret();
lastXChosen = pt.x;
}
@@ -946,7 +955,7 @@ void Editor::HorizontalScrollTo(int xPos) {
void Editor::MoveCaretInsideView(bool ensureVisible) {
PRectangle rcClient = GetTextRectangle();
- Point pt = LocationFromPosition(sel.MainCaret());
+ Point pt = PointMainCaret();
if (pt.y < rcClient.top) {
MovePositionTo(SPositionFromLocation(
Point(lastXChosen, rcClient.top)),
@@ -4521,7 +4530,7 @@ void Editor::NewLine() {
}
void Editor::CursorUpOrDown(int direction, Selection::selTypes selt) {
- Point pt = LocationFromPosition(sel.MainCaret());
+ Point pt = PointMainCaret();
int lineDoc = pdoc->LineFromPosition(sel.MainCaret());
Point ptStartLine = LocationFromPosition(pdoc->LineStart(lineDoc));
int subLine = (pt.y - ptStartLine.y) / vs.lineHeight;
diff --git a/src/Editor.h b/src/Editor.h
index ab1e9a1e8..68580fdaa 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -258,6 +258,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
int LinesToScroll();
int MaxScrollPos();
SelectionPosition ClampPositionIntoDocument(SelectionPosition sp) const;
+ Point LocationFromPosition(SelectionPosition pos);
Point LocationFromPosition(int pos);
int XFromPosition(int pos);
int XFromPosition(SelectionPosition sp);
@@ -295,6 +296,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
int MovePositionTo(int newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true);
SelectionPosition MovePositionSoVisible(SelectionPosition pos, int moveDir);
SelectionPosition MovePositionSoVisible(int pos, int moveDir);
+ Point PointMainCaret();
void SetLastXChosen();
void ScrollTo(int line, bool moveThumb=true);
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index b47986ff0..0a8912c7b 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -226,7 +226,7 @@ void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) {
return;
}
}
- ac.Start(wMain, idAutoComplete, sel.MainCaret(), LocationFromPosition(sel.MainCaret()),
+ ac.Start(wMain, idAutoComplete, sel.MainCaret(), PointMainCaret(),
lenEntered, vs.lineHeight, IsUnicodeMode());
PRectangle rcClient = GetClientRectangle();
@@ -240,7 +240,7 @@ void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) {
if (pt.x >= rcClient.right - widthLB) {
HorizontalScrollTo(xOffset + pt.x - rcClient.right + widthLB);
Redraw();
- pt = LocationFromPosition(sel.MainCaret());
+ pt = PointMainCaret();
}
PRectangle rcac;
rcac.left = pt.x - ac.lb->CaretFromEdge();
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index 9c8036aa9..248ae0d3d 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -524,7 +524,7 @@ sptr_t ScintillaWin::HandleComposition(uptr_t wParam, sptr_t lParam) {
}
}
// Set new position after converted
- Point pos = LocationFromPosition(sel.MainCaret());
+ Point pos = PointMainCaret();
COMPOSITIONFORM CompForm;
CompForm.dwStyle = CFS_POINT;
CompForm.ptCurrentPos.x = pos.x;
@@ -904,7 +904,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam
Point pt = Point::FromLong(lParam);
if ((pt.x == -1) && (pt.y == -1)) {
// Caused by keyboard so display menu near caret
- pt = LocationFromPosition(sel.MainCaret());
+ pt = PointMainCaret();
POINT spt = {pt.x, pt.y};
::ClientToScreen(MainHWND(), &spt);
pt = Point(spt.x, spt.y);
@@ -1136,7 +1136,7 @@ void ScintillaWin::UpdateSystemCaret() {
DestroySystemCaret();
CreateSystemCaret();
}
- Point pos = LocationFromPosition(sel.MainCaret());
+ Point pos = PointMainCaret();
::SetCaretPos(pos.x, pos.y);
}
}
@@ -1817,7 +1817,7 @@ void ScintillaWin::ImeStartComposition() {
if (caret.active) {
// Move IME Window to current caret position
HIMC hIMC = ::ImmGetContext(MainHWND());
- Point pos = LocationFromPosition(sel.MainCaret());
+ Point pos = PointMainCaret();
COMPOSITIONFORM CompForm;
CompForm.dwStyle = CFS_POINT;
CompForm.ptCurrentPos.x = pos.x;