fix: wrong caret position when input using input method
This commit is contained in:
parent
0e6d4483c4
commit
d648e741df
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -2503,7 +2503,11 @@ QRect QSynEdit::calculateCaretRect() const
|
|||
QString sLine = lineText().left(mCaretX-1)
|
||||
+ mInputPreeditString
|
||||
+ lineText().mid(mCaretX-1);
|
||||
coord.x = charToGlyphLeft(mCaretY, sLine, mCaretX+mInputPreeditString.length());
|
||||
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;
|
||||
if (mActiveSelectionMode == SelectionMode::Column) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue