Skip to content

Commit 4bf74df

Browse files
committed
ticket:4233 Consider the column start and end indexes of the class.
1 parent 1267b2c commit 4bf74df

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,37 @@ void LibraryTreeModel::readLibraryTreeItemClassTextFromText(LibraryTreeItem *pLi
21702170
} else if (lineNumber > pLibraryTreeItem->mClassInformation.lineNumberEnd) {
21712171
after += currentLine + "\n";
21722172
} else if (pLibraryTreeItem->inRange(lineNumber)) {
2173-
text += currentLine + "\n";
2173+
/* Ticket #4233
2174+
* We could have code like this,
2175+
*
2176+
* package P
2177+
* package Q
2178+
* model M1
2179+
* end M1;
2180+
*
2181+
* model M2
2182+
* end M2; end Q;
2183+
* end P;
2184+
*
2185+
* So we need to conside column start and end.
2186+
*/
2187+
if (lineNumber == pLibraryTreeItem->mClassInformation.lineNumberStart) {
2188+
QString leftStr = currentLine.left(pLibraryTreeItem->mClassInformation.columnNumberStart - 1);
2189+
int nonSpaceIndex = TabSettings::firstNonSpace(leftStr);
2190+
/* If there is no other text on the first line of class then take the whole line.
2191+
*/
2192+
if (nonSpaceIndex >= pLibraryTreeItem->mClassInformation.columnNumberStart - 1) {
2193+
text += currentLine + "\n";
2194+
} else {
2195+
before += currentLine.left(pLibraryTreeItem->mClassInformation.columnNumberStart - 1);
2196+
text += currentLine.mid(pLibraryTreeItem->mClassInformation.columnNumberStart - 1) + "\n";
2197+
}
2198+
} else if (lineNumber == pLibraryTreeItem->mClassInformation.lineNumberEnd) {
2199+
text += currentLine.left(pLibraryTreeItem->mClassInformation.columnNumberEnd);
2200+
after += currentLine.mid(pLibraryTreeItem->mClassInformation.columnNumberEnd) + "\n";
2201+
} else {
2202+
text += currentLine + "\n";
2203+
}
21742204
}
21752205
lineNumber++;
21762206
}

0 commit comments

Comments
 (0)