- fix: dragging text from lines in the front to lines back will cause error

- fix: dragging text onto itself should do nothing
This commit is contained in:
Roy Qu 2021-11-26 19:54:05 +08:00
parent ed3f320c50
commit db61432d36
4 changed files with 85 additions and 14 deletions

View File

@ -1,6 +1,8 @@
Version 0.10.2 For Dev-C++ 7 Beta
- fix: select by mouse can't correctly set mouse's column position
- fix: dragging out of the editor and back will cause error
- fix: dragging text from lines in the front to lines back will cause error
- fix: dragging text onto itself should do nothing
Version 0.10.1 For Dev-C++ 7 Beta
- fix: can't correctly expand watch expression that has spaces in it

View File

@ -6203,23 +6203,58 @@ void SynEdit::dragEnterEvent(QDragEnterEvent *event)
void SynEdit::dropEvent(QDropEvent *event)
{
//mScrollTimer->stop();
mUndoList->BeginBlock();
auto action = finally([this] {
mUndoList->EndBlock();
});
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(event->pos().x(),
event->pos().y()));
int topLine = mTopLine;
int leftChar = mLeftChar;
if (event->proposedAction() == Qt::DropAction::MoveAction) {
setBlockBegin(mDragSelBeginSave);
setBlockEnd(mDragSelEndSave);
setSelText("");
}
setTopLine(topLine);
setLeftChar(leftChar);
setCaretXY(coord);
setSelText(event->mimeData()->text());
if (coord>=mDragSelBeginSave && coord<=mDragSelEndSave) {
//do nothing if drag onto itself
} else if (event->proposedAction() == Qt::DropAction::CopyAction) {
//just copy it
setSelText(event->mimeData()->text());
} else if (event->proposedAction() == Qt::DropAction::MoveAction) {
int topLine = mTopLine;
int leftChar = mLeftChar;
mUndoList->BeginBlock();
if (coord < mDragSelBeginSave ) {
//delete old
setBlockBegin(mDragSelBeginSave);
setBlockEnd(mDragSelEndSave);
setSelText("");
//paste to new position
setTopLine(topLine);
setLeftChar(leftChar);
setCaretXY(coord);
setSelText(event->mimeData()->text());
} else {
//paste to new position
setTopLine(topLine);
setLeftChar(leftChar);
setCaretXY(coord);
setSelText(event->mimeData()->text());
//delete old
setBlockBegin(mDragSelBeginSave);
setBlockEnd(mDragSelEndSave);
setSelText("");
//set caret to right pos
if (mDragSelBeginSave.Line == mDragSelEndSave.Line) {
if (coord.Line == mDragSelEndSave.Line) {
coord.Char -= mDragSelEndSave.Char-mDragSelBeginSave.Char;
}
} else {
if (coord.Line == mDragSelEndSave.Line) {
coord.Char -= mDragSelEndSave.Char-1;
} else {
coord.Line -= mDragSelEndSave.Line-mDragSelBeginSave.Line;
topLine -= mDragSelEndSave.Line-mDragSelBeginSave.Line;
}
}
setTopLine(topLine);
setLeftChar(leftChar);
setCaretXY(coord);
}
mUndoList->EndBlock();
}
event->acceptProposedAction();
}

View File

@ -239,3 +239,32 @@ bool BufferCoord::operator==(const BufferCoord &coord)
{
return coord.Char == Char && coord.Line == Line;
}
bool BufferCoord::operator>=(const BufferCoord &coord)
{
return (Line > coord.Line)
|| (Line == coord.Line && Char >= coord.Char);
}
bool BufferCoord::operator>(const BufferCoord &coord)
{
return (Line > coord.Line)
|| (Line == coord.Line && Char > coord.Char);
}
bool BufferCoord::operator<(const BufferCoord &coord)
{
return (Line < coord.Line)
|| (Line == coord.Line && Char < coord.Char);
}
bool BufferCoord::operator<=(const BufferCoord &coord)
{
return (Line < coord.Line)
|| (Line == coord.Line && Char <= coord.Char);
}
bool BufferCoord::operator!=(const BufferCoord &coord)
{
return coord.Char != Char || coord.Line != Line;
}

View File

@ -11,6 +11,11 @@ struct BufferCoord {
int Char;
int Line;
bool operator==(const BufferCoord& coord);
bool operator>=(const BufferCoord& coord);
bool operator>(const BufferCoord& coord);
bool operator<(const BufferCoord& coord);
bool operator<=(const BufferCoord& coord);
bool operator!=(const BufferCoord& coord);
};
class SynEdit;