- fix: calculation of caret position is not in consistence.
This commit is contained in:
parent
dafac73e12
commit
1b8f3de21f
1
NEWS.md
1
NEWS.md
|
@ -17,6 +17,7 @@ Red Panda C++ Version 0.14.5
|
||||||
- enhancement: add option "mouse selection/drag scroll speed" in the options dialog's "Editor" / "general" tab.
|
- enhancement: add option "mouse selection/drag scroll speed" in the options dialog's "Editor" / "general" tab.
|
||||||
- fix: the scroll speed of mouse selection/drag is too fast.
|
- fix: the scroll speed of mouse selection/drag is too fast.
|
||||||
- fix: the scroll behavior of mouse dragging on the editor's edge is not correct
|
- fix: the scroll behavior of mouse dragging on the editor's edge is not correct
|
||||||
|
- fix: calculation of caret position is not in consistence.
|
||||||
|
|
||||||
Red Panda C++ Version 0.14.4
|
Red Panda C++ Version 0.14.4
|
||||||
- enhancement: git - log
|
- enhancement: git - log
|
||||||
|
|
|
@ -672,22 +672,6 @@ void SynEdit::invalidateGutterLines(int FirstLine, int LastLine)
|
||||||
* @param aY
|
* @param aY
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
DisplayCoord SynEdit::pixelsToNearestRowColumn(int aX, int aY) const
|
|
||||||
{
|
|
||||||
// Result is in display coordinates
|
|
||||||
float f;
|
|
||||||
f = (aX - mGutterWidth - 2.0) / mCharWidth;
|
|
||||||
// don't return a partially visible last line
|
|
||||||
if (aY >= mLinesInWindow * mTextHeight) {
|
|
||||||
aY = mLinesInWindow * mTextHeight - 1;
|
|
||||||
}
|
|
||||||
if (aY < 0)
|
|
||||||
aY = 0;
|
|
||||||
return {
|
|
||||||
std::max(1, (int)(leftChar() + round(f))),
|
|
||||||
std::max(1, mTopLine + (aY / mTextHeight))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
DisplayCoord SynEdit::pixelsToRowColumn(int aX, int aY) const
|
DisplayCoord SynEdit::pixelsToRowColumn(int aX, int aY) const
|
||||||
{
|
{
|
||||||
|
@ -1838,7 +1822,7 @@ void SynEdit::doMouseScroll(bool isDragging)
|
||||||
} else
|
} else
|
||||||
setBlockEnd(caretXY());
|
setBlockEnd(caretXY());
|
||||||
}
|
}
|
||||||
computeScroll(iMousePos.x(), iMousePos.y(),isDragging);
|
computeScroll(isDragging);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEdit::doDeleteLastChar()
|
void SynEdit::doDeleteLastChar()
|
||||||
|
@ -2482,15 +2466,25 @@ void SynEdit::clearAreaList(SynEditingAreaList areaList)
|
||||||
areaList.clear();
|
areaList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEdit::computeCaret(int X, int Y)
|
void SynEdit::computeCaret()
|
||||||
{
|
{
|
||||||
DisplayCoord vCaretNearestPos = pixelsToNearestRowColumn(X, Y);
|
QPoint iMousePos = QCursor::pos();
|
||||||
|
iMousePos = mapFromGlobal(iMousePos);
|
||||||
|
int X=iMousePos.x();
|
||||||
|
int Y=iMousePos.y();
|
||||||
|
|
||||||
|
DisplayCoord vCaretNearestPos = pixelsToRowColumn(X, Y);
|
||||||
vCaretNearestPos.Row = minMax(vCaretNearestPos.Row, 1, displayLineCount());
|
vCaretNearestPos.Row = minMax(vCaretNearestPos.Row, 1, displayLineCount());
|
||||||
setInternalDisplayXY(vCaretNearestPos);
|
setInternalDisplayXY(vCaretNearestPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEdit::computeScroll(int X, int Y, bool isDragging)
|
void SynEdit::computeScroll(bool isDragging)
|
||||||
{
|
{
|
||||||
|
QPoint iMousePos = QCursor::pos();
|
||||||
|
iMousePos = mapFromGlobal(iMousePos);
|
||||||
|
int X=iMousePos.x();
|
||||||
|
int Y=iMousePos.y();
|
||||||
|
|
||||||
Qt::MouseButtons buttons = qApp->mouseButtons();
|
Qt::MouseButtons buttons = qApp->mouseButtons();
|
||||||
if (!buttons.testFlag(Qt::LeftButton))
|
if (!buttons.testFlag(Qt::LeftButton))
|
||||||
return;
|
return;
|
||||||
|
@ -2529,6 +2523,7 @@ void SynEdit::computeScroll(int X, int Y, bool isDragging)
|
||||||
// mScrollDeltaY = 0;
|
// mScrollDeltaY = 0;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// if (mScrollDeltaX!=0 || mScrollDeltaY!=0) {
|
// if (mScrollDeltaX!=0 || mScrollDeltaY!=0) {
|
||||||
if (isDragging) {
|
if (isDragging) {
|
||||||
mScrollTimer->singleShot(100,this,&SynEdit::onDraggingScrollTimeout);
|
mScrollTimer->singleShot(100,this,&SynEdit::onDraggingScrollTimeout);
|
||||||
|
@ -5882,7 +5877,7 @@ void SynEdit::mousePressEvent(QMouseEvent *event)
|
||||||
|| ! selAvail())) {
|
|| ! selAvail())) {
|
||||||
invalidateSelection();
|
invalidateSelection();
|
||||||
mBlockEnd=mBlockBegin;
|
mBlockEnd=mBlockBegin;
|
||||||
computeCaret(X,Y);
|
computeCaret();
|
||||||
}else {
|
}else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5892,7 +5887,7 @@ void SynEdit::mousePressEvent(QMouseEvent *event)
|
||||||
bWasSel = true;
|
bWasSel = true;
|
||||||
mMouseDownPos = event->pos();
|
mMouseDownPos = event->pos();
|
||||||
}
|
}
|
||||||
computeCaret(X,Y);
|
computeCaret();
|
||||||
//I couldn't track down why, but sometimes (and definitely not all the time)
|
//I couldn't track down why, but sometimes (and definitely not all the time)
|
||||||
//the block positioning is lost. This makes sure that the block is
|
//the block positioning is lost. This makes sure that the block is
|
||||||
//maintained in case they started a drag operation on the block
|
//maintained in case they started a drag operation on the block
|
||||||
|
@ -5922,7 +5917,7 @@ void SynEdit::mousePressEvent(QMouseEvent *event)
|
||||||
//Selection mode must be set before calling SetBlockBegin
|
//Selection mode must be set before calling SetBlockBegin
|
||||||
setBlockBegin(caretXY());
|
setBlockBegin(caretXY());
|
||||||
}
|
}
|
||||||
computeScroll(X,Y,false);
|
computeScroll(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5944,7 +5939,7 @@ void SynEdit::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
|
||||||
if (mStateFlags.testFlag(SynStateFlag::sfWaitForDragging) &&
|
if (mStateFlags.testFlag(SynStateFlag::sfWaitForDragging) &&
|
||||||
!mStateFlags.testFlag(SynStateFlag::sfDblClicked)) {
|
!mStateFlags.testFlag(SynStateFlag::sfDblClicked)) {
|
||||||
computeCaret(X, Y);
|
computeCaret();
|
||||||
if (! (event->modifiers() & Qt::ShiftModifier))
|
if (! (event->modifiers() & Qt::ShiftModifier))
|
||||||
setBlockBegin(caretXY());
|
setBlockBegin(caretXY());
|
||||||
setBlockEnd(caretXY());
|
setBlockEnd(caretXY());
|
||||||
|
@ -5958,8 +5953,8 @@ void SynEdit::mouseMoveEvent(QMouseEvent *event)
|
||||||
QAbstractScrollArea::mouseMoveEvent(event);
|
QAbstractScrollArea::mouseMoveEvent(event);
|
||||||
mMouseMoved = true;
|
mMouseMoved = true;
|
||||||
Qt::MouseButtons buttons = event->buttons();
|
Qt::MouseButtons buttons = event->buttons();
|
||||||
int X=event->pos().x();
|
// int X=event->pos().x();
|
||||||
int Y=event->pos().y();
|
// int Y=event->pos().y();
|
||||||
if ((mStateFlags.testFlag(SynStateFlag::sfWaitForDragging))) {
|
if ((mStateFlags.testFlag(SynStateFlag::sfWaitForDragging))) {
|
||||||
if ( ( event->pos() - mMouseDownPos).manhattanLength()>=QApplication::startDragDistance()) {
|
if ( ( event->pos() - mMouseDownPos).manhattanLength()>=QApplication::startDragDistance()) {
|
||||||
mStateFlags.setFlag(SynStateFlag::sfWaitForDragging,false);
|
mStateFlags.setFlag(SynStateFlag::sfWaitForDragging,false);
|
||||||
|
@ -5976,14 +5971,14 @@ void SynEdit::mouseMoveEvent(QMouseEvent *event)
|
||||||
} else if ((buttons == Qt::LeftButton)) {
|
} else if ((buttons == Qt::LeftButton)) {
|
||||||
// should we begin scrolling?
|
// should we begin scrolling?
|
||||||
//computeScroll(X, Y,false);
|
//computeScroll(X, Y,false);
|
||||||
DisplayCoord P = pixelsToNearestRowColumn(X, Y);
|
// DisplayCoord P = pixelsToNearestRowColumn(X, Y);
|
||||||
P.Row = minMax(P.Row, 1, displayLineCount());
|
// P.Row = minMax(P.Row, 1, displayLineCount());
|
||||||
if (mScrollDeltaX != 0)
|
// if (mScrollDeltaX != 0)
|
||||||
P.Column = displayX();
|
// P.Column = displayX();
|
||||||
if (mScrollDeltaY != 0)
|
// if (mScrollDeltaY != 0)
|
||||||
P.Row = displayY();
|
// P.Row = displayY();
|
||||||
internalSetCaretXY(displayToBufferPos(P));
|
// internalSetCaretXY(displayToBufferPos(P));
|
||||||
setBlockEnd(caretXY());
|
// setBlockEnd(caretXY());
|
||||||
} else if (buttons == Qt::NoButton) {
|
} else if (buttons == Qt::NoButton) {
|
||||||
updateMouseCursor();
|
updateMouseCursor();
|
||||||
}
|
}
|
||||||
|
@ -6081,14 +6076,13 @@ void SynEdit::dragEnterEvent(QDragEnterEvent *event)
|
||||||
mDragCaretSave = caretXY();
|
mDragCaretSave = caretXY();
|
||||||
mDragSelBeginSave = blockBegin();
|
mDragSelBeginSave = blockBegin();
|
||||||
mDragSelEndSave = blockEnd();
|
mDragSelEndSave = blockEnd();
|
||||||
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(event->pos().x(),
|
BufferCoord coord = displayToBufferPos(pixelsToRowColumn(event->pos().x(),
|
||||||
event->pos().y()));
|
event->pos().y()));
|
||||||
internalSetCaretXY(coord);
|
internalSetCaretXY(coord);
|
||||||
setBlockBegin(mDragSelBeginSave);
|
setBlockBegin(mDragSelBeginSave);
|
||||||
setBlockEnd(mDragSelEndSave);
|
setBlockEnd(mDragSelEndSave);
|
||||||
showCaret();
|
showCaret();
|
||||||
computeScroll(event->pos().x(),
|
computeScroll(true);
|
||||||
event->pos().y(),true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6096,7 +6090,7 @@ void SynEdit::dropEvent(QDropEvent *event)
|
||||||
{
|
{
|
||||||
//mScrollTimer->stop();
|
//mScrollTimer->stop();
|
||||||
|
|
||||||
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(event->pos().x(),
|
BufferCoord coord = displayToBufferPos(pixelsToRowColumn(event->pos().x(),
|
||||||
event->pos().y()));
|
event->pos().y()));
|
||||||
setCaretXY(coord);
|
setCaretXY(coord);
|
||||||
if (coord>=mDragSelBeginSave && coord<=mDragSelEndSave) {
|
if (coord>=mDragSelBeginSave && coord<=mDragSelEndSave) {
|
||||||
|
@ -6162,8 +6156,11 @@ void SynEdit::dragMoveEvent(QDragMoveEvent *event)
|
||||||
// computeScroll(event->pos().x(),
|
// computeScroll(event->pos().x(),
|
||||||
// event->pos().y(),true);
|
// event->pos().y(),true);
|
||||||
|
|
||||||
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(event->pos().x(),
|
QPoint iMousePos = QCursor::pos();
|
||||||
event->pos().y()));
|
iMousePos = mapFromGlobal(iMousePos);
|
||||||
|
int X=iMousePos.x();
|
||||||
|
int Y=iMousePos.y();
|
||||||
|
BufferCoord coord = displayToBufferPos(pixelsToRowColumn(X,Y));
|
||||||
internalSetCaretXY(coord);
|
internalSetCaretXY(coord);
|
||||||
setBlockBegin(mDragSelBeginSave);
|
setBlockBegin(mDragSelBeginSave);
|
||||||
setBlockEnd(mDragSelEndSave);
|
setBlockEnd(mDragSelEndSave);
|
||||||
|
|
|
@ -177,7 +177,6 @@ public:
|
||||||
void invalidateGutter();
|
void invalidateGutter();
|
||||||
void invalidateGutterLine(int aLine);
|
void invalidateGutterLine(int aLine);
|
||||||
void invalidateGutterLines(int FirstLine, int LastLine);
|
void invalidateGutterLines(int FirstLine, int LastLine);
|
||||||
DisplayCoord pixelsToNearestRowColumn(int aX, int aY) const;
|
|
||||||
DisplayCoord pixelsToRowColumn(int aX, int aY) const;
|
DisplayCoord pixelsToRowColumn(int aX, int aY) const;
|
||||||
QPoint rowColumnToPixels(const DisplayCoord& coord) const;
|
QPoint rowColumnToPixels(const DisplayCoord& coord) const;
|
||||||
DisplayCoord bufferToDisplayPos(const BufferCoord& p) const;
|
DisplayCoord bufferToDisplayPos(const BufferCoord& p) const;
|
||||||
|
@ -451,8 +450,8 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clearAreaList(SynEditingAreaList areaList);
|
void clearAreaList(SynEditingAreaList areaList);
|
||||||
void computeCaret(int X, int Y);
|
void computeCaret();
|
||||||
void computeScroll(int X, int Y, bool isDragging);
|
void computeScroll(bool isDragging);
|
||||||
|
|
||||||
void incPaintLock();
|
void incPaintLock();
|
||||||
void decPaintLock();
|
void decPaintLock();
|
||||||
|
|
Loading…
Reference in New Issue