The editor now has context aware completions

This commit is contained in:
eelke 2026-10-22 17:52:37 +02:00
parent 1a1bbd0838
commit 960967c8a6
18 changed files with 1984 additions and 0 deletions

View file

@ -4,6 +4,7 @@
#include <QPlainTextEdit>
#include <set>
#include "util/Colors.h"
#include "CompletionPopup.h"
/** This class adds some capabilities to QPlainTextEdit that are useful
* in code editor scenarios.
@ -20,9 +21,16 @@ public:
void clearErrorMarkers();
void setFont(const QFont &);
void setTabSize(int chars);
/// Install the function that supplies completions, an empty function disables completion
void setCompletionCallback(EditorCompletionCallback callback);
/// Show completions at the cursor, also when nothing has been typed yet
void showCompletions();
protected:
void resizeEvent(QResizeEvent *event) override;
void keyPressEvent(QKeyEvent *e) override;
void focusOutEvent(QFocusEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
signals:
@ -44,6 +52,14 @@ private:
std::set<int> errorLines;
EditorCompletionCallback m_completionCallback;
CompletionPopup *m_completionPopup = nullptr;
EditorCompletionResult m_completionResult;
bool updateCompletions(bool explicitRequest);
void hideCompletions();
void acceptCompletion(int row);
// Settings
int m_tabSize = 0; // tabSize in characters
bool m_useTab = false;