mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[escher] Add textArea line number limit
Change-Id: Ia0d9a9136282efc87c0996c141c0852ed75892f9
This commit is contained in:
committed by
Émilie Feral
parent
52f83eb682
commit
aba135bc8b
@@ -67,11 +67,19 @@ void EditorView::GutterView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
KDCoordinate firstLine = m_offset / glyphSize.height();
|
||||
KDCoordinate firstLinePixelOffset = m_offset - firstLine * glyphSize.height();
|
||||
|
||||
char lineNumber[4];
|
||||
char lineNumber[k_lineNumberCharLength];
|
||||
int numberOfLines = bounds().height() / glyphSize.height() + 1;
|
||||
for (int i=0; i<numberOfLines; i++) {
|
||||
Poincare::Integer line(i + firstLine + 1);
|
||||
line.serialize(lineNumber, 4);
|
||||
// Only the first two digits are displayed
|
||||
int lineNumberValue = (i + firstLine + 1) % 100;
|
||||
Poincare::Integer line(lineNumberValue);
|
||||
if (firstLine < 10 || lineNumberValue >= 10) {
|
||||
line.serialize(lineNumber, k_lineNumberCharLength);
|
||||
} else {
|
||||
// Add a leading "0"
|
||||
lineNumber[0] = '0';
|
||||
line.serialize(lineNumber + 1, k_lineNumberCharLength - 1);
|
||||
}
|
||||
KDCoordinate leftPadding = (2 - strlen(lineNumber)) * glyphSize.width();
|
||||
ctx->drawString(
|
||||
lineNumber,
|
||||
|
||||
@@ -42,6 +42,7 @@ private:
|
||||
KDSize minimalSizeForOptimalDisplay() const override;
|
||||
private:
|
||||
static constexpr KDCoordinate k_margin = 2;
|
||||
static constexpr int k_lineNumberCharLength = 3;
|
||||
const KDFont * m_font;
|
||||
KDCoordinate m_offset;
|
||||
};
|
||||
|
||||
@@ -94,6 +94,9 @@ protected:
|
||||
size_t textLength() const {
|
||||
return strlen(m_buffer);
|
||||
}
|
||||
int textLineTotal() const {
|
||||
return positionAtPointer(m_buffer+textLength()).line();
|
||||
}
|
||||
private:
|
||||
char * m_buffer;
|
||||
size_t m_bufferSize;
|
||||
@@ -133,6 +136,8 @@ protected:
|
||||
private:
|
||||
void selectUpDown(bool up, int step);
|
||||
TextAreaDelegate * m_delegate;
|
||||
// Due to rect size limitation, the editor cannot display more than 1800 lines
|
||||
constexpr static int k_maxLines = 999;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -63,6 +63,11 @@ bool TextArea::handleEventWithText(const char * text, bool indentation, bool for
|
||||
}
|
||||
}
|
||||
|
||||
// Check the text will not overflow the max number of lines
|
||||
if (contentView()->getText()->textLineTotal() + UTF8Helper::CountOccurrences(text, '\n') >= k_maxLines) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Insert the text
|
||||
if (!insertTextAtLocation(text, insertionPosition)) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user