fix: wrong caret position when input using input method

This commit is contained in:
Roy Qu 2024-02-26 10:35:42 +08:00
parent 0e6d4483c4
commit d648e741df
3 changed files with 21 additions and 1 deletions

View File

@ -1216,6 +1216,7 @@ void QSynEditPainter::paintLines()
sLine.length(),
glyphStartPositionsList,
tokenWidth);
tokenLeft += tokenWidth;
}
}
// Draw anything that's left in the TokenAccu record. Fill to the end
@ -1253,6 +1254,11 @@ void QSynEditPainter::paintLines()
area->color = colFG;
}
areaList.append(area);
mEdit->mGlyphPostionListCache.str = sLine;
mEdit->mGlyphPostionListCache.glyphCharList = glyphStartCharList;
mEdit->mGlyphPostionListCache.glyphPositionList = glyphStartPositionsList;
mEdit->mGlyphPostionListCache.strWidth = tokenLeft;
}
paintEditAreas(areaList);
}

View File

@ -2503,6 +2503,10 @@ QRect QSynEdit::calculateCaretRect() const
QString sLine = lineText().left(mCaretX-1)
+ mInputPreeditString
+ lineText().mid(mCaretX-1);
if (sLine == mGlyphPostionListCache.str) {
int glyphIdx = searchForSegmentIdx(mGlyphPostionListCache.glyphCharList,0,sLine.length(),mCaretX+mInputPreeditString.length()-1);
coord.x = segmentIntervalStart(mGlyphPostionListCache.glyphPositionList,0,mGlyphPostionListCache.strWidth, glyphIdx);
} else
coord.x = charToGlyphLeft(mCaretY, sLine, mCaretX+mInputPreeditString.length());
}
int rows=1;

View File

@ -132,6 +132,14 @@ using SearchMathedProc = std::function<SearchAction(const QString& sSearch,
const QString& sReplace, int Line, int ch, int wordLen)>;
using SearchConfirmAroundProc = std::function<bool ()>;
struct GlyphPostionsListCache {
QString str;
QList<int> glyphCharList;
QList<int> glyphPositionList;
int strWidth;
};
class QSynEdit;
using PSynEdit = std::shared_ptr<QSynEdit>;
@ -142,6 +150,7 @@ public:
explicit QSynEdit(QWidget* parent=nullptr);
QSynEdit(const QSynEdit&)=delete;
QSynEdit& operator=(const QSynEdit&)=delete;
/**
* Returns how many rows are there in the editor
* @return
@ -770,6 +779,7 @@ private:
int mWheelAccumulatedDeltaY;
PFormatter mFormatter;
GlyphPostionsListCache mGlyphPostionListCache;
friend class QSynEditPainter;