mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Glitchiness with Tab Characters (flutter/engine#8591)
Fix a bug that caused jumping and flashing when entering tab characters into a TextField.
This commit is contained in:
parent
140fd44ee4
commit
4db223edaf
@ -32,8 +32,6 @@ using std::vector;
|
||||
|
||||
namespace minikin {
|
||||
|
||||
const int CHAR_TAB = 0x0009;
|
||||
|
||||
// Large scores in a hierarchy; we prefer desperate breaks to an overfull line.
|
||||
// All these constants are larger than any reasonable actual width score.
|
||||
const float SCORE_INFTY = std::numeric_limits<float>::max();
|
||||
@ -159,22 +157,14 @@ float LineBreaker::addStyleRun(MinikinPaint* paint,
|
||||
size_t postSpaceCount = mSpaceCount;
|
||||
for (size_t i = start; i < end; i++) {
|
||||
uint16_t c = mTextBuf[i];
|
||||
if (c == CHAR_TAB) {
|
||||
mWidth = mPreBreak + mTabStops.nextTab(mWidth - mPreBreak);
|
||||
if (mFirstTabIndex == INT_MAX) {
|
||||
mFirstTabIndex = (int)i;
|
||||
}
|
||||
// fall back to greedy; other modes don't know how to deal with tabs
|
||||
mStrategy = kBreakStrategy_Greedy;
|
||||
} else {
|
||||
if (isWordSpace(c))
|
||||
mSpaceCount += 1;
|
||||
mWidth += mCharWidths[i];
|
||||
if (!isLineEndSpace(c)) {
|
||||
postBreak = mWidth;
|
||||
postSpaceCount = mSpaceCount;
|
||||
afterWord = i + 1;
|
||||
}
|
||||
// libtxt: Tab handling was removed here.
|
||||
if (isWordSpace(c))
|
||||
mSpaceCount += 1;
|
||||
mWidth += mCharWidths[i];
|
||||
if (!isLineEndSpace(c)) {
|
||||
postBreak = mWidth;
|
||||
postSpaceCount = mSpaceCount;
|
||||
afterWord = i + 1;
|
||||
}
|
||||
if (i + 1 == current) {
|
||||
size_t wordStart = mWordBreaker.wordStart();
|
||||
|
||||
@ -85,30 +85,6 @@ class LineWidths {
|
||||
std::vector<float> mIndents;
|
||||
};
|
||||
|
||||
class TabStops {
|
||||
public:
|
||||
void set(const int* stops, size_t nStops, int tabWidth) {
|
||||
if (stops != nullptr) {
|
||||
mStops.assign(stops, stops + nStops);
|
||||
} else {
|
||||
mStops.clear();
|
||||
}
|
||||
mTabWidth = tabWidth;
|
||||
}
|
||||
float nextTab(float widthSoFar) const {
|
||||
for (size_t i = 0; i < mStops.size(); i++) {
|
||||
if (mStops[i] > widthSoFar) {
|
||||
return mStops[i];
|
||||
}
|
||||
}
|
||||
return floor(widthSoFar / mTabWidth + 1) * mTabWidth;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<int> mStops;
|
||||
int mTabWidth;
|
||||
};
|
||||
|
||||
class LineBreaker {
|
||||
public:
|
||||
const static int kTab_Shift =
|
||||
@ -143,10 +119,6 @@ class LineBreaker {
|
||||
|
||||
void setIndents(const std::vector<float>& indents);
|
||||
|
||||
void setTabStops(const int* stops, size_t nStops, int tabWidth) {
|
||||
mTabStops.set(stops, nStops, tabWidth);
|
||||
}
|
||||
|
||||
BreakStrategy getStrategy() const { return mStrategy; }
|
||||
|
||||
void setStrategy(BreakStrategy strategy) { mStrategy = strategy; }
|
||||
@ -246,7 +218,6 @@ class LineBreaker {
|
||||
HyphenationFrequency mHyphenationFrequency = kHyphenationFrequency_Normal;
|
||||
bool mJustified;
|
||||
LineWidths mLineWidths;
|
||||
TabStops mTabStops;
|
||||
|
||||
// result of line breaking
|
||||
std::vector<int> mBreaks;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user