mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/code] Handle acception/dismissal of autocompletion
This commit is contained in:
@@ -196,6 +196,27 @@ KDRect PythonTextArea::ContentView::dirtyRectFromPosition(const char * position,
|
||||
);
|
||||
}
|
||||
|
||||
bool PythonTextArea::handleEvent(Ion::Events::Event event) {
|
||||
if (m_contentView.isAutocompleting()) {
|
||||
// Handle event with autocompletion
|
||||
if (event == Ion::Events::Toolbox || event == Ion::Events::Var) {
|
||||
} else if (event == Ion::Events::Right
|
||||
|| event == Ion::Events::ShiftRight
|
||||
|| event == Ion::Events::OK)
|
||||
{
|
||||
acceptAutocompletion(event != Ion::Events::ShiftRight);
|
||||
if (event != Ion::Events::ShiftRight) {
|
||||
// Do not process the event more
|
||||
scrollToCursor();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
removeAutocompletion();
|
||||
}
|
||||
}
|
||||
return TextArea::handleEvent(event);
|
||||
}
|
||||
|
||||
bool PythonTextArea::handleEventWithText(const char * text, bool indentation, bool forceCursorRightOfText) {
|
||||
if (*text == 0) {
|
||||
return false;
|
||||
@@ -230,4 +251,14 @@ void PythonTextArea::addAutocompletion() {
|
||||
}
|
||||
}
|
||||
|
||||
void PythonTextArea::acceptAutocompletion(bool moveCursorToEndOfAutocompletion) {
|
||||
assert(m_contentView.isAutocompleting());
|
||||
m_contentView.setAutocompleting(false);
|
||||
if (moveCursorToEndOfAutocompletion) {
|
||||
const char * autocompleteEnd = UTF8Helper::EndOfWord(m_contentView.cursorLocation());
|
||||
setCursorLocation(autocompleteEnd);
|
||||
addAutocompletion();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
}
|
||||
void loadSyntaxHighlighter() { m_contentView.loadSyntaxHighlighter(); }
|
||||
void unloadSyntaxHighlighter() { m_contentView.unloadSyntaxHighlighter(); }
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
bool handleEventWithText(const char * text, bool indentation = false, bool forceCursorRightOfText = false) override;
|
||||
protected:
|
||||
class ContentView : public TextArea::ContentView {
|
||||
@@ -40,6 +41,7 @@ protected:
|
||||
private:
|
||||
void removeAutocompletion();
|
||||
void addAutocompletion();
|
||||
void acceptAutocompletion(bool moveCursorToEndOfAutocompletion);
|
||||
const ContentView * nonEditableContentView() const override { return &m_contentView; }
|
||||
ContentView m_contentView;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user