[apps/code] Handle autocomplete coloring

This commit is contained in:
Léa Saviot
2020-03-11 18:58:39 +01:00
committed by Émilie Feral
parent 9b8b0bc98f
commit 32fbea9d06
2 changed files with 25 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ constexpr KDColor KeywordColor = KDColor::RGB24(0xFF000C);
// constexpr KDColor BuiltinColor = KDColor::RGB24(0x0086B3);
constexpr KDColor OperatorColor = KDColor::RGB24(0xd73a49);
constexpr KDColor StringColor = KDColor::RGB24(0x032f62);
constexpr KDColor AutocompleteColor = KDColorRed;
constexpr KDColor BackgroundColor = KDColorWhite;
constexpr KDColor HighlightColor = Palette::Select;
@@ -160,6 +161,27 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
mp_lexer_free(lex);
nlr_pop();
}
// Redraw the autocompleted word in the right color
const char * autocompleteStart = m_cursorLocation;
assert(autocompleteStart != text);
if (m_autocomplete && autocompleteStart > text && autocompleteStart < text + byteLength) {
const char * autocompleteEnd = cursorLocation();
while (*autocompleteEnd != ' ' && autocompleteEnd < text + byteLength) {
autocompleteEnd++;
}
drawStringAt(
ctx,
line,
UTF8Helper::GlyphOffsetAtCodePoint(text, autocompleteStart),
autocompleteStart,
minPointer(text + byteLength, autocompleteEnd) - autocompleteStart,
AutocompleteColor,
BackgroundColor,
nullptr,
nullptr,
HighlightColor);
}
}
KDRect PythonTextArea::ContentView::dirtyRectFromPosition(const char * position, bool includeFollowingLines) const {

View File

@@ -21,7 +21,8 @@ protected:
public:
ContentView(App * pythonDelegate, const KDFont * font) :
TextArea::ContentView(font),
m_pythonDelegate(pythonDelegate)
m_pythonDelegate(pythonDelegate),
m_autocomplete(false)
{
}
void loadSyntaxHighlighter();
@@ -31,6 +32,7 @@ protected:
KDRect dirtyRectFromPosition(const char * position, bool includeFollowingLines) const override;
private:
App * m_pythonDelegate;
bool m_autocomplete;
};
private:
const ContentView * nonEditableContentView() const override { return &m_contentView; }