* fix: new file's name errorString

* fix: display error when row number digit count's Changed
 * fix: top line is not correctly setted, when add new lines after the last line just above the editor's bottom
This commit is contained in:
royqh1979@gmail.com 2021-06-07 21:34:48 +08:00
parent 1f74245f0a
commit a0d142f6df
4 changed files with 76 additions and 40 deletions

View File

@ -46,7 +46,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
{
if (mFilename.isEmpty()) {
newfileCount++;
mFilename = tr("untitled") + newfileCount;
mFilename = tr("untitled%1").arg(newfileCount);
}
QFileInfo fileInfo(mFilename);
if (mParentPageControl!=NULL) {
@ -258,7 +258,7 @@ void Editor::applySettings()
{
SynEditorOptions options = eoAltSetsColumnMode |
eoDragDropEditing | eoDropFiles | eoKeepCaretX | eoTabsToSpaces |
eoRightMouseMovesCursor | eoScrollByOneLess | eoTabIndent;
eoRightMouseMovesCursor | eoScrollByOneLess | eoTabIndent | eoHideShowScrollbars;
options.setFlag(eoAddIndent,pSettings->editor().addIndent());
options.setFlag(eoAutoIndent,pSettings->editor().autoIndent());
options.setFlag(eoTabsToSpaces,pSettings->editor().tabToSpaces());

View File

@ -144,7 +144,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent)
this, &SynEdit::doScrolled);
connect(verticalScrollBar(),&QScrollBar::valueChanged,
this, &SynEdit::doScrolled);
//enable input method
setAttribute(Qt::WA_InputMethodEnabled);
@ -2035,8 +2034,10 @@ void SynEdit::decPaintLock()
Q_ASSERT(mPaintLock > 0);
mPaintLock--;
if (mPaintLock == 0 ) {
if (mStateFlags.testFlag(SynStateFlag::sfScrollbarChanged))
if (mStateFlags.testFlag(SynStateFlag::sfScrollbarChanged)) {
updateScrollbars();
ensureCursorPosVisible();
}
if (mStateFlags.testFlag(SynStateFlag::sfCaretChanged))
updateCaret();
if (mStatusChanges!=0)
@ -2197,11 +2198,10 @@ void SynEdit::updateScrollbars()
setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
}
if (mScrollBars == SynScrollStyle::ssBoth || mScrollBars == SynScrollStyle::ssHorizontal) {
nMaxScroll = std::max(mLines->lengthOfLongestLine(), 1);
if (mOptions.testFlag(eoScrollPastEol))
nMaxScroll = mMaxScrollWidth;
nMaxScroll = mLines->lengthOfLongestLine();
else
nMaxScroll = std::max(mLines->lengthOfLongestLine(), 1);
nMaxScroll = std::max(mLines->lengthOfLongestLine()-mCharsInWindow+1, 1);
if (nMaxScroll <= MAX_SCROLL) {
nMin = 1;
nMax = nMaxScroll;
@ -2222,9 +2222,11 @@ void SynEdit::updateScrollbars()
setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
if (mScrollBars == SynScrollStyle::ssBoth || mScrollBars == SynScrollStyle::ssVertical) {
nMaxScroll = displayLineCount();
if (mOptions.testFlag(eoScrollPastEof))
nMaxScroll+=mLinesInWindow - 1;
nMaxScroll = std::max(displayLineCount(),1);
else
nMaxScroll = std::max(displayLineCount()-mLinesInWindow+1, 1);
if (nMaxScroll <= MAX_SCROLL) {
nMin = 1;
nMax = std::max(1, nMaxScroll);
@ -4812,6 +4814,16 @@ void SynEdit::leaveEvent(QEvent *event)
setCursor(Qt::ArrowCursor);
}
bool SynEdit::viewportEvent(QEvent * event)
{
switch (event->type()) {
case QEvent::Resize:
sizeOrFontChanged(false);
break;
}
return QAbstractScrollArea::viewportEvent(event);
}
int SynEdit::maxScrollWidth() const
{
return mMaxScrollWidth;
@ -4856,6 +4868,7 @@ void SynEdit::setGutterWidth(int Value)
if (mGutterWidth != Value) {
mGutterWidth = Value;
sizeOrFontChanged(false);
invalidate();
}
}
@ -5142,7 +5155,6 @@ void SynEdit::setLeftChar(int Value)
horizontalScrollBar()->setValue(Value);
setStatusChanged(SynStatusChange::scLeftChar);
}
}
int SynEdit::linesInWindow() const
@ -5163,7 +5175,6 @@ void SynEdit::setTopLine(int Value)
Value = std::min(Value, displayLineCount() - mLinesInWindow + 1);
Value = std::max(Value, 1);
if (Value != mTopLine) {
//updateScrollbars();
verticalScrollBar()->setValue(Value);
setStatusChanged(SynStatusChange::scTopLine);
}

View File

@ -602,6 +602,10 @@ void mouseMoveEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
void inputMethodEvent(QInputMethodEvent *event) override;
void leaveEvent(QEvent *event) override;
// QAbstractScrollArea interface
protected:
bool viewportEvent(QEvent * event) override;
};
#endif // SYNEDIT_H

View File

@ -165,7 +165,7 @@
<property name="spacing">
<number>7</number>
</property>
<item row="0" column="2">
<item row="2" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -178,34 +178,7 @@
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbCaretForInsert"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbCaretForInsert">
<property name="text">
<string>Caret for inserting mode</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbCaretForOverwrite">
<property name="text">
<string>Caret for overwriting mode</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cbCaretForOverwrite"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbCaretColor">
<property name="text">
<string>Caret Color</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="ColorEdit" name="colorCaret">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
@ -215,12 +188,60 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="chkCaretPastEol">
<property name="text">
<string>Caret can be positioned past end of line</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="cbCaretForOverwrite"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbCaretForInsert">
<property name="text">
<string>Caret for inserting mode</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cbCaretForInsert"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbCaretForOverwrite">
<property name="text">
<string>Caret for overwriting mode</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbCaretColor">
<property name="text">
<string>Caret Color</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="chkCaretPastEof">
<property name="text">
<string>Caret can be positioned past end of file</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Scroll</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">