- fix: calculation for code snippets's tab stop positions is not correct
This commit is contained in:
parent
6a05496b6f
commit
4cf9c2845a
|
@ -2612,8 +2612,8 @@ void Editor::insertCodeSnippet(const QString &code)
|
||||||
for (int i=0;i<sl.count();i++) {
|
for (int i=0;i<sl.count();i++) {
|
||||||
int lastPos = 0;
|
int lastPos = 0;
|
||||||
QString s = sl[i].trimmed();
|
QString s = sl[i].trimmed();
|
||||||
// if (i>0)
|
if (i>0)
|
||||||
// lastPos = -spaceCount;
|
lastPos = countLeadingWhitespaceChars(s);
|
||||||
while (true) {
|
while (true) {
|
||||||
int insertPos = s.indexOf(USER_CODE_IN_INSERT_POS);
|
int insertPos = s.indexOf(USER_CODE_IN_INSERT_POS);
|
||||||
if (insertPos < 0) // no %INSERT% macro in this line now
|
if (insertPos < 0) // no %INSERT% macro in this line now
|
||||||
|
@ -2629,8 +2629,8 @@ void Editor::insertCodeSnippet(const QString &code)
|
||||||
mUserCodeInTabStops.append(p);
|
mUserCodeInTabStops.append(p);
|
||||||
}
|
}
|
||||||
lastPos = 0;
|
lastPos = 0;
|
||||||
// if (i>0)
|
if (i>0)
|
||||||
// lastPos = -spaceCount;
|
lastPos = countLeadingWhitespaceChars(s);
|
||||||
while (true) {
|
while (true) {
|
||||||
int insertPos = s.indexOf(USER_CODE_IN_REPL_POS_BEGIN);
|
int insertPos = s.indexOf(USER_CODE_IN_REPL_POS_BEGIN);
|
||||||
if (insertPos < 0) // no %INSERT% macro in this line now
|
if (insertPos < 0) // no %INSERT% macro in this line now
|
||||||
|
@ -3611,13 +3611,7 @@ void Editor::popUserCodeInTabStops()
|
||||||
tabStopBegin = mTabStopEnd + p->x;
|
tabStopBegin = mTabStopEnd + p->x;
|
||||||
tabStopEnd = mTabStopEnd + p->endX;
|
tabStopEnd = mTabStopEnd + p->endX;
|
||||||
} else {
|
} else {
|
||||||
QString line = lines()->getString(caretY()-1+p->y);
|
int n=countLeadingWhitespaceChars(lines()->getString(caretY()-1+p->y));
|
||||||
int n=0;
|
|
||||||
while (n<line.length()) {
|
|
||||||
if (line[n].unicode()>32)
|
|
||||||
break;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
// qDebug()<<line<<n<<p->x;
|
// qDebug()<<line<<n<<p->x;
|
||||||
tabStopBegin = n+p->x+1;
|
tabStopBegin = n+p->x+1;
|
||||||
tabStopEnd = n+p->endX+1;
|
tabStopEnd = n+p->endX+1;
|
||||||
|
|
|
@ -1147,3 +1147,14 @@ float pointToPixel(float point, float dpi)
|
||||||
{
|
{
|
||||||
return point * dpi / 72;
|
return point * dpi / 72;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int countLeadingWhitespaceChars(const QString &line)
|
||||||
|
{
|
||||||
|
int n=0;
|
||||||
|
while (n<line.length()) {
|
||||||
|
if (line[n].unicode()>32)
|
||||||
|
break;
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
|
@ -180,6 +180,7 @@ QByteArray readFileToByteArray(const QString& fileName);
|
||||||
void readFileToLines(const QString& fileName, QTextCodec* codec, LineProcessFunc lineFunc);
|
void readFileToLines(const QString& fileName, QTextCodec* codec, LineProcessFunc lineFunc);
|
||||||
void stringsToFile(const QStringList& list, const QString& fileName);
|
void stringsToFile(const QStringList& list, const QString& fileName);
|
||||||
void stringToFile(const QString& str, const QString& fileName);
|
void stringToFile(const QString& str, const QString& fileName);
|
||||||
|
int countLeadingWhitespaceChars(const QString& line);
|
||||||
|
|
||||||
void decodeKey(int combinedKey, int& key, Qt::KeyboardModifiers& modifiers);
|
void decodeKey(int combinedKey, int& key, Qt::KeyboardModifiers& modifiers);
|
||||||
void inflateRect(QRect& rect, int delta);
|
void inflateRect(QRect& rect, int delta);
|
||||||
|
|
Loading…
Reference in New Issue