- enhancement: Windows installer Hi-DPI support.

- refactor: remove Line edit mode in qsynedit.
  - optimization for scroll calculation while inputing text
This commit is contained in:
Roy Qu 2024-03-07 11:06:15 +08:00
parent 0a11b4b6ea
commit 67caf82753
9 changed files with 20 additions and 99 deletions

View File

@ -470,14 +470,12 @@ void Document::putLine(int index, const QString &s, bool notify) {
listIndexOutOfBounds(index); listIndexOutOfBounds(index);
} }
beginUpdate(); beginUpdate();
int oldWidth = mLines[index]->width(); int oldWidth = -1;
if (mIndexOfLongestLine == index)
oldWidth = mLines[index]->mWidth;
mLines[index]->setLineText( s ); mLines[index]->setLineText( s );
if (mIndexOfLongestLine == index && oldWidth>mLines[index]->width() ) if (mIndexOfLongestLine == index && oldWidth>mLines[index]->width() )
mIndexOfLongestLine = -1; mIndexOfLongestLine = -1;
else if (mIndexOfLongestLine>=0
&& mIndexOfLongestLine<mLines.count()
&& mLines[index]->width() > mLines[mIndexOfLongestLine]->width())
mIndexOfLongestLine = index;
if (notify) if (notify)
emit putted(index); emit putted(index);
endUpdate(); endUpdate();

View File

@ -1352,9 +1352,7 @@ bool QSynEdit::isPointInSelection(const BufferCoord &Value) const
BufferCoord ptEnd = blockEnd(); BufferCoord ptEnd = blockEnd();
if ((Value.line >= ptBegin.line) && (Value.line <= ptEnd.line) && if ((Value.line >= ptBegin.line) && (Value.line <= ptEnd.line) &&
((ptBegin.line != ptEnd.line) || (ptBegin.ch != ptEnd.ch))) { ((ptBegin.line != ptEnd.line) || (ptBegin.ch != ptEnd.ch))) {
if (mActiveSelectionMode == SelectionMode::Line) if (mActiveSelectionMode == SelectionMode::Column) {
return true;
else if (mActiveSelectionMode == SelectionMode::Column) {
if (ptBegin.ch > ptEnd.ch) if (ptBegin.ch > ptEnd.ch)
return (Value.ch >= ptEnd.ch) && (Value.ch < ptBegin.ch); return (Value.ch >= ptEnd.ch) && (Value.ch < ptBegin.ch);
else if (ptBegin.ch < ptEnd.ch) else if (ptBegin.ch < ptEnd.ch)
@ -2758,9 +2756,6 @@ void QSynEdit::doAddChar(const QChar& ch)
setBlockEnd(end); setBlockEnd(end);
} }
break; break;
case SelectionMode::Line:
//do nothing;
break;
default: default:
setSelLength(1); setSelLength(1);
} }
@ -4144,9 +4139,6 @@ void QSynEdit::doAddStr(const QString &s)
setBlockEnd(end); setBlockEnd(end);
} }
break; break;
case SelectionMode::Line:
//do nothing;
break;
default: default:
setSelLength(s.length()); setSelLength(s.length());
} }
@ -4591,20 +4583,6 @@ QString QSynEdit::selText() const
} }
return result; return result;
} }
case SelectionMode::Line:
{
QString result;
// If block selection includes LastLine,
// line break code(s) of the last line will not be added.
for (int i= firstLine; i<=lastLine - 1;i++) {
result += mDocument->getLine(i);
result+=lineBreak();
}
result += mDocument->getLine(lastLine);
if (lastLine < mDocument->count() - 1)
result+=lineBreak();
return result;
}
} }
} }
return ""; return "";
@ -4664,16 +4642,6 @@ QStringList QSynEdit::getContent(BufferCoord startPos, BufferCoord endPos, Selec
} }
} }
break; break;
case SelectionMode::Line:
// If block selection includes LastLine,
// line break code(s) of the last line will not be added.
for (int i= firstLine; i<=lastLine - 1;i++) {
result.append(mDocument->getLine(i));
}
result.append(mDocument->getLine(lastLine));
if (lastLine < mDocument->count() - 1)
result.append("");
break;
} }
return result; return result;
} }
@ -4779,8 +4747,7 @@ void QSynEdit::moveCaretHorz(int deltaX, bool isSelection)
else else
ptDst = blockEnd(); ptDst = blockEnd();
} else { } else {
if (mOptions.testFlag(eoAltSetsColumnMode) && if (mOptions.testFlag(eoAltSetsColumnMode)) {
(mActiveSelectionMode != SelectionMode::Line)) {
if (qApp->keyboardModifiers().testFlag(Qt::AltModifier) && !mReadOnly) { if (qApp->keyboardModifiers().testFlag(Qt::AltModifier) && !mReadOnly) {
setActiveSelectionMode(SelectionMode::Column); setActiveSelectionMode(SelectionMode::Column);
} else } else
@ -4855,8 +4822,7 @@ void QSynEdit::moveCaretVert(int deltaY, bool isSelection)
if (mOptions.testFlag(eoKeepCaretX)) if (mOptions.testFlag(eoKeepCaretX))
ptDst.x = mLastCaretColumn; ptDst.x = mLastCaretColumn;
} }
if (mOptions.testFlag(eoAltSetsColumnMode) && if (mOptions.testFlag(eoAltSetsColumnMode)) {
(mActiveSelectionMode != SelectionMode::Line)) {
if (qApp->keyboardModifiers().testFlag(Qt::AltModifier) && !mReadOnly) if (qApp->keyboardModifiers().testFlag(Qt::AltModifier) && !mReadOnly)
setActiveSelectionMode(SelectionMode::Column); setActiveSelectionMode(SelectionMode::Column);
else else
@ -5114,10 +5080,7 @@ int QSynEdit::searchReplace(const QString &sSearch, const QString &sReplace, Sea
ptStart = blockBegin(); ptStart = blockBegin();
ptEnd = blockEnd(); ptEnd = blockEnd();
// search the whole line in the line selection mode // search the whole line in the line selection mode
if (mActiveSelectionMode == SelectionMode::Line) { if (mActiveSelectionMode == SelectionMode::Column) {
ptStart.ch = 1;
ptEnd.ch = mDocument->getLine(ptEnd.line - 1).length();
} else if (mActiveSelectionMode == SelectionMode::Column) {
// make sure the start column is smaller than the end column // make sure the start column is smaller than the end column
if (ptStart.ch > ptEnd.ch) if (ptStart.ch > ptEnd.ch)
std::swap(ptStart.ch,ptEnd.ch); std::swap(ptStart.ch,ptEnd.ch);
@ -5362,18 +5325,6 @@ void QSynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionM
// updating is needed here. // updating is needed here.
break; break;
} }
case SelectionMode::Line:
if (endPos.line == mDocument->count()) {
mDocument->putLine(endPos.line - 1,"");
mDocument->deleteLines(startPos.line-1,endPos.line-startPos.line);
} else {
mDocument->deleteLines(startPos.line-1,endPos.line-startPos.line+1);
}
// smLine deletion always resets to first column.
internalSetCaretXY(BufferCoord{1, startPos.line});
UpdateMarks = true;
MarkOffset = 1;
break;
} }
// Update marks // Update marks
if (UpdateMarks) if (UpdateMarks)
@ -5429,13 +5380,6 @@ void QSynEdit::doInsertText(const BufferCoord& pos,
} }
} }
break; break;
case SelectionMode::Line:
insertedLines = doInsertTextByLineMode(pos,text, newPos);
doLinesInserted(pos.line, insertedLines);
internalSetCaretXY(newPos);
setBlockBegin(newPos);
ensureCursorPosVisible();
break;
} }
} }
@ -5590,34 +5534,6 @@ int QSynEdit::doInsertTextByColumnMode(const QStringList& text, int startLine, i
return result; return result;
} }
int QSynEdit::doInsertTextByLineMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos)
{
QString Str;
int Result = 0;
newPos=pos;
newPos.ch=1;
// mCaretX = 1;
// emit statusChanged(SynStatusChange::scCaretX);
// Insert string before current line
for (int i=0;i<text.length();i++) {
if ((mCaretY == mDocument->count()) || mInserting) {
mDocument->insertLine(mCaretY - 1, "");
Result++;
}
properSetLine(mCaretY - 1, Str);
newPos.line++;
// mCaretY++;
// mStatusChanges.setFlag(SynStatusChange::scCaretY);
}
if (!mUndoing) {
mUndoList->addChange(
ChangeReason::Insert,
BufferCoord{1,pos.line},newPos,
QStringList(),SelectionMode::Line);
}
return Result;
}
void QSynEdit::deleteFromTo(const BufferCoord &start, const BufferCoord &end) void QSynEdit::deleteFromTo(const BufferCoord &start, const BufferCoord &end)
{ {
if (mReadOnly) if (mReadOnly)
@ -6216,8 +6132,7 @@ void QSynEdit::mousePressEvent(QMouseEvent *event)
//BlockBegin and BlockEnd are restored to their original position in the //BlockBegin and BlockEnd are restored to their original position in the
//code from above and SetBlockEnd will take care of proper invalidation //code from above and SetBlockEnd will take care of proper invalidation
setBlockEnd(caretXY()); setBlockEnd(caretXY());
} else if (mOptions.testFlag(eoAltSetsColumnMode) && } else if (mOptions.testFlag(eoAltSetsColumnMode)) {
(mActiveSelectionMode != SelectionMode::Line)) {
if (event->modifiers() == Qt::AltModifier && !mReadOnly) if (event->modifiers() == Qt::AltModifier && !mReadOnly)
setActiveSelectionMode(SelectionMode::Column); setActiveSelectionMode(SelectionMode::Column);
else else
@ -6280,8 +6195,7 @@ void QSynEdit::mouseMoveEvent(QMouseEvent *event)
drag->exec(Qt::DropActions(Qt::CopyAction | Qt::MoveAction)); drag->exec(Qt::DropActions(Qt::CopyAction | Qt::MoveAction));
} }
} else if (buttons == Qt::LeftButton) { } else if (buttons == Qt::LeftButton) {
if (mOptions.testFlag(eoAltSetsColumnMode) && if (mOptions.testFlag(eoAltSetsColumnMode)) {
(mActiveSelectionMode != SelectionMode::Line) ) {
if (event->modifiers() == Qt::AltModifier && !mReadOnly) if (event->modifiers() == Qt::AltModifier && !mReadOnly)
setActiveSelectionMode(SelectionMode::Column); setActiveSelectionMode(SelectionMode::Column);
else else

View File

@ -594,7 +594,6 @@ private:
void doInsertText(const BufferCoord& pos, const QStringList& text, SelectionMode mode, int startLine, int endLine); void doInsertText(const BufferCoord& pos, const QStringList& text, SelectionMode mode, int startLine, int endLine);
int doInsertTextByNormalMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos); int doInsertTextByNormalMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos);
int doInsertTextByColumnMode(const QStringList& text, int startLine, int endLine); int doInsertTextByColumnMode(const QStringList& text, int startLine, int endLine);
int doInsertTextByLineMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos);
void doTrimTrailingSpaces(); void doTrimTrailingSpaces();
void deleteFromTo(const BufferCoord& start, const BufferCoord& end); void deleteFromTo(const BufferCoord& start, const BufferCoord& end);

View File

@ -24,7 +24,7 @@
namespace QSynedit { namespace QSynedit {
enum class SelectionMode {Normal, Line, Column}; enum class SelectionMode {Normal, Column};
enum class ProgrammingLanguage { enum class ProgrammingLanguage {
DecideBySuffix, DecideBySuffix,

View File

@ -33,6 +33,8 @@ SetDatablockOptimize on
SetOverwrite try SetOverwrite try
XPStyle on XPStyle on
ManifestDPIAware true
InstType "Full";1 InstType "Full";1
InstType "Minimal";2 InstType "Minimal";2
InstType "Safe";3 InstType "Safe";3

View File

@ -33,6 +33,8 @@ SetDatablockOptimize on
SetOverwrite try SetOverwrite try
XPStyle on XPStyle on
ManifestDPIAware true
InstType "Full";1 InstType "Full";1
InstType "Minimal";2 InstType "Minimal";2
InstType "Safe";3 InstType "Safe";3

View File

@ -33,6 +33,8 @@ SetDatablockOptimize on
SetOverwrite try SetOverwrite try
XPStyle on XPStyle on
ManifestDPIAware true
InstType "Full";1 InstType "Full";1
InstType "Minimal";2 InstType "Minimal";2
InstType "Safe";3 InstType "Safe";3

View File

@ -32,6 +32,8 @@ SetDatablockOptimize on
SetOverwrite try SetOverwrite try
XPStyle on XPStyle on
ManifestDPIAware true
InstType "Full";1 InstType "Full";1
InstType "Minimal";2 InstType "Minimal";2
InstType "Safe";3 InstType "Safe";3

View File

@ -34,6 +34,8 @@ SetDatablockOptimize on
SetOverwrite try SetOverwrite try
XPStyle on XPStyle on
ManifestDPIAware true
InstType "Full";1 InstType "Full";1
InstType "Minimal";2 InstType "Minimal";2
InstType "Safe";3 InstType "Safe";3