- change: only auto complete symbol '(' when at line end, or there are spaces or right ')' '}' ']'after it

- fix: mouse drag may fail when start drag at the right half of the selection's last character
This commit is contained in:
Roy Qu 2022-03-31 19:36:46 +08:00
parent f0c0197380
commit f7a6db7005
4 changed files with 32 additions and 10 deletions

View File

@ -20,6 +20,8 @@ Red Panda C++ Version 1.0.2
- fix: vector vars can't be expanded in the watch panel
- change: use qt's mingw 8.1 (32bit) and 11.2 (64bit) in distributions, to provide better compatibility with simplified chinese windows.
- fix: crash when rename an openned file, and choose "no" when ask if keep the editor open
- change: only auto complete symbol '(' when at line end, or there are spaces or right ')' '}' ']'after it
- fix: mouse drag may fail when start drag at the right half of the selection's last character
Red Panda C++ Version 1.0.1
- fix: only convert project icon file when it's filename doesn't end with ".ico"

View File

@ -554,6 +554,10 @@ void Editor::focusOutEvent(QFocusEvent *event)
pMainWindow->functionTip()->hide();
}
static bool isSpaceOrRightParenthesis(const QChar& ch) {
return ch.isSpace() || ch==')' || ch=="]" || ch=="}";
}
void Editor::keyPressEvent(QKeyEvent *event)
{
bool handled = false;
@ -784,7 +788,6 @@ void Editor::keyPressEvent(QKeyEvent *event)
switch (ch.unicode()) {
case '"':
case '\'':
case '(':
case ')':
case '{':
case '}':
@ -794,6 +797,13 @@ void Editor::keyPressEvent(QKeyEvent *event)
case '*':
handled = handleSymbolCompletion(ch);
return;
case '(':
if (caretX()-1>=lineText().length()
|| caretX()<=0
|| isSpaceOrRightParenthesis(lineText().at(caretX()-1))) {
handled = handleSymbolCompletion(ch);
}
return;
case '>':
if ((caretX() <= 1) || lineText().isEmpty()
|| lineText()[caretX() - 2] != '-') {

View File

@ -608,7 +608,7 @@ bool SynEdit::pointToCharLine(const QPoint &point, BufferCoord &coord)
return false;
}
coord = displayToBufferPos(pixelsToRowColumn(point.x(),point.y()));
coord = displayToBufferPos(pixelsToNearestRowColumn(point.x(),point.y()));
return true;
}
@ -622,7 +622,7 @@ bool SynEdit::pointToLine(const QPoint &point, int &line)
return false;
}
BufferCoord coord = displayToBufferPos(pixelsToRowColumn(point.x(),point.y()));
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(point.x(),point.y()));
line = coord.Line;
return true;
}
@ -684,7 +684,7 @@ void SynEdit::invalidateGutterLines(int FirstLine, int LastLine)
* @return
*/
DisplayCoord SynEdit::pixelsToRowColumn(int aX, int aY) const
DisplayCoord SynEdit::pixelsToNearestRowColumn(int aX, int aY) const
{
return {
std::max(1, (int)(mLeftChar + round((aX - mGutterWidth - 2.0) / mCharWidth))),
@ -692,6 +692,15 @@ DisplayCoord SynEdit::pixelsToRowColumn(int aX, int aY) const
};
}
DisplayCoord SynEdit::pixelsToRowColumn(int aX, int aY) const
{
return {
std::max(1, (int)(mLeftChar + (aX - mGutterWidth - 2.0) / mCharWidth)),
std::max(1, mTopLine + (aY / mTextHeight))
};
}
QPoint SynEdit::rowColumnToPixels(const DisplayCoord &coord) const
{
QPoint result;
@ -1125,7 +1134,7 @@ void SynEdit::processGutterClick(QMouseEvent *event)
{
int X = event->pos().x();
int Y = event->pos().y();
DisplayCoord RowColumn = pixelsToRowColumn(X, Y);
DisplayCoord RowColumn = pixelsToNearestRowColumn(X, Y);
int Line = rowToLine(RowColumn.Row);
// Check if we clicked on a folding thing
@ -1843,7 +1852,7 @@ void SynEdit::doMouseScroll(bool isDragging)
iMousePos = QCursor::pos();
iMousePos = mapFromGlobal(iMousePos);
C = pixelsToRowColumn(iMousePos.x(), iMousePos.y());
C = pixelsToNearestRowColumn(iMousePos.x(), iMousePos.y());
C.Row = minMax(C.Row, 1, displayLineCount());
if (mScrollDeltaX != 0) {
setLeftChar(leftChar() + mScrollDeltaX * mMouseSelectionScrollSpeed);
@ -2576,7 +2585,7 @@ void SynEdit::computeCaret()
int X=iMousePos.x();
int Y=iMousePos.y();
DisplayCoord vCaretNearestPos = pixelsToRowColumn(X, Y);
DisplayCoord vCaretNearestPos = pixelsToNearestRowColumn(X, Y);
vCaretNearestPos.Row = minMax(vCaretNearestPos.Row, 1, displayLineCount());
setInternalDisplayXY(vCaretNearestPos);
}
@ -6288,7 +6297,7 @@ void SynEdit::dragEnterEvent(QDragEnterEvent *event)
mDragCaretSave = caretXY();
mDragSelBeginSave = blockBegin();
mDragSelEndSave = blockEnd();
BufferCoord coord = displayToBufferPos(pixelsToRowColumn(event->pos().x(),
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(event->pos().x(),
event->pos().y()));
internalSetCaretXY(coord);
setBlockBegin(mDragSelBeginSave);
@ -6302,7 +6311,7 @@ void SynEdit::dropEvent(QDropEvent *event)
{
//mScrollTimer->stop();
BufferCoord coord = displayToBufferPos(pixelsToRowColumn(event->pos().x(),
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(event->pos().x(),
event->pos().y()));
setCaretXY(coord);
if (coord>=mDragSelBeginSave && coord<=mDragSelEndSave) {
@ -6371,7 +6380,7 @@ void SynEdit::dragMoveEvent(QDragMoveEvent *event)
iMousePos = mapFromGlobal(iMousePos);
int X=iMousePos.x();
int Y=iMousePos.y();
BufferCoord coord = displayToBufferPos(pixelsToRowColumn(X,Y));
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(X,Y));
internalSetCaretXY(coord);
setBlockBegin(mDragSelBeginSave);
setBlockEnd(mDragSelEndSave);

View File

@ -177,6 +177,7 @@ public:
void invalidateGutter();
void invalidateGutterLine(int aLine);
void invalidateGutterLines(int FirstLine, int LastLine);
DisplayCoord pixelsToNearestRowColumn(int aX, int aY) const;
DisplayCoord pixelsToRowColumn(int aX, int aY) const;
QPoint rowColumnToPixels(const DisplayCoord& coord) const;
DisplayCoord bufferToDisplayPos(const BufferCoord& p) const;