Skip to content

Commit

Permalink
fix: [editor] The editor comment feature is abnormal
Browse files Browse the repository at this point in the history
as title

Log: fix issue
  • Loading branch information
Kakueeen authored and deepin-mozart committed Oct 30, 2024
1 parent c79fdef commit d4e5594
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/plugins/codeeditor/gui/texteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,17 @@ void TextEditor::commentOperation()
if (!hasSelectedText()) {
int cursorLine = 0, cursorIndex = 0;
getCursorPosition(&cursorLine, &cursorIndex);
int lineLastIndex = lineLength(cursorLine);
// The `lineLength` interface gets the byte length
// and needs to get the character length
const auto &lineText = text(cursorLine);
int lineLastIndex = lineText.length();
if (lineText.endsWith('\n'))
lineLastIndex--;

if (hasUncommentedLines(cursorLine, cursorLine, 0, lineLastIndex, fileCommentSettings))
addCommentToSelectedLines(cursorLine, cursorLine, 0, lineLastIndex - 1, fileCommentSettings);
addCommentToSelectedLines(cursorLine, cursorLine, 0, lineLastIndex, fileCommentSettings);
else
delCommentToSelectedLines(cursorLine, cursorLine, 0, lineLastIndex - 1, fileCommentSettings);
delCommentToSelectedLines(cursorLine, cursorLine, 0, lineLastIndex, fileCommentSettings);
return;
}

Expand All @@ -502,8 +508,9 @@ void TextEditor::commentOperation()

QString TextEditor::getFileType()
{
// Get mimetype using only the file name
QMimeDatabase mimeDatabase;
QString mimeTypeName = mimeDatabase.mimeTypeForFile(d->fileName).name();
QString mimeTypeName = mimeDatabase.mimeTypeForFile(d->fileName, QMimeDatabase::MatchExtension).name();
return mimeTypeName;
}

Expand Down

0 comments on commit d4e5594

Please sign in to comment.