Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: double click edit incorrect format #543

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/widgets/dcrumbedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ class DCrumbEditPrivate : public DCORE_NAMESPACE::DObjectPrivate

void registerHandler(QAbstractTextDocumentLayout *layout)
{
D_Q(DCrumbEdit);

for (int i = QTextFormat::UserObject + 1; ; ++i) {
if (!layout->handlerForObject(i)) {
objectType = i;
Expand Down Expand Up @@ -379,7 +377,9 @@ class DCrumbEditPrivate : public DCORE_NAMESPACE::DObjectPrivate
if (cursor.charFormat().objectType() != objectType)
return false;

DCrumbTextFormat format(cursor.charFormat());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

从 cursor 获取 charformat 不准,还是从layout中获取准确一些

auto fmt = q->document()->documentLayout()->formatAt(mousePos);
DCrumbTextFormat format = formats.value(fmt.stringProperty(QTextFormat::UserProperty + 1));

currentText = format.text();
currentBrush = format.background();

Expand All @@ -391,7 +391,8 @@ class DCrumbEditPrivate : public DCORE_NAMESPACE::DObjectPrivate

makeCrumb();

if (mousePos.x() < q->cursorRect().left())
if (mousePos.x() < q->cursorRect().left() ||
mousePos.y() < q->cursorRect().top())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换行时会有计算错误,所以要考虑 y

cursor.setPosition(cursor.position() - 1, QTextCursor::KeepAnchor);
else
cursor.setPosition(cursor.position() + 1, QTextCursor::KeepAnchor);
Expand Down